catala/compiler/lcalc/ast.mli

143 lines
4.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) 2020 Inria, contributor:
Denis Merigoux <denis.merigoux@inria.fr>
2021-02-12 19:20: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-02-12 19:20:14 +03:00
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
2021-02-12 19:20:14 +03:00
the License. *)
open Utils
(** Abstract syntax tree for the lambda calculus *)
(** {1 Abstract syntax tree} *)
(** The expressions use the {{:https://lepigre.fr/ocaml-bindlib/} Bindlib}
library, based on higher-order abstract syntax*)
2021-02-12 19:20:14 +03:00
type lit =
2021-02-12 19:20:14 +03:00
| LBool of bool
| LInt of Runtime.integer
| LRat of Runtime.decimal
| LMoney of Runtime.money
| LUnit
| LDate of Runtime.date
| LDuration of Runtime.duration
2021-02-12 19:20:14 +03:00
2022-02-18 17:47:54 +03:00
type except = ConflictError | EmptyError | NoValueProvided | Crash
2021-02-12 19:20:14 +03:00
type expr =
2021-02-12 19:20:14 +03:00
| EVar of expr Bindlib.var Pos.marked
| ETuple of expr Pos.marked list * Dcalc.Ast.StructName.t option
(** The [MarkedString.info] is the former struct field name*)
2021-02-12 20:16:06 +03:00
| ETupleAccess of
expr Pos.marked
* int
* Dcalc.Ast.StructName.t option
* Dcalc.Ast.typ Pos.marked list
2021-02-12 19:20:14 +03:00
(** The [MarkedString.info] is the former struct field name *)
| EInj of
expr Pos.marked
* int
* Dcalc.Ast.EnumName.t
* Dcalc.Ast.typ Pos.marked list
2021-02-12 19:20:14 +03:00
(** The [MarkedString.info] is the former enum case name *)
| EMatch of expr Pos.marked * expr Pos.marked list * Dcalc.Ast.EnumName.t
(** The [MarkedString.info] is the former enum case name *)
| EArray of expr Pos.marked list
2022-02-04 14:28:03 +03:00
| ELit of lit
| EAbs of
(expr, expr Pos.marked) Bindlib.mbinder Pos.marked
* Dcalc.Ast.typ Pos.marked list
2021-02-12 19:20:14 +03:00
| EApp of expr Pos.marked * expr Pos.marked list
| EAssert of expr Pos.marked
| EOp of Dcalc.Ast.operator
| EIfThenElse of expr Pos.marked * expr Pos.marked * expr Pos.marked
| ERaise of except
2021-02-12 19:20:14 +03:00
| ECatch of expr Pos.marked * except * expr Pos.marked
2021-11-02 20:09:59 +03:00
2021-02-12 19:20:14 +03:00
(** {1 Variable helpers} *)
module Var : sig
type t = expr Bindlib.var
2021-02-12 20:16:06 +03:00
2021-02-12 19:20:14 +03:00
val make : string Pos.marked -> t
val compare : t -> t -> int
end
module VarMap : Map.S with type key = Var.t
module VarSet : Set.S with type elt = Var.t
2021-02-12 19:20:14 +03:00
type vars = expr Bindlib.mvar
2021-02-12 19:20:14 +03:00
val make_var : Var.t Pos.marked -> expr Pos.marked Bindlib.box
val make_abs :
vars ->
2021-02-12 19:20:14 +03:00
expr Pos.marked Bindlib.box ->
Pos.t ->
Dcalc.Ast.typ Pos.marked list ->
Pos.t ->
expr Pos.marked Bindlib.box
val make_app :
2021-02-12 19:20:14 +03:00
expr Pos.marked Bindlib.box ->
expr Pos.marked Bindlib.box list ->
Pos.t ->
expr Pos.marked Bindlib.box
val make_let_in :
Var.t ->
2021-02-12 19:20:14 +03:00
Dcalc.Ast.typ Pos.marked ->
expr Pos.marked Bindlib.box ->
expr Pos.marked Bindlib.box ->
expr Pos.marked Bindlib.box
2021-11-30 18:27:47 +03:00
val option_enum : Dcalc.Ast.EnumName.t
val none_constr : Dcalc.Ast.EnumConstructor.t
val some_constr : Dcalc.Ast.EnumConstructor.t
val option_enum_config :
(Dcalc.Ast.EnumConstructor.t * Dcalc.Ast.typ Pos.marked) list
2021-11-30 18:27:47 +03:00
val make_none : Pos.t -> expr Pos.marked Bindlib.box
val make_some : expr Pos.marked Bindlib.box -> expr Pos.marked Bindlib.box
2022-02-04 14:33:26 +03:00
val make_matchopt_with_abs_arms :
expr Pos.marked Bindlib.box ->
expr Pos.marked Bindlib.box ->
expr Pos.marked Bindlib.box ->
expr Pos.marked Bindlib.box
val make_matchopt :
Pos.t ->
Var.t ->
Dcalc.Ast.typ Pos.marked ->
expr Pos.marked Bindlib.box ->
expr Pos.marked Bindlib.box ->
expr Pos.marked Bindlib.box ->
expr Pos.marked Bindlib.box
(** [e' = make_matchopt'' pos v e e_none e_some] Builds the term corresponding
to [match e with | None -> fun () -> e_none |Some -> fun v -> e_some]. *)
2021-06-23 18:47:34 +03:00
val handle_default : Var.t
2021-12-07 18:03:15 +03:00
val handle_default_opt : Var.t
2021-02-12 19:20:14 +03:00
type binder = (expr, expr Pos.marked) Bindlib.binder
2022-02-14 19:01:34 +03:00
type scope_body = {
scope_body_name : Dcalc.Ast.ScopeName.t;
scope_body_var : Var.t;
scope_body_expr : expr Pos.marked;
}
type program = { decl_ctx : Dcalc.Ast.decl_ctx; scopes : scope_body list }