diff --git a/checked.ts b/checked.ts index 6904c7c..7d997d1 100644 --- a/checked.ts +++ b/checked.ts @@ -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; diff --git a/checker.ts b/checker.ts index 8c1c402..006e755 100644 --- a/checker.ts +++ b/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, + }; + } +}