e0/lib/ast.ml
2022-03-08 03:20:19 -06:00

61 lines
875 B
OCaml

type op
= OpAdd
| OpSub
| OpMul
| OpDiv
[@@deriving show]
type lit
= LitInt of int
| LitNegInt of int
| LitFloat of float
[@@deriving show]
type ty
= TySizedInt
| TyGenericInt
| TyFunc of ty list * ty
| TyPointer of ty
| TyStruct of (string * ty) list
[@@deriving show]
type expr
= ExprUnit
| ExprLit of lit
| ExprBin of expr * op * expr
| ExprAnnot of expr * ty
[@@deriving show]
type pat
= PatName of string
[@@deriving show]
type stmt
= StmtLet of pat * expr
| StmtReturn of expr
[@@deriving show]
type block =
{ stmts : stmt list
; ret : expr
}
[@@deriving show]
type func =
{ name : string
; body : block
}
[@@deriving show]
type extern_func =
{ name : string
}
[@@deriving show]
type decl
= DeclFunc of func
| DeclExternFunc of extern_func
[@@deriving show]
type program = decl list
[@@deriving show]