From df3d483de5c5d3b71b6c843c5744f4dabbc15231 Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Wed, 29 Oct 2025 12:21:02 -0700 Subject: [PATCH] update repl and shrimp --- bin/repl | 8 ++++---- bin/shrimp | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bin/repl b/bin/repl index 5ae39b9..052f481 100755 --- a/bin/repl +++ b/bin/repl @@ -1,7 +1,7 @@ #!/usr/bin/env bun import { Compiler } from '../src/compiler/compiler' -import { colors, formatValue, globalFunctions } from '../src/prelude' +import { colors, formatValue, globals } from '../src/prelude' import { VM, Scope, bytecodeToString } from 'reefvm' import * as readline from 'readline' import { readFileSync, writeFileSync } from 'fs' @@ -48,7 +48,7 @@ async function repl() { return } - vm ||= new VM({ instructions: [], constants: [] }, globalFunctions) + vm ||= new VM({ instructions: [], constants: [] }, globals) if (['/exit', 'exit', '/quit', 'quit'].includes(trimmed)) { console.log(`\n${colors.yellow}Goodbye!${colors.reset}`) @@ -147,7 +147,7 @@ async function repl() { codeHistory.push(trimmed) try { - const compiler = new Compiler(trimmed) + const compiler = new Compiler(trimmed, Object.keys(globals)) vm.appendBytecode(compiler.bytecode) @@ -211,7 +211,7 @@ async function loadFile(filePath: string): Promise<{ vm: VM; codeHistory: string console.log(`${colors.dim}Loading ${basename(filePath)}...${colors.reset}`) - const vm = new VM({ instructions: [], constants: [] }, globalFunctions) + const vm = new VM({ instructions: [], constants: [] }, globals) await vm.run() const codeHistory: string[] = [] diff --git a/bin/shrimp b/bin/shrimp index 2260519..49cd7f3 100755 --- a/bin/shrimp +++ b/bin/shrimp @@ -1,7 +1,7 @@ #!/usr/bin/env bun import { Compiler } from '../src/compiler/compiler' -import { colors, globalFunctions } from '../src/prelude' +import { colors, globals } from '../src/prelude' import { VM, fromValue, bytecodeToString } from 'reefvm' import { readFileSync, writeFileSync, mkdirSync } from 'fs' import { randomUUID } from "crypto" @@ -11,8 +11,8 @@ import { join } from 'path' async function runFile(filePath: string) { try { const code = readFileSync(filePath, 'utf-8') - const compiler = new Compiler(code) - const vm = new VM(compiler.bytecode, globalFunctions) + const compiler = new Compiler(code, Object.keys(globals)) + const vm = new VM(compiler.bytecode, globals) await vm.run() return vm.stack.length ? fromValue(vm.stack[vm.stack.length - 1]) : null } catch (error: any) {