nandgame-compiler/checked.ts

105 lines
2.4 KiB
TypeScript
Raw Normal View History

2023-04-27 01:32:06 +01:00
import { AssignType, BinaryType, UnaryType } from "./parsed.ts";
import { Position } from "./token.ts";
export type CheckedExpr =
& {
pos: Position;
}
& ({ exprType: "error"; message: string } | {
exprType: "unit";
} | {
exprType: "id";
value: string;
} | {
exprType: "int";
value: number;
2023-04-27 13:48:08 +01:00
valueType: CheckedType;
2023-04-27 01:32:06 +01:00
} | {
exprType: "if";
condition: CheckedExpr;
truthy: CheckedExpr;
falsy: CheckedExpr | null;
} | {
exprType: "block";
body: CheckedExpr[];
2023-05-01 12:36:06 +01:00
value: CheckedExpr | null;
valueType: CheckedType;
2023-04-27 01:32:06 +01:00
} | {
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";
2023-04-27 13:48:08 +01:00
} | {
typeType: "i16";
2023-04-27 01:32:06 +01:00
} | {
typeType: "pointer";
subject: CheckedType;
mutable: boolean;
} | {
typeType: "function";
params: CheckedParameter[];
returnType: CheckedType;
});