Writing a runtime system for Jzero
In a programming language implementation, the runtime system is the code that is included to provide basic functionalities needed for the generated code to run. Generally, the more high-level the language is and the greater its distance from the underlying hardware, the larger the runtime system. Since Jzero is a toy language, its toy runtime system is incomplete and only supports a few internal helper functions such as deref()
and some basic functions for input and output.
These functions are written in the implementation language (in our case, Unicon or Java), not the Jzero language. Here is the deref()
method in Unicon. Additional runtime system functions are left as exercises for the reader:
method deref(reg, od)
case reg of {
Op.R_ABS: {
if od < finstr then return data.word(od)
else return code[od]
}
Op.R_IMM: { return od }
Op.R_STACK: { return stack[bp+od] }
default: { stop(...