Switching to ML style type annotations. not separate statement from the expression

This commit is contained in:
Dustin Swan 2026-03-26 16:05:22 -06:00
parent 6acec5641c
commit f3c3a76671
No known key found for this signature in database
GPG key ID: 30D46587E2100467
6 changed files with 35 additions and 36 deletions

View file

@ -10,7 +10,7 @@ type CompileCtx = {
};
const defaultCtx: CompileCtx = { useStore: true, bound: new Set(), topLevel: new Set() };
export const definitions: Map<string, AST> = new Map();
export const definitions: Map<string, Definition> = new Map();
export const dependencies: Map<string, Set<string>> = new Map();
export const dependents: Map<string, Set<string>> = new Map();
export const astRegistry = new Map<number, AST>();
@ -226,7 +226,7 @@ export function compileAndRun(defs: Definition[]) {
const topLevel = new Set(defs.map(d => d.name));
for (const def of defs) {
definitions.set(def.name, def.body);
definitions.set(def.name, def);
const free = freeVars(def.body);
const deps = new Set([...free].filter(v => topLevel.has(v)));
dependencies.set(def.name, deps);
@ -364,7 +364,9 @@ function patternVars(pattern: Pattern): string[] {
}
export function recompile(name: string, newAst: AST) {
definitions.set(name, newAst);
const existing = definitions.get(name);
definitions.set(name, { kind: 'definition', name, body: newAst, annotation: existing?.annotation });;
// definitions.set(name, newAst);
const topLevel = new Set(definitions.keys());
const free = freeVars(newAst);
@ -394,7 +396,7 @@ export function recompile(name: string, newAst: AST) {
collectDependents(name);
for (const defName of toRecompile) {
const ast = definitions.get(defName)!;
const ast = definitions.get(defName)!.body;
const compiled = compile(ast);
const fn = new Function('store', `return ${compiled}`);