import { resolve } from 'path' import { readFileSync } from 'fs' import { Compiler } from '#compiler/compiler' import { type Value, VM, Scope } from 'reefvm' export const load = async function (this: VM, path: string): Promise> { const scope = this.scope const pc = this.pc const fullPath = resolve(path) + '.sh' const code = readFileSync(fullPath, 'utf-8') this.pc = this.instructions.length this.scope = new Scope(scope) const compiled = new Compiler(code) this.appendBytecode(compiled.bytecode) await this.continue() const module: Record = {} for (const [name, value] of this.scope.locals.entries()) module[name] = value this.scope = scope this.pc = pc this.stopped = false return module }