|
* Overhaul the preprocessor
The old Slang preprocessor was based on a simple mental model that tried to unify two parts of macro expansion:
* Scanning for macro invocations in a sequence of tokens
* Producing the expanded tokens for a macro expansion by substituting arguments into its body
The basic was that substitution of macro arguments into a macro definition is superficially similar to top-level macro expansion, just with an environment where the macro arguments act like `#define`s for the corresponding parameter names. That approach was "clever" and could conceivably have been extended to include a lot of advanced preprocessor features (e.g., a preprocessor-level `lambda` would be easy to support!), but it was basically impossible to make it correctly handle all the corner cases of the full C/C++ preprocessor.
The fundamental problem with the old approach was that it conflated the two parts of expansion listed above into one implementation, while the various special cases of the C/C++ preprocessor rely on treating the two cases very differently. The new approach here (which is somewhere between a refactor and a full rewrite of the preprocessor) changes things up in a few key ways:
* The abstraction still cares a lot about streams of tokens, but it now treats the top level streams (`InputFile`s) as fairly different from the lower-level streams (`InputStream`s)
* Macro expansion is handled as a dedicated type of stream that wraps another stream. This allows macro expansion to be applied to anything, and supports cases where multiple rounds of macro expansion are required by the spec.
* Macroresult code = 0
standard error = {
}
standard output = {
{
"parameters": [
],
"entryPoints": [
{
"name": "main",
"stage:": "fragment",
"parameters": [
{
"name": "input",
"stage": "fragment",
"binding": {"kind": "varyingInput", "index": 0},
"type": {
"kind": "struct",
"name": "PSInput",
"fields": [
{
"name": "color",
"type": {
"kind": "vector",
"elementCount": 4,
"elementType": {
"kind": "scalar",
"scalarType": "float32"
}
},
"stage": "fragment",
"binding": {"kind": "varyingInput", "index": 0},
"semanticName": "COLOR"
},
{
"name": "sampleIndex",
"type": {
"kind": "scalar",
"scalarType": "uint32"
},
"semanticName": "SV_SAMPLEINDEX"
}
]
}
}
],
"usesAnySampleRateInput": true,
"result:": {
"stage": "fragment",
"binding": {"kind": "varyingOutput", "index": 0},
"semanticName": "SV_TARGET",
"type": {
"kind": "vector",
"elementCount": 4,
"elementType": {
"kind": "scalar",
"scalarType": "float32"
}
}
}
}
]
}
}
|