Skip to content

Instantly share code, notes, and snippets.

@broquaint
Created February 9, 2024 08:26
Show Gist options
  • Save broquaint/47b41f119dcc0def381db04d7a651a18 to your computer and use it in GitHub Desktop.
Save broquaint/47b41f119dcc0def381db04d7a651a18 to your computer and use it in GitHub Desktop.
The deno TypeScript compiler output for env.ts
// Plucked from the output of: deno bundle impls/ts/step3_env.ts
class Env {
outer;
data;
constructor(outer){
this.outer = outer ?? null;
this.data = {};
}
set(k, v) {
this.data[k.value] = v;
return v;
}
find(k) {
if (k.value in this.data) return this;
else if (this.outer) return this.outer.find(k);
else return null;
}
get(k) {
const env = this.find(k);
if (env !== null) return env.data[k.value];
else throw `The symbol '${k.value}' not found in the environment`;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment