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-02-10 20:56:40 +03:00
|
|
|
module FuncName = Uid.Gen ()
|
|
|
|
module VarName = Uid.Gen ()
|
2021-06-22 17:01:57 +03:00
|
|
|
|
2023-02-10 20:56:40 +03:00
|
|
|
let dead_value = VarName.fresh ("dead_value", Pos.no_pos)
|
|
|
|
let handle_default = FuncName.fresh ("handle_default", Pos.no_pos)
|
|
|
|
let handle_default_opt = FuncName.fresh ("handle_default_opt", Pos.no_pos)
|
2022-07-25 12:00:18 +03:00
|
|
|
|
2022-08-25 18:29:00 +03:00
|
|
|
type expr = naked_expr Marked.pos
|
2022-08-25 20:46:13 +03:00
|
|
|
|
2022-08-25 18:29:00 +03:00
|
|
|
and naked_expr =
|
2023-02-10 20:56:40 +03:00
|
|
|
| EVar : VarName.t -> naked_expr
|
|
|
|
| EFunc : FuncName.t -> naked_expr
|
Add overloaded operators for the common operations
This uses the same disambiguation mechanism put in place for
structures, calling the typer on individual rules on the desugared AST
to propagate types, in order to resolve ambiguous operators like `+`
to their strongly typed counterparts (`+!`, `+.`, `+$`, `+@`, `+$`) in
the translation to scopelang.
The patch includes some normalisation of the definition of all the
operators, and classifies them based on their typing policy instead of
their arity. It also adds a little more flexibility:
- a couple new operators, like `-` on date and duration
- optional type annotation on some aggregation constructions
The `Shared_ast` lib is also lightly restructured, with the `Expr`
module split into `Type`, `Operator` and `Expr`.
2022-11-29 11:47:53 +03:00
|
|
|
| EStruct : expr list * StructName.t -> naked_expr
|
|
|
|
| EStructFieldAccess : expr * StructField.t * StructName.t -> naked_expr
|
|
|
|
| EInj : expr * EnumConstructor.t * EnumName.t -> naked_expr
|
|
|
|
| EArray : expr list -> naked_expr
|
|
|
|
| ELit : L.lit -> naked_expr
|
|
|
|
| EApp : expr * expr list -> naked_expr
|
|
|
|
| EOp : (lcalc, _) operator -> naked_expr
|
2021-06-22 17:01:57 +03:00
|
|
|
|
|
|
|
type stmt =
|
2023-02-10 20:56:40 +03:00
|
|
|
| SInnerFuncDef of VarName.t Marked.pos * func
|
|
|
|
| SLocalDecl of VarName.t Marked.pos * typ
|
|
|
|
| SLocalDef of VarName.t Marked.pos * expr
|
2022-08-12 23:42:39 +03:00
|
|
|
| STryExcept of block * except * block
|
|
|
|
| SRaise of except
|
2022-08-25 18:29:00 +03:00
|
|
|
| SIfThenElse of expr * block * block
|
2021-06-24 15:52:51 +03:00
|
|
|
| SSwitch of
|
2022-08-25 18:29:00 +03:00
|
|
|
expr
|
2022-08-12 23:42:39 +03:00
|
|
|
* EnumName.t
|
2021-06-24 15:52:51 +03:00
|
|
|
* (block (* Statements corresponding to arm closure body*)
|
2023-02-10 20:56:40 +03:00
|
|
|
* (* Variable instantiated with enum payload *) VarName.t)
|
2021-06-24 15:52:51 +03:00
|
|
|
list (** Each block corresponds to one case of the enum *)
|
2022-08-25 17:35:08 +03:00
|
|
|
| SReturn of naked_expr
|
|
|
|
| SAssert of naked_expr
|
2021-06-22 17:01:57 +03:00
|
|
|
|
2022-05-30 12:20:48 +03:00
|
|
|
and block = stmt Marked.pos list
|
2021-06-22 17:01:57 +03:00
|
|
|
|
2022-03-08 17:03:14 +03:00
|
|
|
and func = {
|
2023-02-10 20:56:40 +03:00
|
|
|
func_params : (VarName.t Marked.pos * typ) list;
|
2022-03-08 17:03:14 +03:00
|
|
|
func_body : block;
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2023-02-10 20:56:40 +03:00
|
|
|
type global =
|
|
|
|
| GlobalVar of { var : VarName.t; expr : expr }
|
|
|
|
| GlobalFunc of { var : FuncName.t; func : func }
|
2023-01-23 14:19:36 +03:00
|
|
|
|
|
|
|
type program = {
|
|
|
|
decl_ctx : decl_ctx;
|
2023-02-10 20:56:40 +03:00
|
|
|
globals : global list;
|
2023-01-23 14:19:36 +03:00
|
|
|
scopes : scope_body list;
|
|
|
|
}
|