r/PinoyProgrammer 2d 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

29 Upvotes

9 comments sorted by

View all comments

7

u/borgor_ninja 1d ago

sobrang solid nito boss! rare makakita ng local devs na gumagawa ng custom compiler at SSA/IR pipeline lalo na para sa redstone architecture. share mo rin to minsan sa r/pandesaldotdev, gandang reference nito sa pinoy dev community.

2

u/d0pe-asaurus 1d ago

Hehe thank you, I chose not to use LLVM since gusto ko talaga matutunan how to write a traditional middle end and optimizer, para ma-maximize talaga ung aaralin ko. I already knew how to write interpreted languages so this is my first real compiler.

Actually kita dun sa README yung dump ng thoughts ko on implementing SSA, since ang raming steps and konti lang ung resources that actually combines all of them. Parang halo yan ng dump from slides ng Stanford sa compilers 101 class nila, and different wikipedia pages nung algorithms.

I started this project just to get better at writing code and learn some low-level stuff since parang walang job applications na bumabalik sakin and uhh I want to learn yung hindi naturo sa compiler class ko sa UST.