2021-02-12 19:20:14 +03:00
|
|
|
(* 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>
|
|
|
|
|
|
|
|
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. *)
|
|
|
|
|
|
|
|
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-11 20:48:59 +03:00
|
|
|
type lit =
|
2021-02-12 19:20:14 +03:00
|
|
|
| LBool of bool
|
2021-03-05 21:16:56 +03:00
|
|
|
| LInt of Runtime.integer
|
|
|
|
| LRat of Runtime.decimal
|
|
|
|
| LMoney of Runtime.money
|
2021-02-11 20:48:59 +03:00
|
|
|
| LUnit
|
2021-03-05 21:16:56 +03:00
|
|
|
| LDate of Runtime.date
|
|
|
|
| LDuration of Runtime.duration
|
2021-02-12 19:20:14 +03:00
|
|
|
|
2021-04-03 15:38:38 +03:00
|
|
|
type except = ConflictError | EmptyError | NoValueProvided | Crash
|
2021-02-12 19:20:14 +03:00
|
|
|
|
2021-02-11 20:48:59 +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
|
|
|
|
(** 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
|
2021-02-11 20:48:59 +03:00
|
|
|
| ELit of lit
|
2021-04-03 12:49:13 +03:00
|
|
|
| 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
|
2021-02-11 20:48:59 +03:00
|
|
|
| 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
|
2021-02-12 20:16:06 +03:00
|
|
|
|
2021-02-12 19:20:14 +03:00
|
|
|
val compare : t -> t -> int
|
|
|
|
end
|
|
|
|
|
|
|
|
module VarMap : Map.S with type key = Var.t
|
|
|
|
|
2021-02-11 20:48:59 +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
|
|
|
|
|
2021-02-11 20:48:59 +03:00
|
|
|
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
|
|
|
|
|
2021-02-11 20:48:59 +03:00
|
|
|
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
|
|
|
|
|
2021-02-11 20:48:59 +03:00
|
|
|
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-24 17:22:29 +03:00
|
|
|
val make_letopt_in :
|
2021-11-04 18:00:27 +03:00
|
|
|
Var.t ->
|
|
|
|
Dcalc.Ast.typ Pos.marked ->
|
2021-11-04 19:57:41 +03:00
|
|
|
expr Pos.marked Bindlib.box ->
|
|
|
|
expr Pos.marked Bindlib.box ->
|
|
|
|
expr Pos.marked Bindlib.box
|
2021-11-04 18:00:27 +03:00
|
|
|
|
2021-11-30 18:27:47 +03:00
|
|
|
val option_enum : Dcalc.Ast.EnumName.t
|
2021-11-26 19:10:31 +03:00
|
|
|
|
2021-11-30 18:27:47 +03:00
|
|
|
val none_constr : Dcalc.Ast.EnumConstructor.t
|
2021-11-26 19:10:31 +03:00
|
|
|
|
2021-11-30 18:27:47 +03:00
|
|
|
val some_constr : Dcalc.Ast.EnumConstructor.t
|
2021-11-25 19:24:18 +03:00
|
|
|
|
2021-11-30 18:27:47 +03:00
|
|
|
val option_enum_config : (Dcalc.Ast.EnumConstructor.t * Dcalc.Ast.typ Pos.marked) list
|
|
|
|
|
|
|
|
val make_none : Pos.t -> expr Pos.marked Bindlib.box
|
|
|
|
|
|
|
|
val make_some : expr Pos.marked Bindlib.box -> expr Pos.marked Bindlib.box
|
2021-11-25 19:24:18 +03:00
|
|
|
|
2021-11-30 18:27:47 +03:00
|
|
|
val make_some' : expr Pos.marked -> expr
|
2021-11-29 19:53:07 +03:00
|
|
|
|
2021-11-30 18:27:47 +03:00
|
|
|
val make_matchopt :
|
2021-11-25 19:24:18 +03:00
|
|
|
expr Pos.marked Bindlib.box ->
|
|
|
|
expr Pos.marked Bindlib.box ->
|
|
|
|
expr Pos.marked Bindlib.box ->
|
|
|
|
expr Pos.marked Bindlib.box
|
|
|
|
|
2021-11-30 20:05:30 +03:00
|
|
|
val make_bindopt :
|
|
|
|
Pos.t ->
|
|
|
|
Dcalc.Ast.typ Pos.marked ->
|
|
|
|
expr Pos.marked Bindlib.box ->
|
|
|
|
(expr Bindlib.var -> expr Pos.marked Bindlib.box) ->
|
|
|
|
expr Pos.marked Bindlib.box
|
|
|
|
|
2021-06-23 18:47:34 +03:00
|
|
|
val handle_default : Var.t
|
|
|
|
|
2021-02-12 19:20:14 +03:00
|
|
|
type binder = (expr, expr Pos.marked) Bindlib.binder
|
|
|
|
|
2021-02-12 20:16:06 +03:00
|
|
|
type program = { decl_ctx : Dcalc.Ast.decl_ctx; scopes : (Var.t * expr Pos.marked) list }
|