mirror of
https://github.com/Noratrieb/riverdelta.git
synced 2026-01-14 16:35:03 +01:00
CHECK THE TYPES
This commit is contained in:
parent
35f1c92e36
commit
5c6ade6cbb
6 changed files with 670 additions and 18 deletions
|
|
@ -5,7 +5,9 @@ import {
|
|||
Identifier,
|
||||
Item,
|
||||
Resolution,
|
||||
Ty,
|
||||
Type,
|
||||
tyIsUnit,
|
||||
} from "./ast";
|
||||
|
||||
export function printAst(ast: Ast): string {
|
||||
|
|
@ -139,6 +141,33 @@ function printIdent(ident: Identifier): string {
|
|||
return `${ident.name}${res}`;
|
||||
}
|
||||
|
||||
export function printTy(ty: Ty): string {
|
||||
switch (ty.kind) {
|
||||
case "string": {
|
||||
return "String";
|
||||
}
|
||||
case "int": {
|
||||
return "Int";
|
||||
}
|
||||
case "bool": {
|
||||
return "Bool";
|
||||
}
|
||||
case "list": {
|
||||
return `[${printTy(ty.elem)}]`;
|
||||
}
|
||||
case "tuple": {
|
||||
return `(${ty.elems.map(printTy).join(", ")})`;
|
||||
}
|
||||
case "fn": {
|
||||
const ret = tyIsUnit(ty.returnTy) ? "" : `: ${printTy(ty.returnTy)}`;
|
||||
return `fn(${ty.params.map(printTy).join(", ")})${ret}`;
|
||||
}
|
||||
case "var": {
|
||||
return `?${ty.index}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function linebreak(indent: number): string {
|
||||
return `\n${ind(indent)}`;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue