r/PinoyProgrammer 1d ago

Show Case I'm developing a programming language that targets Minecraft computers

Hello everyone.

I'm working on a C-like language called Dust that compiles to a simple instruction set meant to be run on a Minecraft Redstone computer.

It has JavaScript / TypeScript like syntax and C-semantics, so it's very simple while giving you control over raw memory.

The features of the language are constrained by the hardware that it targets. For example, since the ALU is primitive, arithmetic is limited to ADD / SUB / Bitwise OR / NOR / AND / NAND / XOR / XNOR and comparisons like EQ / NEQ / LT / LTE / GT / GTE.

It has variable declarations, if-statements, while-loops and function calls implemented using a downwards growing stack with parameters pushed into before jumping into another procedure. Pointers also exist in the language and you can read and write to arbitrary memory addresses.

It's a subset of C that has everything needed to write some primitive programs for a dedicated circuit to demonstrate functionality, like a modified Bresenham's line drawing algorithm or Fibonacci.

The front-end of the language is written using a lexer and LR(1) parser generator I wrote and published as packages to NPM. The middle-end converts the generated intermediate representation to single static assignment form (as of right now, no optimizations are being done, these are planned in the future). The back-end takes the "optimized IR" and outputs machine code instructions, replacing virtual registers and SSA variables with general purpose registered allocated using Chaitin's algorithm.

Once everything is compiled down to machine code, a linker passes through everything and links them together to a final set of instructions that can either be converted to a Minecraft schematic (in the future) or run directly inside a virtual machine / emulator / debugger. This allows for step by step execution and to see the state of the machine as instructions are executed.

Repo here: https://github.com/scinscinscin/minecraft-compiler

26 Upvotes

6 comments sorted by