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

21 lines
394 B
TypeScript

import { toBytecode } from "#bytecode"
import { VM } from "#vm"
import { type Value, toString, toValue } from "#value"
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 toValue(null)
})
console.write('5 + 10 = ')
await vm.run()