Today's brain-racking topic: Deciding on the intermediate output format (kinda l...
Luna Dragofelis ΘΔ🏳️⚧️🐱& @LunaDragofelis@void.lgbt
Today's brain-racking topic: Deciding on the intermediate output format (kinda like the return type) of the #Kittyscript core compiler (midend), before that gets handed off to the target specific backend.
The options I considered:
1: The same kind of Lisp-like tree that came in but with all macros expanded.
2: It all gets written mutably into the environment context (or alternatively, the environment context gets immutably updated).
3: A simplified tree structure of a finite set of element types, like Guile Scheme's Tree-IL.
4: Some kind of Single Static Assignment or Continuation Passing Style representation, as commonly seen in more low-level compilers.
5: The format is dependent on the current compile target (Java bytecode, C source, JS source, LLVM bytecode…) and opaque to the rest of the compiler.
Problem with option 1: Might need multiple passes, and what will happen with the information accumulating in the context - pass it alongside the tree?
Problem with options 3 and 4: They will struggle hard to represent target specific stuff, especially for higher level targets like Java bytecode. The programmer might want to define target specific details to be passed through to the output and not all of them can be represented as a run-time expression - Java class files should be defined at compile time.
Problem with option 5: It's a mess.
I think I'm mostly going with option 2, and put some elements of the other options into the context (context can contain code expressions and target specific data).
The options I considered:
1: The same kind of Lisp-like tree that came in but with all macros expanded.
2: It all gets written mutably into the environment context (or alternatively, the environment context gets immutably updated).
3: A simplified tree structure of a finite set of element types, like Guile Scheme's Tree-IL.
4: Some kind of Single Static Assignment or Continuation Passing Style representation, as commonly seen in more low-level compilers.
5: The format is dependent on the current compile target (Java bytecode, C source, JS source, LLVM bytecode…) and opaque to the rest of the compiler.
Problem with option 1: Might need multiple passes, and what will happen with the information accumulating in the context - pass it alongside the tree?
Problem with options 3 and 4: They will struggle hard to represent target specific stuff, especially for higher level targets like Java bytecode. The programmer might want to define target specific details to be passed through to the output and not all of them can be represented as a run-time expression - Java class files should be defined at compile time.
Problem with option 5: It's a mess.
I think I'm mostly going with option 2, and put some elements of the other options into the context (context can contain code expressions and target specific data).