lib exports

This commit is contained in:
Chris Wanstrath 2025-10-06 09:11:22 -07:00
parent 000eb7ad92
commit d057bf4b10
4 changed files with 15 additions and 6 deletions

View File

@ -1,6 +1,4 @@
import { toBytecode } from "#bytecode" import { VM, toBytecode, type Value, toString, toNull } from "#reef"
import { VM } from "#vm"
import { type Value, toString, toValue } from "#value"
const bytecode = toBytecode(` const bytecode = toBytecode(`
PUSH 5 PUSH 5
@ -13,7 +11,7 @@ const vm = new VM(bytecode)
vm.registerFunction('print', (...args: Value[]): Value => { vm.registerFunction('print', (...args: Value[]): Value => {
console.log(...args.map(toString)) console.log(...args.map(toString))
return toValue(null) return toNull()
}) })
console.write('5 + 10 = ') console.write('5 + 10 = ')

View File

@ -1,8 +1,12 @@
import type { Bytecode } from "./bytecode" import type { Bytecode } from "./bytecode"
import type { Value } from "./value" import { type Value } from "./value"
import { VM } from "./vm" import { VM } from "./vm"
export async function run(bytecode: Bytecode): Promise<Value> { export async function run(bytecode: Bytecode): Promise<Value> {
const vm = new VM(bytecode) const vm = new VM(bytecode)
return await vm.run() return await vm.run()
} }
export { type Bytecode, toBytecode } from "./bytecode"
export { type Value, toValue, toString, toNumber, toJs, toNull } from "./value"
export { VM } from "./vm"

View File

@ -131,4 +131,8 @@ export function toJs(v: Value): any {
case 'dict': return Object.fromEntries(v.value.entries().map(([k, v]) => [k, toJs(v)])) case 'dict': return Object.fromEntries(v.value.entries().map(([k, v]) => [k, toJs(v)]))
case 'function': return '<function>' case 'function': return '<function>'
} }
}
export function toNull(): Value {
return toValue(null)
} }

View File

@ -28,6 +28,9 @@
"paths": { "paths": {
"#*": [ "#*": [
"./src/*" "./src/*"
],
"#reef": [
"./src/index.ts"
] ]
}, },
} }