This document describes all available instructions of the Lola intermediate language as well as it's encoding in a binary stream.
The following list contains each instruction and describes it's effects on the virtual machine state.
nop
No operationstore_global_name
stores global variable by name [ var:str ]
str
load_global_name
loads global variable by name [ var:str ]
str
push_str
pushes string literal [ val:str ]
str
push_num
pushes number literal [ val:f64 ]
val
array_pack
packs num elements into an array [ num:u16 ]
num
elements front-to-back and packs them into an array front to backcall_fn
calls a function [ fun:str ] [argc:u8 ]
argc
elements front-to-back into the argument list, then calls function fun
call_obj
calls an object method [ fun:str ] [argc:u8 ]
argc
elements front-to-back into the argument list,fun
pop
destroys stack top
add
adds rhs and lhs together
sub
subtracts rhs and lhs together
mul
multiplies rhs and lhs together
div
divides rhs and lhs together
mod
modulo division of rhs and lhs
(-5 % 2) == 1
bool_and
conjunct rhs and lhs
true
when both left and right hand side are true
bool_or
disjuncts rhs and lhs
true
when either of left or right hand side is true
bool_not
logically inverts stack top
true
if the value was false
, otherwise true
negate
arithmetically inverts stack top
eq
neq
less_eq
true
when left hand side is less or equal to the right hand side.greater_eq
true
when left hand side is greater or equal to the right hand side.less
true
when left hand side is less to the right hand side.greater
true
when left hand side is greater to the right hand side.jmp
jumps unconditionally [target:u32 ]
target
jnf
jump when not false [target:u32 ]
true
target
iter_make
iter_next
true
false
array_store
array_load
ret
returns from the current function with Void
void
valuestore_local
stores a local variable [index : u16 ]
load_local
loads a local variable [index : u16 ]
retval
returns from the current function with a value
jif
jump when false [ target:u32 ]
false
target
store_global_idx
stores global variable by index [ idx:u16 ]
load_global_idx
loads global variable by index [ idx:u16 ]
push_true
true
push_false
false
push_void
The instructions are encoded in an intermediate language. Each instruction is encoded by a single byte, followed by arguments different for each instruction.
Argument types are noted in name:type
notation where type is one of the following: str
, f64
, u16
, u8
, u32
. The encoding of these types is described below the table.
Instruction | Value | Arguments | Description |
---|---|---|---|
nop | 0 | No operation | |
scope_push | 1 | reserved | |
scope_pop | 2 | reserved | |
declare | 3 | var:str |
reserved |
store_global_name | 4 | var:str |
stores global variable by name |
load_global_name | 5 | var:str |
loads global variable by name |
push_str | 6 | val:str |
pushes string literal |
push_num | 7 | val:f64 |
pushes number literal |
array_pack | 8 | num:u16 |
packs num elements into an array |
call_fn | 9 | fun:str, argc:u8 |
calls a function |
call_obj | 10 | fun:str, argc:u8 |
calls an object method |
pop | 11 | destroys stack top | |
add | 12 | adds rhs and lhs together | |
sub | 13 | subtracts rhs and lhs together | |
mul | 14 | multiplies rhs and lhs together | |
div | 15 | divides rhs and lhs together | |
mod | 16 | reminder division of rhs and lhs | |
bool_and | 17 | conjunct rhs and lhs | |
bool_or | 18 | disjuncts rhs and lhs | |
bool_not | 19 | logically inverts stack top | |
negate | 20 | arithmetically inverts stack top | |
eq | 21 | ||
neq | 22 | ||
less_eq | 23 | ||
greater_eq | 24 | ||
less | 25 | ||
greater | 26 | ||
jmp | 27 | target:u32 |
jumps unconditionally |
jnf | 28 | target:u32 |
jump when not false |
iter_make | 29 | ||
iter_next | 30 | ||
array_store | 31 | ||
array_load | 32 | ||
ret | 33 | returns from the current function with Void | |
store_local | 34 | index:u16 |
|
load_local | 35 | index:u16 |
|
retval | 37 | returns from the current function with a value | |
jif | 38 | target:u32 |
jump when false |
store_global_idx | 39 | idx:u16 |
stores global variable by index |
load_global_idx | 40 | idx:u16 |
loads global variable by index |
push_true | 41 | pushes a boolean true |
|
push_false | 42 | pushes a boolean false |
|
push_void | 43 | pushes a void value. |
u8
, u16
, u32
Each of these corresponds to a single, little endian encoded unsigned integer with either 8, 16 or 32 bits width.
f64
A 64 bit floating point number, encoded with IEEE 754 binary64 format, also known as double
.
str
A literal string value with a maximum of 65535 bytes length. It's text is encoded in an application-defined encoding where all values below 128 must follow the ASCII encoding scheme. Values equal or above 128 are interpreted by an application-defined logic.
A string is started by a 16 bit unsigned integer defining the length of the string, followed by length bytes of content.
Rationale: The encoding is not fixed to UTF-8 as the language is meant to be embedded into games where a unicode encoding would be a burden to the player. Thus, a string is defined to be "at least" ASCII-compatible and allows UTF-8 encoding, but does not enforce this.