r/tinycode • u/Main_Temporary7098 • 2h ago
Showcase Blue, minimal colorForth interpreter in 437 bytes
codeberg.orgJust stumbled upon this sub and thought this might be of interest (if nothing else once you see where the data stack is stored you may lol a little). It is an interpreter for my colorForth dialect in 172 lines of non code-golfed x86_64 asm. Assembles with fasm to 437 bytes of unsafe as hell fun. Probably could be smaller but I've mainly been focused on the simplicity of the entire system.
In Blue each program starts with a completely clean slate, there are no built in words. So using the colors:
red word: define label
green word: compile call/jmp to word in output
green number: write number to output
blue word: execute word at assemble time
blue number: push number onto the data stack
magenta word: push address of word onto the data stack
You dsl yourself an artisanal binary, brick by brick. Blue source is binary bytecode, so here are some html views of what a program might look like. The first is non typical, but is likely the most minimal Blue program that emits a valid binary. 124 byte version of `/bin/true`:
https://jbirddog.codeberg.page/blue/example/x86_64/true.b.html
However this is more representative of an actual Blue program and shows how one goes from hand jit'ing with green numbers to higher level words, macros, variables and assemble-time execution of user defined words. This yields a 129 byte binary:
https://jbirddog.codeberg.page/blue/example/x86_64/true2.bl.html
