add some checker
This commit is contained in:
parent
b2b1533ee6
commit
a431185747
@ -13,6 +13,7 @@ export type CheckedExpr =
|
||||
} | {
|
||||
exprType: "int";
|
||||
value: number;
|
||||
valueType: CheckedType;
|
||||
} | {
|
||||
exprType: "if";
|
||||
condition: CheckedExpr;
|
||||
@ -88,6 +89,8 @@ export type CheckedType =
|
||||
typeType: "unit";
|
||||
} | {
|
||||
typeType: "u16";
|
||||
} | {
|
||||
typeType: "i16";
|
||||
} | {
|
||||
typeType: "pointer";
|
||||
subject: CheckedType;
|
||||
|
38
checker.ts
38
checker.ts
@ -1,6 +1,6 @@
|
||||
import { CheckedExpr, CheckedType } from "./checked.ts";
|
||||
import { ParsedExpr } from "./parsed.ts";
|
||||
import { CompileError } from "./token.ts";
|
||||
import { CompileError, Position } from "./token.ts";
|
||||
|
||||
export type SymbolValue = {
|
||||
id: number;
|
||||
@ -51,5 +51,39 @@ export class Checker {
|
||||
|
||||
private searchTopLevelFn(statement: ParsedExpr & { exprType: "fn" }) {
|
||||
}
|
||||
}
|
||||
|
||||
private checkExpr(expr: ParsedExpr): CheckedExpr {
|
||||
switch (expr.exprType) {
|
||||
case "error":
|
||||
return this.errorExpr(expr.message, expr.pos);
|
||||
case "unit":
|
||||
return { pos: expr.pos, exprType: "unit" };
|
||||
case "id":
|
||||
throw new Error("not implemented");
|
||||
case "int":
|
||||
case "if":
|
||||
case "block":
|
||||
case "call":
|
||||
case "index":
|
||||
case "increment":
|
||||
case "decrement":
|
||||
case "unary":
|
||||
case "binary":
|
||||
case "assign":
|
||||
default:
|
||||
return this.errorExpr(
|
||||
`expected expression, got '${expr.exprType}' statement`,
|
||||
expr.pos,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private errorExpr(message: string, pos: Position): CheckedExpr {
|
||||
this.errors.push({ message, pos });
|
||||
return {
|
||||
pos,
|
||||
exprType: "error",
|
||||
message,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user