ReefVM/examples/native.ts
2025-10-06 09:11:22 -07:00

19 lines
339 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.registerFunction('print', (...args: Value[]): Value => {
console.log(...args.map(toString))
return toNull()
})
console.write('5 + 10 = ')
await vm.run()