nandgame-compiler/checked.ts
2023-05-04 01:06:09 +02:00

104 lines
2.4 KiB
TypeScript

import { AssignType, BinaryType, UnaryType } from "./parsed.ts";
import { Position } from "./token.ts";
export type CheckedExpr =
& {
pos: Position;
valueType: CheckedType;
}
& ({ exprType: "error"; message: string } | {
exprType: "unit";
} | {
exprType: "id";
value: string;
} | {
exprType: "int";
value: number;
} | {
exprType: "if";
condition: CheckedExpr;
truthy: CheckedExpr;
falsy: CheckedExpr | null;
} | {
exprType: "block";
body: CheckedExpr[];
value: CheckedExpr | null;
} | {
exprType: "call";
subject: CheckedExpr;
args: CheckedExpr[];
} | {
exprType: "index";
subject: CheckedExpr;
value: CheckedExpr;
} | {
exprType: "increment" | "decrement";
subject: CheckedExpr;
} | {
exprType: "unary";
unaryType: UnaryType;
subject: CheckedExpr;
} | {
exprType: "binary";
binaryType: BinaryType;
left: CheckedExpr;
right: CheckedExpr;
} | {
exprType: "assign";
assignType: AssignType;
subject: CheckedExpr;
value: CheckedExpr;
} | {
exprType: "let";
param: CheckedParameter;
value: CheckedExpr;
} | {
exprType: "fn";
subject: string;
params: CheckedParameter[];
body: CheckedExpr;
} | {
exprType: "return";
value: CheckedExpr | null;
} | {
exprType: "loop";
body: CheckedExpr;
} | {
exprType: "while";
condition: CheckedExpr;
body: CheckedExpr;
} | {
exprType: "break";
} | {
exprType: "continue";
});
export type CheckedParameter =
& {
pos: Position;
}
& ({ paramType: "error"; message: string } | {
paramType: "value";
subject: string;
valueType: CheckedType | null;
mutable: boolean;
});
export type CheckedType =
& { pos: Position }
& ({ typeType: "error"; message: string } | {
typeType: "unit";
} | {
typeType: "u16";
} | {
typeType: "i16";
} | {
typeType: "pointer";
subject: CheckedType;
mutable: boolean;
} | {
typeType: "function";
params: CheckedParameter[];
returnType: CheckedType;
});