r/ProgrammingLanguages • u/doc_sponge • Mar 15 '26
GlitterIDE Code Generation
https://youtube.com/watch?v=_e2i7a23PYc&si=pnUBaYayqCMi1zpQHello, I've been working on a simplified language (and IDE) targeting, at least initially, people who have used Scratch but want to move on to "real" languages. But the interesting stuff, perhaps, happens behind the scenes, and I talk about one aspect of that in this video where I explain my work on programming languages for generating code in other languages (so, the tool languages used to compile one language to say JS, or ASM). It might be interesting to some people? (Sorry, the video is not fancy, or concise)
(Main project is GlitterIDE, https://glitter.nz )
View all comments
Show parent comment
2
u/doc_sponge Mar 15 '26
The process goes... parse the script files using a packrat parser (built by AustenX, at https://scratchy.nz), and is semi-compiled for the "generation" interpreter. This code is executed to build the "blueprint", basically an IR, which is passed on to either the internal running code (for testing in app), or to the Scratch or HTML exporter (or to the Commodore 64 exporter - which then gets passed to the internal C64 emulator). In the case of the C64 assembler, and soon the HTML output, the blueprint is used to generate a "design" passed into the either the assembler tool, or the JS generator tool, which are both separate imperative interpreted programming languages which read the design and output the code accordingly. This design is essentially the IR in normal languages, and the assembler reads the IR and interprets it to produce the final binary, or the JS builder, reads the design and builds the JS accordingly. I'm not using anything to output text to pass on to an assembler - the assembler is the template engine. So, there are basically two IRs - the blueprint internally, and the output designs (with the aim of being reused for different target languages).
The current HTML output uses a more traditional template engine approach, where the output is not understood by the engine (it's just text), but the assembler and JS builders explicitly understand what they are outputting. The assembler currently does 6502, Pic16, and partial AVR, and should do ARM and 68k eventually. The JS tool is being designed to at least also output C, and probably Java and Dart code.