catala/compiler/scalc/ast.ml

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

115 lines
3.2 KiB
OCaml
Raw Normal View History

(* 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>
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
http://www.apache.org/licenses/LICENSE-2.0
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
the License. *)
2022-11-21 12:46:17 +03:00
open Catala_utils
open Shared_ast
module D = Dcalc.Ast
module L = Lcalc.Ast
module FuncName =
Uid.Gen
(struct
let style = Ocolor_types.(Fg (C4 green))
end)
()
module VarName =
Uid.Gen
(struct
let style = Ocolor_types.(Fg (C4 hi_green))
end)
()
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
type operator =
< overloaded : no ; monomorphic : yes ; polymorphic : yes ; resolved : yes >
Shared_ast.operator
type expr = naked_expr Mark.pos
and naked_expr =
2023-11-28 16:14:26 +03:00
| EVar of VarName.t
| EFunc of FuncName.t
2023-12-11 17:59:47 +03:00
| EStruct of { fields : expr list; name : StructName.t }
| EStructFieldAccess of {
e1 : expr;
field : StructField.t;
name : StructName.t;
}
2023-11-28 16:14:26 +03:00
| ETuple of expr list
2023-12-11 17:59:47 +03:00
| ETupleAccess of { e1 : expr; index : int }
| EInj of { e1 : expr; cons : EnumConstructor.t; name : EnumName.t }
2023-11-28 16:14:26 +03:00
| EArray of expr list
| ELit of lit
2023-12-11 17:59:47 +03:00
| EApp of { f : expr; args : expr list }
2023-11-28 16:14:26 +03:00
| EOp of operator
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 }
2023-12-11 17:59:47 +03:00
| SLocalDef of { name : VarName.t Mark.pos; expr : expr }
| STryExcept of { try_block : block; except : except; with_block : block }
| SRaise of except
2023-12-11 17:59:47 +03:00
| SIfThenElse of { if_expr : expr; then_block : block; else_block : block }
| SSwitch of {
switch_expr : expr;
2023-12-11 19:08:32 +03:00
switch_expr_typ : typ;
2023-12-11 17:59:47 +03:00
enum_name : EnumName.t;
switch_cases : switch_case list;
}
| SReturn of naked_expr
| SAssert of naked_expr
| SSpecialOp of special_operator
2023-12-12 18:08:40 +03:00
and special_operator =
| OHandleDefaultOpt of {
exceptions : expr list;
just : expr;
cons : block;
return_typ : typ;
}
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;
}
2022-02-14 19:01:34 +03:00
type scope_body = {
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;
}
type code_item =
2023-12-07 18:38:29 +03:00
| SVar of { var : VarName.t; expr : expr; typ : typ }
| SFunc of { var : FuncName.t; func : func }
| SScope of scope_body
type program = { decl_ctx : decl_ctx; code_items : code_item list }