The Interpreter of Arcane OpCodes
Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in Move.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Interpreter
ARCANUM SCHOOL: Divination // Linguistics
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
module arcane::interpreter {
use std::vector;
struct Context has drop {
stack: vector<u64>,
}
public fun new_context(): Context {
Context { stack: vector::empty() }
}
public fun eval(ctx: &mut Context, opcode: u8) {
if (opcode == 0x01) { // PUSH 1
vector::push_back(&mut ctx.stack, 1);
} else if (opcode == 0x02) { // ADD
let a = vector::pop_back(&mut ctx.stack);
let b = vector::pop_back(&mut ctx.stack);
vector::push_back(&mut ctx.stack, a + b);
}
}
}
Runic Tags:
#behavioral
#interpreter
#move
#opcodes
#vm