Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gidra5 committed Dec 18, 2024
1 parent d86bd43 commit 853dd18
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ export class Environment {
return [...new Set(keys)];
}

readonlyKeys(): symbol[] {
const keys: symbol[] = [...this.readonly.keys()];
if (this.parent) keys.push(...this.parent.readonlyKeys());
return [...new Set(keys)];
}

mutableKeys(): symbol[] {
const keys: symbol[] = [...this.mutable.keys()];
if (this.parent) keys.push(...this.parent.mutableKeys());
return [...new Set(keys)];
}

shallowCopy(): Environment {
const copy = new Environment({ parent: this.parent });
copy.readonly = new Map(this.readonly);
Expand Down
4 changes: 2 additions & 2 deletions src/evaluate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const incAssign = (position: Position, context: CompileContext) => {
context.env.has(patternKey),
undeclaredName(
patternKey.description!,
context.env.keys().map((k) => k.description ?? String(k))
context.env.mutableKeys().map((k) => k.description ?? String(k))
)
);

Expand Down Expand Up @@ -200,7 +200,7 @@ const assign = (position: Position, context: CompileContext) => {
context.env.set(patternKey, value),
undeclaredName(
patternKey.description!,
context.env.keys().map((k) => k.description ?? String(k))
context.env.mutableKeys().map((k) => k.description ?? String(k))
)
);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ program
console.log('Starting REPL...');
const file = '<repl>';

const context = newContext();
console.log('Waiting for next input...');
const rl = readline.createInterface({ input, output, prompt: '>> ' });
rl.prompt();
Expand All @@ -42,7 +43,6 @@ program
default: {
const fileId = addFile(file, line);
const compileContext = newCompileContext(fileId, file);
const context = newContext();
const compiled = compileScriptString(line, compileContext);
const result = await compiled(context);
console.dir(result, { depth: null });
Expand Down

0 comments on commit 853dd18

Please sign in to comment.