2019-03-11 06:26:21 +04:00
|
|
|
[@@@warning "-30"]
|
|
|
|
|
2019-03-13 19:55:41 +04:00
|
|
|
module SMap : Map.S with type key = string
|
2019-03-11 06:26:21 +04:00
|
|
|
|
2019-03-14 21:31:59 +04:00
|
|
|
module I = AST2.O
|
|
|
|
|
2019-03-13 19:55:41 +04:00
|
|
|
module O : sig
|
2019-03-11 06:26:21 +04:00
|
|
|
type asttodo = [`TODO] (* occurrences of asttodo will point to some part of the original parser AST *)
|
|
|
|
|
2019-03-14 14:19:15 +04:00
|
|
|
type name_and_region = {name: string; orig: Region.t}
|
|
|
|
type type_name = name_and_region
|
|
|
|
type var_name = name_and_region
|
|
|
|
type field_name = name_and_region
|
2019-03-14 02:42:16 +04:00
|
|
|
|
2019-03-11 06:26:21 +04:00
|
|
|
type pattern =
|
|
|
|
PVar of var_name
|
|
|
|
| PWild
|
|
|
|
| PInt of Z.t
|
|
|
|
| PBytes of MBytes.t
|
|
|
|
| PString of string
|
|
|
|
| PUnit
|
|
|
|
| PFalse
|
|
|
|
| PTrue
|
|
|
|
| PNone
|
|
|
|
| PSome of pattern
|
|
|
|
| PCons of pattern * pattern
|
|
|
|
| PNull
|
2019-03-14 19:46:18 +04:00
|
|
|
| PRecord of (field_name * pattern) list
|
2019-03-11 06:26:21 +04:00
|
|
|
|
|
|
|
type type_constructor =
|
2019-03-14 14:50:18 +04:00
|
|
|
Option
|
2019-03-11 06:26:21 +04:00
|
|
|
| List
|
|
|
|
| Set
|
|
|
|
| Map
|
|
|
|
|
|
|
|
type type_expr_case =
|
2019-03-14 14:50:18 +04:00
|
|
|
Sum of (type_name * type_expr) list
|
2019-03-14 19:46:18 +04:00
|
|
|
| Record of (field_name * type_expr) list
|
2019-03-14 14:50:18 +04:00
|
|
|
| TypeApp of type_constructor * (type_expr list)
|
|
|
|
| Function of { arg: type_expr; ret: type_expr }
|
|
|
|
| Ref of type_expr
|
2019-03-11 06:26:21 +04:00
|
|
|
| String
|
|
|
|
| Int
|
|
|
|
| Unit
|
|
|
|
| Bool
|
|
|
|
|
2019-03-14 14:50:18 +04:00
|
|
|
and type_expr = { type_expr: type_expr_case; name: string option; orig: AST.type_expr }
|
2019-03-11 06:26:21 +04:00
|
|
|
|
|
|
|
type typed_var = { name:var_name; ty:type_expr; orig: asttodo }
|
|
|
|
|
|
|
|
type type_decl = { name:string; ty:type_expr; orig: asttodo }
|
|
|
|
|
|
|
|
type expr_case =
|
|
|
|
App of { operator: operator; arguments: expr list }
|
|
|
|
| Var of typed_var
|
|
|
|
| Constant of constant
|
2019-03-14 19:46:18 +04:00
|
|
|
| Record of (field_name * expr) list
|
2019-03-11 06:26:21 +04:00
|
|
|
| Lambda of lambda
|
|
|
|
|
|
|
|
and expr = { expr: expr_case; ty:type_expr; orig: asttodo }
|
|
|
|
|
|
|
|
and decl = { var: typed_var; value: expr; orig: asttodo }
|
|
|
|
|
|
|
|
and lambda = {
|
2019-03-14 15:30:51 +04:00
|
|
|
parameter: typed_var;
|
2019-03-11 06:26:21 +04:00
|
|
|
declarations: decl list;
|
|
|
|
instructions: instr list;
|
|
|
|
result: expr;
|
|
|
|
}
|
|
|
|
|
|
|
|
and operator_case =
|
2019-03-14 13:58:15 +04:00
|
|
|
Function of var_name
|
2019-03-14 21:19:51 +04:00
|
|
|
| Constructor of var_name
|
2019-03-14 19:46:18 +04:00
|
|
|
| UpdateField of field_name
|
|
|
|
| GetField of field_name
|
2019-03-11 06:26:21 +04:00
|
|
|
| Or | And | Lt | Leq | Gt | Geq | Equal | Neq | Cat | Cons | Add | Sub | Mult | Div | Mod
|
|
|
|
| Neg | Not
|
2019-03-13 19:55:41 +04:00
|
|
|
| Set
|
2019-03-11 06:26:21 +04:00
|
|
|
| MapLookup
|
|
|
|
|
|
|
|
and operator = { operator: operator_case; ty:type_expr; orig: asttodo }
|
|
|
|
|
|
|
|
and constant =
|
|
|
|
Unit
|
|
|
|
| Int of Z.t | String of string | Bytes of MBytes.t
|
|
|
|
| False | True
|
|
|
|
| Null
|
|
|
|
| EmptySet
|
|
|
|
| CNone
|
|
|
|
|
|
|
|
and instr =
|
|
|
|
Assignment of { name: var_name; value: expr; orig: asttodo }
|
|
|
|
| While of { condition: expr; body: instr list; orig: asttodo }
|
2019-03-14 13:58:15 +04:00
|
|
|
| ForCollection of { list: expr; var: var_name; body: instr list; orig: asttodo }
|
2019-03-11 06:26:21 +04:00
|
|
|
| Match of { expr: expr; cases: (pattern * instr list) list; orig: asttodo }
|
2019-03-14 13:58:15 +04:00
|
|
|
| ProcedureCall of { expr: expr; orig: asttodo } (* expr returns unit, drop the result. Similar to OCaml's ";". *)
|
2019-03-11 06:26:21 +04:00
|
|
|
| Fail of { expr: expr; orig: asttodo }
|
|
|
|
|
|
|
|
type ast = {
|
|
|
|
types : type_decl list;
|
|
|
|
storage_decl : typed_var;
|
|
|
|
declarations : decl list;
|
|
|
|
orig: AST.t
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2019-03-14 21:31:59 +04:00
|
|
|
val annotate : I.ast -> O.ast
|