A "high-level" language for the Gameboy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

71 lines
1.2 KiB

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 = LabelStmt | GotoStmt | AssignStmt
export type LabelStmt = AStmt<"label", {
name: string,
}>
export type GotoStmt = AStmt<"goto", {
name: string,
}>
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"