Very easy, they just pop a word then defer to their normal versions. This is probably the best case where a macro works directly so I didn't even need to write a function form for them first. One thing is that then names for the macros are quite bad right now, probably need renaming.
Oreo's Virtual Machine (OVM)
A stack based virtual machine in C11, with a dynamic register setup which acts as variable space. Deals primarily in bytes, doesn't make assertions about typing and is very simple to target.
How to build
Requires GNU make, a compliant C11 compiler. Code base has been
tested against gcc and clang, but given how the project has been
written without use of GNU'isms it shouldn't be an issue to compile
using something like tcc or another compiler (look at
here to change the compiler).
To build everything simply run make. This will build:
- instruction bytecode system which allows one to target the VM by writing and reading instruction bytecode
- VM executable which can execute bytecode (your
javaexecutable) - Assembler executable which can assemble compliant assembly code to VM bytecode
- Assembly examples which provide some source code examples on common programs one may write. Use this to figure out how to write compliant assembly.
One may also build each component individually through the corresponding recipe:
make libmake vmmake asmmake examples
Instructions to target the virtual machine
You need to link with the object files for
base.c, darr.c and
inst.c to be able to properly target the OVM.
The basic idea is to create instructions via inst_t then using the
inst(s)_write_* API to generate bytecode (and write to a file).
Then to execute the program, the virtual machine interpreter ovm.out
is used.
For clarity, one may build lib (make lib) then use the resulting
object files to link and create bytecode for the virtual machine.
Lines of code
| 216 | ./vm/runtime.h |
| 83 | ./vm/main.c |
| 718 | ./vm/runtime.c |
| 452 | ./lib/inst.c |
| 39 | ./lib/darr.h |
| 193 | ./lib/inst.h |
| 90 | ./lib/base.h |
| 39 | ./lib/base.c |
| 77 | ./lib/darr.c |
| 315 | ./asm/parser.c |
| 140 | ./asm/main.c |
| 68 | ./asm/lexer.h |
| 37 | ./asm/parser.h |
| 439 | ./asm/lexer.c |