diff --git a/examples/native.ts b/examples/native.ts index c4b6344..70d3e0d 100644 --- a/examples/native.ts +++ b/examples/native.ts @@ -1,6 +1,4 @@ -import { toBytecode } from "#bytecode" -import { VM } from "#vm" -import { type Value, toString, toValue } from "#value" +import { VM, toBytecode, type Value, toString, toNull } from "#reef" const bytecode = toBytecode(` PUSH 5 @@ -13,7 +11,7 @@ const vm = new VM(bytecode) vm.registerFunction('print', (...args: Value[]): Value => { console.log(...args.map(toString)) - return toValue(null) + return toNull() }) console.write('5 + 10 = ') diff --git a/src/index.ts b/src/index.ts index eae608b..26308d7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,12 @@ import type { Bytecode } from "./bytecode" -import type { Value } from "./value" +import { type Value } from "./value" import { VM } from "./vm" export async function run(bytecode: Bytecode): Promise { const vm = new VM(bytecode) return await vm.run() -} \ No newline at end of file +} + +export { type Bytecode, toBytecode } from "./bytecode" +export { type Value, toValue, toString, toNumber, toJs, toNull } from "./value" +export { VM } from "./vm" \ No newline at end of file diff --git a/src/value.ts b/src/value.ts index 4bf524f..14acdd0 100644 --- a/src/value.ts +++ b/src/value.ts @@ -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 'function': return '' } +} + +export function toNull(): Value { + return toValue(null) } \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index de4c31b..78f80c6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -28,6 +28,9 @@ "paths": { "#*": [ "./src/*" + ], + "#reef": [ + "./src/index.ts" ] }, }