import type { Value } from "./value" export class Scope { locals = new Map() parent?: Scope constructor(parent?: Scope) { this.parent = parent } get(name: string): Value | undefined { if (this.locals.has(name)) return this.locals.get(name)! if (this.parent) return this.parent.get(name) return undefined } set(name: string, value: Value) { if (this.locals.has(name)) this.locals.set(name, value) else if (this.parent?.has(name)) this.parent.set(name, value) else this.locals.set(name, value) } has(name: string): boolean { return this.locals.has(name) || this.parent?.has(name) || false } }