native -> global

This commit is contained in:
Chris Wanstrath 2025-10-26 13:05:31 -07:00
parent d3e83e17b2
commit 7387c56a20
2 changed files with 5 additions and 5 deletions

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bun #!/usr/bin/env bun
import { Compiler } from '../src/compiler/compiler' import { Compiler } from '../src/compiler/compiler'
import { colors, formatValue, nativeFunctions } from '../src/prelude' import { colors, formatValue, globalFunctions } from '../src/prelude'
import { VM, Scope, bytecodeToString } from 'reefvm' import { VM, Scope, bytecodeToString } from 'reefvm'
import * as readline from 'readline' import * as readline from 'readline'
import { readFileSync, writeFileSync } from 'fs' import { readFileSync, writeFileSync } from 'fs'
@ -48,7 +48,7 @@ async function repl() {
return return
} }
vm ||= new VM({ instructions: [], constants: [] }, nativeFunctions) vm ||= new VM({ instructions: [], constants: [] }, globalFunctions)
if (['/exit', 'exit', '/quit', 'quit'].includes(trimmed)) { if (['/exit', 'exit', '/quit', 'quit'].includes(trimmed)) {
console.log(`\n${colors.yellow}Goodbye!${colors.reset}`) console.log(`\n${colors.yellow}Goodbye!${colors.reset}`)
@ -211,7 +211,7 @@ async function loadFile(filePath: string): Promise<{ vm: VM; codeHistory: string
console.log(`${colors.dim}Loading ${basename(filePath)}...${colors.reset}`) console.log(`${colors.dim}Loading ${basename(filePath)}...${colors.reset}`)
const vm = new VM({ instructions: [], constants: [] }, nativeFunctions) const vm = new VM({ instructions: [], constants: [] }, globalFunctions)
await vm.run() await vm.run()
const codeHistory: string[] = [] const codeHistory: string[] = []

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bun #!/usr/bin/env bun
import { Compiler } from '../src/compiler/compiler' import { Compiler } from '../src/compiler/compiler'
import { colors, nativeFunctions } from '../src/prelude' import { colors, globalFunctions } from '../src/prelude'
import { VM, fromValue, bytecodeToString } from 'reefvm' import { VM, fromValue, bytecodeToString } from 'reefvm'
import { readFileSync, writeFileSync, mkdirSync } from 'fs' import { readFileSync, writeFileSync, mkdirSync } from 'fs'
import { randomUUID } from "crypto" import { randomUUID } from "crypto"
@ -12,7 +12,7 @@ async function runFile(filePath: string) {
try { try {
const code = readFileSync(filePath, 'utf-8') const code = readFileSync(filePath, 'utf-8')
const compiler = new Compiler(code) const compiler = new Compiler(code)
const vm = new VM(compiler.bytecode, nativeFunctions) const vm = new VM(compiler.bytecode, globalFunctions)
await vm.run() await vm.run()
return vm.stack.length ? fromValue(vm.stack[vm.stack.length - 1]) : null return vm.stack.length ? fromValue(vm.stack[vm.stack.length - 1]) : null
} catch (error: any) { } catch (error: any) {