forked from defunkt/ReefVM
native example
This commit is contained in:
parent
7d2047f3a6
commit
000eb7ad92
21
examples/native.ts
Normal file
21
examples/native.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
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()
|
||||
Loading…
Reference in New Issue
Block a user