e0/lib/ast.ml

62 lines
875 B
OCaml
Raw Normal View History

2022-03-08 06:16:27 +00:00
type op
= OpAdd
| OpSub
| OpMul
| OpDiv
2022-03-08 08:52:20 +00:00
[@@deriving show]
2022-03-08 06:16:27 +00:00
type lit
2022-03-08 08:52:20 +00:00
= LitInt of int
| LitNegInt of int
2022-03-08 06:16:27 +00:00
| LitFloat of float
2022-03-08 08:52:20 +00:00
[@@deriving show]
type ty
= TySizedInt
| TyGenericInt
| TyFunc of ty list * ty
| TyPointer of ty
| TyStruct of (string * ty) list
[@@deriving show]
2022-03-08 06:16:27 +00:00
type expr
2022-03-08 08:52:20 +00:00
= ExprUnit
| ExprLit of lit
2022-03-08 06:16:27 +00:00
| ExprBin of expr * op * expr
2022-03-08 08:52:20 +00:00
| 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]
2022-03-08 06:16:27 +00:00
type func =
{ name : string
2022-03-08 08:52:20 +00:00
; body : block
2022-03-08 06:16:27 +00:00
}
2022-03-08 08:52:20 +00:00
[@@deriving show]
2022-03-08 06:16:27 +00:00
type extern_func =
{ name : string
}
[@@deriving show]
2022-03-08 06:16:27 +00:00
type decl
= DeclFunc of func
| DeclExternFunc of extern_func
2022-03-08 08:52:20 +00:00
[@@deriving show]
2022-03-08 06:16:27 +00:00
type program = decl list
2022-03-08 08:52:20 +00:00
[@@deriving show]