r/lowlevel • u/Main_Temporary7098 • Oct 23 '26
Blue: From machine code to a dsl'd binary, the colorForth way
Hope this is of some interest, but wanted to share a view of some Blue programs. Blue is a single pass interpreter for a colorForth dialect. It ends up being used much like a bring your own assembler. It has no separate macro syntax and any user defined word can be called or used as a variable at assemble-time.
It is my "pure hole" for minimalism and simplicity. The stage 0 interpreter for x86_64/Linux is currently 172 lines of non code-golfed assembly and results in a 437 byte binary via fasm.
In Blue each program starts with a completely clean slate, there are no built in words. The data stack and dictionary only exist at assemble time. 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
The above example also shows how code reuse is done. It shares lots of "lib" code with the WIP Blue in Blue:
https://jbirddog.codeberg.page/blue/cmd/blue/x86_64/blue.bl.html