2022-03-08 17:03:14 +03:00
|
|
|
(* This file is part of the Catala compiler, a specification language for tax
|
|
|
|
and social benefits computation rules. Copyright (C) 2021 Inria, contributor:
|
|
|
|
Denis Merigoux <denis.merigoux@inria.fr>
|
2021-06-22 17:01:57 +03:00
|
|
|
|
2022-03-08 17:03:14 +03:00
|
|
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
|
|
use this file except in compliance with the License. You may obtain a copy of
|
|
|
|
the License at
|
2021-06-22 17:01:57 +03:00
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
2022-03-08 17:03:14 +03:00
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
License for the specific language governing permissions and limitations under
|
2021-06-22 17:01:57 +03:00
|
|
|
the License. *)
|
|
|
|
|
2022-11-21 12:46:17 +03:00
|
|
|
open Catala_utils
|
2022-08-12 23:42:39 +03:00
|
|
|
open Shared_ast
|
2021-06-22 17:01:57 +03:00
|
|
|
module D = Dcalc.Ast
|
|
|
|
module L = Lcalc.Ast
|
2023-09-01 11:43:46 +03:00
|
|
|
|
|
|
|
module FuncName =
|
|
|
|
Uid.Gen
|
|
|
|
(struct
|
|
|
|
let style = Ocolor_types.(Fg (C4 green))
|
|
|
|
end)
|
|
|
|
()
|
|
|
|
|
|
|
|
module VarName =
|
|
|
|
Uid.Gen
|
|
|
|
(struct
|
2024-02-22 14:14:25 +03:00
|
|
|
let style = Ocolor_types.Default_fg
|
2023-09-01 11:43:46 +03:00
|
|
|
end)
|
|
|
|
()
|
2021-06-22 17:01:57 +03:00
|
|
|
|
2024-01-15 19:19:17 +03:00
|
|
|
type operator = Shared_ast.lcalc Shared_ast.operator
|
2023-03-30 16:30:08 +03:00
|
|
|
|
2023-05-17 16:44:57 +03:00
|
|
|
type expr = naked_expr Mark.pos
|
2022-08-25 20:46:13 +03:00
|
|
|
|
2022-08-25 18:29:00 +03:00
|
|
|
and naked_expr =
|
2023-11-28 16:14:26 +03:00
|
|
|
| EVar of VarName.t
|
|
|
|
| EFunc of FuncName.t
|
2024-01-26 22:15:32 +03:00
|
|
|
| EStruct of { fields : expr StructField.Map.t; name : StructName.t }
|
2023-12-11 17:59:47 +03:00
|
|
|
| EStructFieldAccess of {
|
|
|
|
e1 : expr;
|
|
|
|
field : StructField.t;
|
|
|
|
name : StructName.t;
|
|
|
|
}
|
2023-11-28 16:14:26 +03:00
|
|
|
| ETuple of expr list
|
2024-08-09 13:24:34 +03:00
|
|
|
| ETupleAccess of { e1 : expr; index : int; typ : typ }
|
2023-12-12 20:21:20 +03:00
|
|
|
| EInj of {
|
|
|
|
e1 : expr;
|
|
|
|
cons : EnumConstructor.t;
|
|
|
|
name : EnumName.t;
|
|
|
|
expr_typ : typ;
|
|
|
|
}
|
2023-11-28 16:14:26 +03:00
|
|
|
| EArray of expr list
|
|
|
|
| ELit of lit
|
2024-08-20 16:39:11 +03:00
|
|
|
| EPosLit
|
2023-12-11 17:59:47 +03:00
|
|
|
| EApp of { f : expr; args : expr list }
|
2024-08-09 13:24:34 +03:00
|
|
|
| EAppOp of { op : operator Mark.pos; args : expr list; tys : typ list }
|
2024-02-22 14:14:25 +03:00
|
|
|
| EExternal of { modname : VarName.t Mark.pos; name : string Mark.pos }
|
2021-06-22 17:01:57 +03:00
|
|
|
|
|
|
|
type stmt =
|
2023-12-11 17:59:47 +03:00
|
|
|
| SInnerFuncDef of { name : VarName.t Mark.pos; func : func }
|
|
|
|
| SLocalDecl of { name : VarName.t Mark.pos; typ : typ }
|
2023-12-11 19:28:32 +03:00
|
|
|
| SLocalInit of { name : VarName.t Mark.pos; typ : typ; expr : expr }
|
2024-07-12 12:14:58 +03:00
|
|
|
| SLocalDef of { name : VarName.t Mark.pos; typ : typ; expr : expr }
|
2024-08-26 16:44:00 +03:00
|
|
|
| SFatalError of { pos_expr : expr; error : Runtime.error }
|
2024-09-25 20:32:38 +03:00
|
|
|
(** [pos_expr] here is the position reified into an expression *)
|
2023-12-11 17:59:47 +03:00
|
|
|
| SIfThenElse of { if_expr : expr; then_block : block; else_block : block }
|
|
|
|
| SSwitch of {
|
2024-08-08 16:06:03 +03:00
|
|
|
switch_var : VarName.t;
|
|
|
|
switch_var_typ : typ;
|
2023-12-11 17:59:47 +03:00
|
|
|
enum_name : EnumName.t;
|
|
|
|
switch_cases : switch_case list;
|
|
|
|
}
|
2024-07-31 19:04:53 +03:00
|
|
|
| SReturn of expr
|
2024-08-26 16:44:00 +03:00
|
|
|
| SAssert of { pos_expr : expr; expr : expr }
|
2024-09-25 20:32:38 +03:00
|
|
|
(** [pos_expr] here is the position reified into an expression *)
|
2023-12-07 18:58:22 +03:00
|
|
|
| SSpecialOp of special_operator
|
2021-06-22 17:01:57 +03:00
|
|
|
|
2024-08-09 13:24:34 +03:00
|
|
|
and special_operator = |
|
2023-05-17 16:44:57 +03:00
|
|
|
and block = stmt Mark.pos list
|
2023-12-12 18:25:02 +03:00
|
|
|
|
|
|
|
and switch_case = {
|
|
|
|
case_block : block;
|
|
|
|
payload_var_name : VarName.t;
|
|
|
|
payload_var_typ : typ;
|
|
|
|
}
|
2023-12-07 18:38:29 +03:00
|
|
|
|
|
|
|
and func = {
|
|
|
|
func_params : (VarName.t Mark.pos * typ) list;
|
|
|
|
func_body : block;
|
|
|
|
func_return_typ : typ;
|
|
|
|
}
|
2021-06-22 17:01:57 +03:00
|
|
|
|
2022-02-14 19:01:34 +03:00
|
|
|
type scope_body = {
|
2022-08-12 23:42:39 +03:00
|
|
|
scope_body_name : ScopeName.t;
|
2023-02-10 20:56:40 +03:00
|
|
|
scope_body_var : FuncName.t;
|
2022-02-14 19:01:34 +03:00
|
|
|
scope_body_func : func;
|
2024-09-23 17:40:38 +03:00
|
|
|
scope_body_visibility : visibility;
|
2022-02-14 19:01:34 +03:00
|
|
|
}
|
|
|
|
|
2023-02-13 17:00:23 +03:00
|
|
|
type code_item =
|
2024-09-23 17:40:38 +03:00
|
|
|
| SVar of { var : VarName.t; expr : expr; typ : typ; visibility : visibility }
|
|
|
|
| SFunc of { var : FuncName.t; func : func; visibility : visibility }
|
2023-02-13 17:00:23 +03:00
|
|
|
| SScope of scope_body
|
2023-01-23 14:19:36 +03:00
|
|
|
|
2024-02-22 14:14:25 +03:00
|
|
|
type ctx = { decl_ctx : decl_ctx; modules : VarName.t ModuleName.Map.t }
|
|
|
|
|
|
|
|
type program = {
|
|
|
|
ctx : ctx;
|
|
|
|
code_items : code_item list;
|
2024-05-27 12:26:14 +03:00
|
|
|
module_name : (ModuleName.t * module_intf_id) option;
|
2024-02-22 14:14:25 +03:00
|
|
|
}
|