forked from defunkt/ReefVM
19 lines
326 B
TypeScript
19 lines
326 B
TypeScript
import { VM, toBytecode, type Value, toString, toNull } from "#reef"
|
|
|
|
const bytecode = toBytecode(`
|
|
PUSH 5
|
|
PUSH 10
|
|
ADD
|
|
CALL_NATIVE print
|
|
`)
|
|
|
|
const vm = new VM(bytecode)
|
|
|
|
vm.set('print', (...args: Value[]): Value => {
|
|
console.log(...args.map(toString))
|
|
return toNull()
|
|
})
|
|
|
|
console.write('5 + 10 = ')
|
|
|
|
await vm.run() |