diff --git a/compiler/check/checker.ts b/compiler/check/checker.ts index 01d9491..c156d2d 100644 --- a/compiler/check/checker.ts +++ b/compiler/check/checker.ts @@ -1,15 +1,16 @@ import * as ast from "../ast/mod.ts"; import { Ctx, File } from "../ctx.ts"; import { Span } from "../diagnostics.ts"; +import { AstId, IdMap } from "../ids.ts"; import { Resols } from "../resolve/resolver.ts"; import { tyToString } from "../ty/to_string.ts"; import { Ty } from "../ty/ty.ts"; import { exhausted, Res, todo } from "../util.ts"; export class Checker { - private itemTys = new Map(); - private exprTys = new Map(); - private tyTys = new Map(); + private itemTys = new IdMap(); + private exprTys = new IdMap(); + private tyTys = new IdMap(); private currentFile: File; diff --git a/compiler/ctx.ts b/compiler/ctx.ts index 6072567..e53e5b6 100644 --- a/compiler/ctx.ts +++ b/compiler/ctx.ts @@ -6,7 +6,8 @@ import { Report, Span, } from "./diagnostics.ts"; -import { File, IdentId, IdMap, Ids } from "./ids.ts"; +import { DefId, File, IdentId, IdMap, Ids } from "./ids.ts"; +export { type File } from "./ids.ts"; export class Ctx { private fileIds = new Ids(); @@ -105,10 +106,6 @@ export class Ctx { // - private defIds = new Ids(); - - // - public report(rep: Report) { this.reports.push(rep); this.reportImmediately(rep); diff --git a/compiler/main.ts b/compiler/main.ts index 4844f9c..b113337 100644 --- a/compiler/main.ts +++ b/compiler/main.ts @@ -1,8 +1,7 @@ import * as path from "jsr:@std/path"; import { Parser } from "./parse/parser.ts"; import * as ast from "./ast/mod.ts"; -import { Ctx } from "./ctx.ts"; -import { File } from "./ctx.ts"; +import { Ctx, File } from "./ctx.ts"; import { Resolver } from "./resolve/resolver.ts"; import { Checker } from "./check/checker.ts"; diff --git a/compiler/parse/lexer.ts b/compiler/parse/lexer.ts index 3c7e390..019e8ca 100644 --- a/compiler/parse/lexer.ts +++ b/compiler/parse/lexer.ts @@ -1,5 +1,6 @@ -import { Ctx, File } from "../ctx.ts"; +import { Ctx } from "../ctx.ts"; import { Pos, Span } from "../diagnostics.ts"; +import { File } from "../ids.ts"; import { ControlFlow, range } from "../util.ts"; import { Token, TokenIter } from "./token.ts"; diff --git a/compiler/parse/token.ts b/compiler/parse/token.ts index f7a26a5..3efbf69 100644 --- a/compiler/parse/token.ts +++ b/compiler/parse/token.ts @@ -1,5 +1,5 @@ -import { IdentId } from "../ctx.ts"; import { Span } from "../diagnostics.ts"; +import { IdentId } from "../ids.ts"; export type Token = { type: string; diff --git a/compiler/resolve/cx.ts b/compiler/resolve/cx.ts index 5ed2834..1fb3c65 100644 --- a/compiler/resolve/cx.ts +++ b/compiler/resolve/cx.ts @@ -1,5 +1,5 @@ import * as ast from "../ast/mod.ts"; -import { IdentId, idKey, Key } from "../ctx.ts"; +import { IdentId, IdMap } from "../ids.ts"; import { Res } from "../util.ts"; export interface Syms { @@ -30,17 +30,17 @@ export type Redef = { }; export class SymsOneNsTab { - private defs = new Map, Resolve>(); + private defs = new IdMap(); public get(ident: ast.Ident): Resolve | undefined { - return this.defs.get(idKey(ident.id))!; + return this.defs.get(ident.id)!; } public def(ident: ast.Ident, kind: ResolveKind): Res { - if (this.defs.has(idKey(ident.id))) { - return Res.Err({ ident: this.defs.get(idKey(ident.id))!.ident }); + if (this.defs.has(ident.id)) { + return Res.Err({ ident: this.defs.get(ident.id)!.ident }); } - this.defs.set(idKey(ident.id), { ident, kind }); + this.defs.set(ident.id, { ident, kind }); return Res.Ok(undefined); } } @@ -127,4 +127,3 @@ export class LocalSyms implements Syms { return this.syms.defTy(ident, kind); } } - diff --git a/compiler/resolve/resolver.ts b/compiler/resolve/resolver.ts index 637fa3d..4437dd8 100644 --- a/compiler/resolve/resolver.ts +++ b/compiler/resolve/resolver.ts @@ -1,5 +1,6 @@ import * as ast from "../ast/mod.ts"; import { Ctx, File } from "../ctx.ts"; +import { AstId, IdMap } from "../ids.ts"; import { exhausted, todo } from "../util.ts"; import { FnSyms, @@ -12,10 +13,10 @@ import { export class Resols { public constructor( - private exprResols: Map, + private exprResols: IdMap, ) {} - public exprRes(id: number): Resolve { + public exprRes(id: AstId): Resolve { if (!this.exprResols.has(id)) { throw new Error(); } @@ -28,7 +29,7 @@ export class Resolver implements ast.Visitor { private rootSyms = new RootSyms(); private syms: Syms = this.rootSyms; - private exprResols = new Map(); + private exprResols = new IdMap(); public constructor( private ctx: Ctx,