export type Program = Array<Decl | Stmt>
|
|
|
|
// Declarations
|
|
export type Decl = VarDecl
|
|
|
|
export type VarDecl = ADecl<"var", {
|
|
type: Type,
|
|
}>
|
|
|
|
type ADecl<Ty, Args> = {
|
|
type: "decl",
|
|
decl_type: Ty,
|
|
attrs: Array<Attr>,
|
|
name: string,
|
|
args: Args,
|
|
}
|
|
|
|
// Statements
|
|
export type Stmt = AssignStmt
|
|
|
|
export type AssignStmt = AStmt<"assign", {
|
|
name: string,
|
|
expr: Expr,
|
|
}>
|
|
|
|
type AStmt<Ty, Args> = {
|
|
type: "stmt",
|
|
stmt_type: Ty,
|
|
args: Args,
|
|
}
|
|
|
|
// Expressions
|
|
export type Expr = BinaryExpr | UnaryExpr | BasicExpr
|
|
|
|
type BinaryExpr = {
|
|
type: "binary",
|
|
op: BinaryOp,
|
|
left: Expr,
|
|
right: Expr,
|
|
}
|
|
|
|
type UnaryExpr = {
|
|
type: "unary",
|
|
op: UnaryOp,
|
|
arg: Expr,
|
|
}
|
|
|
|
type BasicExpr = number | string
|
|
|
|
type UnaryOp = "arith_negate" | "bit_negate"
|
|
type BinaryOp = "add" | "subtract" | "shift_left" | "shift_right" | "bit_and"
|
|
| "bit_xor" | "bit_or"
|
|
|
|
// Attributes
|
|
export type Attr = {
|
|
name: string,
|
|
args: Array<string | number>,
|
|
}
|
|
|
|
// Types
|
|
export type Type = PrimitiveType
|
|
|
|
export type PrimitiveType = "s8" | "u8" | "u16"
|