add tree rewriter
All checks were successful
Check / Explore-Gitea-Actions (push) Successful in 10s

This commit is contained in:
sfja 2026-04-15 02:41:15 +02:00
parent 9012cfbd5f
commit db129a3c16
2 changed files with 40 additions and 3 deletions

View File

@ -136,7 +136,36 @@ class TypeChecker {
} }
} }
throw new Error("not implemented"); const expectedInner = expected.is("Any")
? expected
: expected.as("Array").kind.ty;
let res = this.resolve(
this.expr(k.values[0], expectedInner),
expected,
k.values[0].loc,
);
while (true) {
for (const val of k.values.slice(1)) {
res = this.resolve(
this.expr(val, expectedInner),
expected,
k.values[0].loc,
);
if (res.rewriteSubtree) {
break;
}
}
if (!res.rewriteSubtree) {
break;
}
for (const val of k.values) {
this.rewriteTree(val, res.ty);
}
}
return res.ty;
} }
case "IndexExpr": { case "IndexExpr": {
throw new Error("not implemented"); throw new Error("not implemented");
@ -187,6 +216,14 @@ class TypeChecker {
} }
throw new Error("not implemented"); throw new Error("not implemented");
} }
private rewriteTree(node: ast.Node, ty: Ty) {
const k = node.kind;
switch (k.tag) {
default:
throw new Error("not implemented");
}
}
} }
type TyRes = { type TyRes = {

View File

@ -69,8 +69,6 @@ export function tyPretty(ty: ty.Ty, colors = noColors): string {
return `<error>`; return `<error>`;
case "Void": case "Void":
return `${c.typeIdent}void`; return `${c.typeIdent}void`;
case "IntLiteral":
return `${c.typeIdent}{integer}`;
case "Int": case "Int":
return `${c.typeIdent}${ty.kind.intTy}`; return `${c.typeIdent}${ty.kind.intTy}`;
case "Bool": case "Bool":
@ -103,6 +101,8 @@ export function tyPretty(ty: ty.Ty, colors = noColors): string {
`${c.punctuation}, `, `${c.punctuation}, `,
) )
}${c.punctuation}) -> ${ty.kind.ty.kind.retTy.pretty(c)}`; }${c.punctuation}) -> ${ty.kind.ty.kind.retTy.pretty(c)}`;
case "AnyInt":
return `${c.typeIdent}{integer}`;
} }
return "<unhandled>"; return "<unhandled>";
} }