asm
Generated by tinox doc
A minimal bytecode assembler for a toy stack VM: Assembler builds up a byte array of opcodes/operands (with label support), Ops holds the opcode constants (Push, Add, Jmp, Call, ...).
Assemble bytecode
import tinox.core.asm;
class Main
{
fnc main() -> Int32
{
let asm: Assembler = Assembler::new();
// push 1, push 2, add, halt
Assembler::emit(asm, Ops::Push());
Assembler::emitInt(asm, 1);
Assembler::emit(asm, Ops::Push());
Assembler::emitInt(asm, 2);
Assembler::emit(asm, Ops::Add());
Assembler::emit(asm, Ops::Halt());
let bytecode: List<Int64> = Assembler::resolveLabels(asm);
println("bytecode length: " + bytecode.len().toString());
return 0;
}
}
fn tinoxBytesToString(bytes: List<Int64>) → String
class Assembler
Fields
bytecode | List<Int64> | |
labels | Map<String, Int64> |
Methods
fn new() → Assembler
fn emit(asm: Assembler, op: Int64) → Nothing
fn emitInt(asm: Assembler, value: Int64) → Nothing
fn emitLabel(asm: Assembler, name: String) → Nothing
fn resolveLabels(asm: Assembler) → List<Int64>
fn toBytes(asm: Assembler) → String
class Ops
Methods
fn Nop() → Int64
fn Halt() → Int64
fn Load() → Int64
fn Store() → Int64
fn Push() → Int64
fn Pop() → Int64
fn Add() → Int64
fn Sub() → Int64
fn Mul() → Int64
fn Div() → Int64
fn Jmp() → Int64
fn Jz() → Int64
fn Jnz() → Int64
fn Cmp() → Int64
fn Call() → Int64
fn Ret() → Int64