e0/lib/ast.ml
Michael Zhang 4ea1071ca1
a
2022-03-23 01:12:37 -05:00

29 lines
842 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 =
| TyUnit
| 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]