Mano Compiler was a project I did for two courses, Computer Organization and Theory of Computation. It is a proof-of-concept compiler that converts a simple high-level language into the 25-instruction assembly dialect accepted by the Mano Machine. The result can then be assembled and executed on a simulator.
The language supports integer, array and string data types, functions, and textual output of any variable. Being a proof of concept, it also has some flaws, including sharing of local variables (but not arguments) between instances of the same function during recursion and lack of support for reading input.
The compiler is written in Python 2 and does not use anything outside the standard library. It is portable to any platform that supports Python, and can be used to generate large amounts of assembly code to test new implementations of the machine or its simulator.
Although it has little practical use, it may have educational value as an example of a very simple compiler that covers the whole path from reading plain text source code to emitting final assembly code in about 1K lines of code.
The compiler is invoked from the command line and passed the name of the file
containing the source code to be compiled, and optionally the name of the
output file. The
-O flag can be used to produce optimized code.
Once compiled, the code can be run using a simulator. However, due to the lack
of linking, the runtime library used by the compiler (included in the
distribution) has to be loaded manually. In
whole sequence of assembling, loading and running a compiled program looks
* source lib [Some assembly information, including identifier list.] * source compiled_filename [Some more assembly information.] * go [Output of the program goes here.]
- A semi-formal language definition .
- Example source code to be compiled.
- The assembly code produced by the compiler.
- A manosim session log showing the output of the above code.
- The runtime library used by the compiler.
There are several simulators for the Mano machine, although each has its own problems:
- manosim.exe or mano2.exe , the one explicitly targeted by this compiler and included in the binary distribution works well, but it is a DOS program, and does not run natively on 64-bit Windows systems, much less any kind of UNIX. However, it can be convinced to work in DOSBox or on a 16- or 32-bit virtual Windows machine. I was unable to track down its source code to recompile.
- Mark Roth's ManoSimulator is a newer open-source implementation, and can be compiled on most platforms using modern tools with minor modifications. However, it lacks I/O support, so its practical usefulness is rather limited. It also uses a slightly different assembly syntax (slashes instead of semicolons for comments) and limits the maximum length of identifiers to 3 characters, which is incompatible with Mano Compiler (but not hard to remedy).
Basic Computer Simulator
is a simulator with quite a rich GUI, written in Flash/ActionScript (of all
things). It seems to work well, but lacks textual output capabilities and
like Mark Roth's simulator, uses a slightly different syntax:
- Labels are created using a colon rather than a comma.
- Comments start with a double-slash rather than a semicolon.
- There must be exactly one space between an instruction and its arguments.
OUThas no parameters (
manosimrequires an explicit
- Programs must end with the pseudo-instruction
- javamanomachine and Mano Virtual Computer are two simulators written in Java, neither of which I could get to run properly, and my knowledge of Java is too limited to tinker with their code.