update repl and shrimp

This commit is contained in:
Chris Wanstrath 2025-10-29 12:21:02 -07:00
parent 4fb58483f0
commit df3d483de5
2 changed files with 7 additions and 7 deletions

View File

@ -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[] = []

View File

@ -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) {