An interpreter that can produce stack code for the J5 stack machine from register code for the DCPU-16 and run it.
This project was the implementation part of my final year project at the University of York as part of my Computer Science degree course.
Requires a C++ compiler that supports C++14, and a version of the Boost library installed (only headers required). Python3 is also required for running the tests.
From there, navigate to the checked out directory, and run make
. This will produce a reg2stack
binary in the current directory.
There are several example test programs in the examples/ directory. As yet the only notable program is bsort, an implementation of bubble sort.
Very basic test suite is implemented, run make test
to check that the register and the stack outputs match.
Running ./reg2stack -vc examples/bsort.reg
will run the bsort register code on the J5 emulator.
This will result in a lot of output. If you get rid of the -v
flag and ignore stderr (e.g. append 2> /dev/null
to the command), you will only get the actual output from the stack machine.
Usage: ./reg2stack [-v] [-f] [-scr] file
-v
: Verbose output-f
: Unlimited clock speed-c
: Convert register code-s
: Stack (J5) interpreter-r
: Register (DCPU-16) interpreter
How the stack scheduler determines blocks is very stupid, as it just splits based on labels. Therefore, in the case that a loop doesn't have a determined "end" point specified with a label, the optimiser will think that the rest of the program is a single block, i.e. including the stuff outside the loop definition. A workaround is to add an (unused) label at the end of the loop "block"