From f9e14e50564ed8d56ddf7edf6e210e9ae2e57371 Mon Sep 17 00:00:00 2001 From: sfja Date: Tue, 4 Feb 2025 17:01:32 +0100 Subject: [PATCH] set deno workspace --- slige/compiler/ast/ast.ts | 3 +-- slige/compiler/ast/cx.ts | 3 +-- slige/compiler/ast/deno.jsonc | 4 ++++ slige/compiler/ast/to_string.ts | 3 +-- slige/compiler/ast/visitor.ts | 3 ++- slige/compiler/check/checker.ts | 21 +++++++++++++-------- slige/compiler/check/deno.jsonc | 4 ++++ slige/compiler/check/mod.ts | 1 + slige/compiler/{ => common}/ctx.ts | 2 +- slige/compiler/common/deno.jsonc | 4 ++++ slige/compiler/{ => common}/diagnostics.ts | 0 slige/compiler/{ => common}/ids.ts | 2 +- slige/compiler/common/mod.ts | 9 +++++++++ slige/compiler/{ => common}/util.ts | 2 +- slige/compiler/deno.jsonc | 11 ++++++++++- slige/compiler/main.ts | 2 +- slige/compiler/middle/ast_lower.ts | 12 +++++------- slige/compiler/middle/deno.jsonc | 4 ++++ slige/compiler/middle/mir.ts | 5 ++--- slige/compiler/parse/deno.jsonc | 4 ++++ slige/compiler/parse/lexer.ts | 4 +--- slige/compiler/parse/mod.ts | 0 slige/compiler/parse/parser.ts | 20 ++++++++------------ slige/compiler/parse/token.ts | 3 +-- slige/compiler/resolve/cx.ts | 5 ++--- slige/compiler/resolve/deno.jsonc | 4 ++++ slige/compiler/resolve/mod.ts | 2 ++ slige/compiler/resolve/resolver.ts | 16 +++++++++++----- slige/compiler/ty/deno.jsonc | 4 ++++ slige/compiler/ty/mod.ts | 2 ++ slige/compiler/ty/to_string.ts | 3 +-- slige/compiler/ty/ty.ts | 2 +- 32 files changed, 106 insertions(+), 58 deletions(-) create mode 100644 slige/compiler/ast/deno.jsonc create mode 100644 slige/compiler/check/deno.jsonc create mode 100644 slige/compiler/check/mod.ts rename slige/compiler/{ => common}/ctx.ts (98%) create mode 100644 slige/compiler/common/deno.jsonc rename slige/compiler/{ => common}/diagnostics.ts (100%) rename slige/compiler/{ => common}/ids.ts (98%) create mode 100644 slige/compiler/common/mod.ts rename slige/compiler/{ => common}/util.ts (95%) create mode 100644 slige/compiler/middle/deno.jsonc create mode 100644 slige/compiler/parse/deno.jsonc create mode 100644 slige/compiler/parse/mod.ts create mode 100644 slige/compiler/resolve/deno.jsonc create mode 100644 slige/compiler/resolve/mod.ts create mode 100644 slige/compiler/ty/deno.jsonc create mode 100644 slige/compiler/ty/mod.ts diff --git a/slige/compiler/ast/ast.ts b/slige/compiler/ast/ast.ts index c50faf3..ea61696 100644 --- a/slige/compiler/ast/ast.ts +++ b/slige/compiler/ast/ast.ts @@ -1,5 +1,4 @@ -import { AstId, File as CtxFile, IdentId } from "../ids.ts"; -import { Span } from "../diagnostics.ts"; +import { AstId, File as CtxFile, IdentId, Span } from "@slige/common"; export type File = { stmts: Stmt[]; diff --git a/slige/compiler/ast/cx.ts b/slige/compiler/ast/cx.ts index 903aea6..44535f5 100644 --- a/slige/compiler/ast/cx.ts +++ b/slige/compiler/ast/cx.ts @@ -1,5 +1,4 @@ -import { Span } from "../diagnostics.ts"; -import { AstId, Ids } from "../ids.ts"; +import { AstId, Ids, Span } from "@slige/common"; import { Expr, ExprKind, diff --git a/slige/compiler/ast/deno.jsonc b/slige/compiler/ast/deno.jsonc new file mode 100644 index 0000000..b5705a6 --- /dev/null +++ b/slige/compiler/ast/deno.jsonc @@ -0,0 +1,4 @@ +{ + "name": "@slige/ast", + "exports": "./mod.ts", +} diff --git a/slige/compiler/ast/to_string.ts b/slige/compiler/ast/to_string.ts index e7289cf..b674b17 100644 --- a/slige/compiler/ast/to_string.ts +++ b/slige/compiler/ast/to_string.ts @@ -1,5 +1,4 @@ -import { Ctx } from "../ctx.ts"; -import { exhausted, todo } from "../util.ts"; +import { Ctx, exhausted, todo } from "@slige/common"; import { Block, Item } from "./ast.ts"; export function itemToString(ctx: Ctx, item: Item): string { diff --git a/slige/compiler/ast/visitor.ts b/slige/compiler/ast/visitor.ts index c345eea..18d134c 100644 --- a/slige/compiler/ast/visitor.ts +++ b/slige/compiler/ast/visitor.ts @@ -1,4 +1,5 @@ -import { exhausted } from "../util.ts"; +import { exhausted } from "@slige/common"; + import { AnonStructTy, ArrayExpr, diff --git a/slige/compiler/check/checker.ts b/slige/compiler/check/checker.ts index 20d880c..6ca72b7 100644 --- a/slige/compiler/check/checker.ts +++ b/slige/compiler/check/checker.ts @@ -1,11 +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"; +import * as ast from "@slige/ast"; +import { + AstId, + Ctx, + exhausted, + File, + IdMap, + Res, + Span, + todo, +} from "@slige/common"; +import { Resols } from "@slige/resolve"; +import { Ty, tyToString } from "@slige/ty"; export class Checker { private itemTys = new IdMap(); diff --git a/slige/compiler/check/deno.jsonc b/slige/compiler/check/deno.jsonc new file mode 100644 index 0000000..0092463 --- /dev/null +++ b/slige/compiler/check/deno.jsonc @@ -0,0 +1,4 @@ +{ + "name": "@slige/check", + "exports": "./mod.ts", +} diff --git a/slige/compiler/check/mod.ts b/slige/compiler/check/mod.ts new file mode 100644 index 0000000..9ebb8a9 --- /dev/null +++ b/slige/compiler/check/mod.ts @@ -0,0 +1 @@ +export * from "./checker.ts"; diff --git a/slige/compiler/ctx.ts b/slige/compiler/common/ctx.ts similarity index 98% rename from slige/compiler/ctx.ts rename to slige/compiler/common/ctx.ts index e53e5b6..97e4511 100644 --- a/slige/compiler/ctx.ts +++ b/slige/compiler/common/ctx.ts @@ -1,4 +1,4 @@ -import * as ast from "./ast/mod.ts"; +import * as ast from "@slige/ast"; import { Pos, prettyPrintReport, diff --git a/slige/compiler/common/deno.jsonc b/slige/compiler/common/deno.jsonc new file mode 100644 index 0000000..f1a71ac --- /dev/null +++ b/slige/compiler/common/deno.jsonc @@ -0,0 +1,4 @@ +{ + "name": "@slige/common", + "exports": "./mod.ts", +} diff --git a/slige/compiler/diagnostics.ts b/slige/compiler/common/diagnostics.ts similarity index 100% rename from slige/compiler/diagnostics.ts rename to slige/compiler/common/diagnostics.ts diff --git a/slige/compiler/ids.ts b/slige/compiler/common/ids.ts similarity index 98% rename from slige/compiler/ids.ts rename to slige/compiler/common/ids.ts index ec4af8c..abcaade 100644 --- a/slige/compiler/ids.ts +++ b/slige/compiler/common/ids.ts @@ -31,7 +31,7 @@ export class Ids { export class IdMap implements Map { private map = new Map, V>(); - set(id: Id, val: V) { + set(id: Id, val: V): this { this.map.set(idRaw(id), val); return this; } diff --git a/slige/compiler/common/mod.ts b/slige/compiler/common/mod.ts new file mode 100644 index 0000000..f3fcfb8 --- /dev/null +++ b/slige/compiler/common/mod.ts @@ -0,0 +1,9 @@ +export * from "./ids.ts"; +export * from "./ctx.ts"; +export * from "./util.ts"; +export * from "./diagnostics.ts"; + +export * as ids from "./ids.ts"; +export * as ctx from "./ctx.ts"; +export * as util from "./util.ts"; +export * as diagnostics from "./diagnostics.ts"; diff --git a/slige/compiler/util.ts b/slige/compiler/common/util.ts similarity index 95% rename from slige/compiler/util.ts rename to slige/compiler/common/util.ts index 750eb36..a711395 100644 --- a/slige/compiler/util.ts +++ b/slige/compiler/common/util.ts @@ -42,7 +42,7 @@ export const ControlFlow = { Continue: (val: V): Continue => ({ break: false, val }), } as const; -export const range = (length: number) => (new Array(length).fill(0)); +export const range = (length: number): number[] => (new Array(length).fill(0)); export const strictEq = (a: T, b: T): boolean => a === b; diff --git a/slige/compiler/deno.jsonc b/slige/compiler/deno.jsonc index 3fecf5f..dede7e7 100644 --- a/slige/compiler/deno.jsonc +++ b/slige/compiler/deno.jsonc @@ -1,5 +1,14 @@ { + "workspace": ["./ast", "./check", "./middle", "./parse", "./resolve", "./ty", "./common"], + "lint": { + "rules": { + "exclude": [ + "verbatim-module-syntax", + "no-unused-vars" + ], + } + }, "fmt": { "indentWidth": 4 - } + }, } diff --git a/slige/compiler/main.ts b/slige/compiler/main.ts index 73e3e81..f03c2b7 100644 --- a/slige/compiler/main.ts +++ b/slige/compiler/main.ts @@ -1,7 +1,7 @@ import * as path from "jsr:@std/path"; import { Parser } from "./parse/parser.ts"; import * as ast from "./ast/mod.ts"; -import { Ctx, File } from "./ctx.ts"; +import { Ctx, File } from "@slige/common"; import { Resolver } from "./resolve/resolver.ts"; import { Checker } from "./check/checker.ts"; import { AstLowerer } from "./middle/ast_lower.ts"; diff --git a/slige/compiler/middle/ast_lower.ts b/slige/compiler/middle/ast_lower.ts index b6299a9..38824e9 100644 --- a/slige/compiler/middle/ast_lower.ts +++ b/slige/compiler/middle/ast_lower.ts @@ -1,10 +1,8 @@ -import * as ast from "../ast/mod.ts"; -import { Checker } from "../check/checker.ts"; -import { Ctx } from "../ctx.ts"; -import { IdMap, Ids } from "../ids.ts"; -import { LocalId as ReLocalId, Resols } from "../resolve/resolver.ts"; -import { Ty } from "../ty/ty.ts"; -import { exhausted, Res, todo } from "../util.ts"; +import * as ast from "@slige/ast"; +import { Checker } from "@slige/check"; +import { Ctx, exhausted, IdMap, Ids, Res, todo } from "@slige/common"; +import { LocalId as ReLocalId, Resols } from "@slige/resolve"; +import { Ty } from "@slige/ty"; import { BinaryType, Operand, StmtKind, TerKind } from "./mir.ts"; import { Block, BlockId, Fn, Local, LocalId, RVal, Stmt, Ter } from "./mir.ts"; diff --git a/slige/compiler/middle/deno.jsonc b/slige/compiler/middle/deno.jsonc new file mode 100644 index 0000000..851ec68 --- /dev/null +++ b/slige/compiler/middle/deno.jsonc @@ -0,0 +1,4 @@ +{ + "name": "@slige/middle", + "exports": "./mod.ts", +} diff --git a/slige/compiler/middle/mir.ts b/slige/compiler/middle/mir.ts index b91747c..b42175a 100644 --- a/slige/compiler/middle/mir.ts +++ b/slige/compiler/middle/mir.ts @@ -1,6 +1,5 @@ -import { Span } from "../diagnostics.ts"; -import { IdBase, IdMap } from "../ids.ts"; -import { Ty } from "../ty/ty.ts"; +import { IdBase, IdMap } from "@slige/common"; +import { Ty } from "@slige/ty"; export type Fn = { label: string; diff --git a/slige/compiler/parse/deno.jsonc b/slige/compiler/parse/deno.jsonc new file mode 100644 index 0000000..b1587a3 --- /dev/null +++ b/slige/compiler/parse/deno.jsonc @@ -0,0 +1,4 @@ +{ + "name": "@slige/parse", + "exports": "./mod.ts", +} diff --git a/slige/compiler/parse/lexer.ts b/slige/compiler/parse/lexer.ts index 906f363..510f4a8 100644 --- a/slige/compiler/parse/lexer.ts +++ b/slige/compiler/parse/lexer.ts @@ -1,6 +1,4 @@ -import { Ctx, File } from "../ctx.ts"; -import { Pos, Span } from "../diagnostics.ts"; -import { ControlFlow, range } from "../util.ts"; +import { ControlFlow, Ctx, File, Pos, range, Span } from "@slige/common"; import { Token, TokenIter } from "./token.ts"; export class Lexer implements TokenIter { diff --git a/slige/compiler/parse/mod.ts b/slige/compiler/parse/mod.ts new file mode 100644 index 0000000..e69de29 diff --git a/slige/compiler/parse/parser.ts b/slige/compiler/parse/parser.ts index 6caa4ec..2e855d8 100644 --- a/slige/compiler/parse/parser.ts +++ b/slige/compiler/parse/parser.ts @@ -1,15 +1,11 @@ import { AnonFieldDef, - BinaryType, - ExprField, - PathSegment, - RefType, - UnaryType, -} from "../ast/ast.ts"; -import { AssignType, + BinaryType, Block, + Cx, Expr, + ExprField, ExprKind, File, GenericParam, @@ -19,16 +15,16 @@ import { Param, Pat, Path, + PathSegment, PatKind, + RefType, Stmt, StmtKind, Ty, TyKind, -} from "../ast/ast.ts"; -import { Cx } from "../ast/cx.ts"; -import { Ctx, File as CtxFile } from "../ctx.ts"; -import { Pos, Span } from "../diagnostics.ts"; -import { Res, todo } from "../util.ts"; + UnaryType, +} from "@slige/ast"; +import { Ctx, File as CtxFile, Pos, Res, Span, todo } from "@slige/common"; import { Lexer } from "./lexer.ts"; import { TokenIter } from "./token.ts"; import { SigFilter } from "./token.ts"; diff --git a/slige/compiler/parse/token.ts b/slige/compiler/parse/token.ts index cfc0667..cb9c853 100644 --- a/slige/compiler/parse/token.ts +++ b/slige/compiler/parse/token.ts @@ -1,5 +1,4 @@ -import { Span } from "../diagnostics.ts"; -import { IdentId } from "../ids.ts"; +import { IdentId, Span } from "@slige/common"; export type Token = { type: string; diff --git a/slige/compiler/resolve/cx.ts b/slige/compiler/resolve/cx.ts index f2bd84e..f3ad502 100644 --- a/slige/compiler/resolve/cx.ts +++ b/slige/compiler/resolve/cx.ts @@ -1,6 +1,5 @@ -import * as ast from "../ast/mod.ts"; -import { IdBase, IdentId, IdMap } from "../ids.ts"; -import { Res } from "../util.ts"; +import * as ast from "@slige/ast"; +import { IdBase, IdentId, IdMap, Res } from "@slige/common"; export interface Syms { getVal(ident: ast.Ident): Resolve; diff --git a/slige/compiler/resolve/deno.jsonc b/slige/compiler/resolve/deno.jsonc new file mode 100644 index 0000000..02c9766 --- /dev/null +++ b/slige/compiler/resolve/deno.jsonc @@ -0,0 +1,4 @@ +{ + "name": "@slige/resolve", + "exports": "./mod.ts", +} diff --git a/slige/compiler/resolve/mod.ts b/slige/compiler/resolve/mod.ts new file mode 100644 index 0000000..63dfe22 --- /dev/null +++ b/slige/compiler/resolve/mod.ts @@ -0,0 +1,2 @@ +export * from "./resolver.ts"; +export * from "./cx.ts"; diff --git a/slige/compiler/resolve/resolver.ts b/slige/compiler/resolve/resolver.ts index 22a0ddb..1e50ae4 100644 --- a/slige/compiler/resolve/resolver.ts +++ b/slige/compiler/resolve/resolver.ts @@ -1,7 +1,5 @@ -import * as ast from "../ast/mod.ts"; -import { Ctx, File } from "../ctx.ts"; -import { AstId, IdMap, Ids } from "../ids.ts"; -import { exhausted, todo } from "../util.ts"; +import * as ast from "@slige/ast"; +import { AstId, Ctx, exhausted, File, IdMap, Ids, todo } from "@slige/common"; import { FnSyms, LocalId, @@ -156,7 +154,7 @@ export class Resolver implements ast.Visitor { } visitPathPat(pat: ast.Pat, kind: ast.PathPat): ast.VisitRes { - todo(); + todo(pat, kind); } visitBlock(block: ast.Block): ast.VisitRes { @@ -166,6 +164,14 @@ export class Resolver implements ast.Visitor { return "stop"; } + visitPath(_path: ast.Path): ast.VisitRes { + throw new Error("should not be reached"); + } + + visitIdent(_ident: ast.Ident): ast.VisitRes { + throw new Error("should not be reached"); + } + private resolveInnerPath(path: ast.Path): Resolve { const res = path.segments.slice(1, path.segments.length) .reduce((innerRes, seg) => { diff --git a/slige/compiler/ty/deno.jsonc b/slige/compiler/ty/deno.jsonc new file mode 100644 index 0000000..72c6de0 --- /dev/null +++ b/slige/compiler/ty/deno.jsonc @@ -0,0 +1,4 @@ +{ + "name": "@slige/ty", + "exports": "./mod.ts", +} diff --git a/slige/compiler/ty/mod.ts b/slige/compiler/ty/mod.ts new file mode 100644 index 0000000..095a7b8 --- /dev/null +++ b/slige/compiler/ty/mod.ts @@ -0,0 +1,2 @@ +export * from "./ty.ts"; +export * from "./to_string.ts"; diff --git a/slige/compiler/ty/to_string.ts b/slige/compiler/ty/to_string.ts index 0f91c7f..941c8bd 100644 --- a/slige/compiler/ty/to_string.ts +++ b/slige/compiler/ty/to_string.ts @@ -1,5 +1,4 @@ -import { Ctx } from "../ctx.ts"; -import { exhausted } from "../util.ts"; +import { Ctx, exhausted } from "@slige/common"; import { Ty } from "./ty.ts"; export function tyToString(ctx: Ctx, ty: Ty): string { diff --git a/slige/compiler/ty/ty.ts b/slige/compiler/ty/ty.ts index c5c79a5..10fce19 100644 --- a/slige/compiler/ty/ty.ts +++ b/slige/compiler/ty/ty.ts @@ -1,4 +1,4 @@ -import * as ast from "../ast/mod.ts"; +import * as ast from "@slige/ast"; export type Ty = { kind: TyKind;