Vapor-M Language Specification
A Vapor-M program is largely the same as a Vapor program except one step closer to MIPS assembly language. The main difference is that instead of local variables, you use registers and stack memory.
The first is that instead of local variables you get 23 registers.
- Registers are specified by prefixing an identifier with "$". For example: "$r1".
- There are 23 registers: $s0..$s7, $t0..$t8, $a0..$a3, $v0, $v1.
- Registers are global to all functions (whereas local variables were local to a function activation).
To follow MIPS calling conventions, use the registers as follows:
- $s0..$s7: general use callee-saved
- $t0..$t8: general use caller-saved
- $a0..$a3: reserved for argument passing
- $v0: returning a result from a call
- $v0, $v1: can also be used as temporary registers for loading values from the stack
The second difference is the ability to store values on the stack. Each function has three stack arrays called "in", "out", and "locals". The "in" and "out" array are for passing arguments between functions. The "in" array actual refers to the "out" array of the caller. The "local" array is for function-local storage (for example: spilled registers). The sizes of these arrays are declared at the top of every function (instead of a parameter list).
Each element of each array is a 4-byte word. The indexes into the array is the word-offset (not the byte offset). Array references can be used wherever memory references can be used. So "in[1]" refers to the second element of the "in" stack array.
func Run [in 2, out 0, local 4] $r1 = in[1] local[3] = $r1 PrintString($r1) $v0 = 1 ret