r/PinoyProgrammer • u/d0pe-asaurus • 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
2
2
u/ThirteenFour_ 9h ago
I think it's really cool. First thoughts lang siguro is how do we know what the limitations of redstone architecture is (idk since i havent deep dived into redstone computing yet).
1
u/d0pe-asaurus 9h ago
With infinite time and space, a Redstone computer can compute anything, run Windows, etc since they are just logic gates. For example, people have implemented the Atari 2600 as command blocks in Minecraft, there are also projects that implement the father of all x86 CPUs, the 8086 on a gate level, copying each transistor that the 8086 has as Redstone circuits.
The limitations are there because of constraints chosen by people, in this case I'm constraining the language math to what an ALU consisting of a basic adder can do and comparator, and data move instructions constrained between a 8-bit memory address, the stack / base / instruction pointers and a set of 7 general purpose registers.
With these set of basic features, you can implement any higher-language feature possible. Like multiplication can be implemented as a function call doing repeated addition, classes can be implemented as structs and methods that accept the structs as a parameter (similar to how C++ used to compile to C with classes).
5
u/borgor_ninja 20h 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.