This commit is contained in:
Chris Wanstrath 2025-10-05 21:17:54 -07:00
parent 0a7a3dcfdb
commit 2f2a8fe9f2
3 changed files with 29 additions and 0 deletions

14
bin/reef Executable file
View File

@ -0,0 +1,14 @@
#!/usr/bin/env bun
import { toBytecode } from "../src/bytecode"
import { run } from "../src/index"
import { toJs } from "../src/value"
const file = Bun.argv[2]
if (!file || !await Bun.file(file).exists()) {
console.error("usage: reef <path/to/bytecode.reef>")
process.exit(1)
}
const value = await run(toBytecode(await Bun.file(file).text()))
console.log(toJs(value))

3
examples/add.reef Normal file
View File

@ -0,0 +1,3 @@
PUSH 1
PUSH 2
ADD

View File

@ -120,3 +120,15 @@ export function isEqual(a: Value, b: Value): boolean {
case 'function': return false // functions never equal
}
}
export function toJs(v: Value): any {
switch (v.type) {
case 'null': return null
case 'boolean': return v.value
case 'number': return v.value
case 'string': return v.value
case 'array': return v.value.map(toJs)
case 'dict': return Object.fromEntries(v.value.entries().map(([k, v]) => [k, toJs(v)]))
case 'function': return '<function>'
}
}