Conversation

who needs an assembler (or a parser) when you have C99 designated initializers
A stack-based virtual machine written in C99. The virtual machine reads from a tiny array called "RAM" of 16-bit unsigned integers. It is implemented via a switch statement that checks the current operator under the instruction pointer, and executes it, or, failing to find an operator, interprets it as a "CALL" instruction. The VM only has 32 operators, mostly arithmetic, branching, stack manipulation, get, and set.

To get things going, the RAM is initialized via an array initializer, and it uses C99 designated initializer syntax to make sure everything is in the right place. Labels are declared in a separate enum, with values that are carefully chosen not to overlap (but if an overlap were to occur, the compiler would warn us). The labels are used in the initializer to make sure each piece of code in "RAM" ends up where we want it.

So, this is effectively an embedded domain-specific language (EDSL) in C99. And it lies somewhere in between forth and assembly.
6
47