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;
|
2023-05-04 00:06:09 +01:00
|
|
|
valueType: CheckedType;
|
2023-04-27 01:32:06 +01:00
|
|
|
}
|
|
|
|
& ({ 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[];
|
2023-05-01 12:36:06 +01:00
|
|
|
value: CheckedExpr | null;
|
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;
|
|
|
|
});
|