package catala
Install
Dune Dependency
Authors
Maintainers
Sources
md5=b22e238d5d5c8452067109e9c7c0f427
sha512=ccc8c557c67c2f9d1bed4b957b2367f0f6afc0ef9b8b83237cf2a2912b3e8829b7e8af78ea7fe00b20ecf28b436ad04b591e5fff4f82fd08725d40a18c9924d0
doc/catala.dcalc/Dcalc/Ast/index.html
Module Dcalc.Ast
Source
Abstract syntax tree of the default calculus intermediate representation
Abstract syntax tree for the default calculus
Abstract syntax tree
type typ =
| TLit of typ_lit
| TTuple of typ Utils.Pos.marked list * StructName.t option
| TEnum of typ Utils.Pos.marked list * EnumName.t
| TArrow of typ Utils.Pos.marked * typ Utils.Pos.marked
| TArray of typ Utils.Pos.marked
| TAny
type lit =
| LBool of bool
| LEmptyError
| LInt of Runtime.integer
| LRat of Runtime.decimal
| LMoney of Runtime.money
| LUnit
| LDate of date
| LDuration of duration
type unop =
| Not
| Minus of op_kind
| Log of log_entry * Utils.Uid.MarkedString.info list
| Length
| IntToRat
| GetDay
| GetMonth
| GetYear
type expr =
| EVar of expr Bindlib.var Utils.Pos.marked
| ETuple of expr Utils.Pos.marked list * StructName.t option
(*The
*)MarkedString.info
is the former struct field name| ETupleAccess of expr Utils.Pos.marked * int * StructName.t option * typ Utils.Pos.marked list
(*The
*)MarkedString.info
is the former struct field name| EInj of expr Utils.Pos.marked * int * EnumName.t * typ Utils.Pos.marked list
(*The
*)MarkedString.info
is the former enum case name| EMatch of expr Utils.Pos.marked * expr Utils.Pos.marked list * EnumName.t
(*The
*)MarkedString.info
is the former enum case name| EArray of expr Utils.Pos.marked list
| ELit of lit
| EAbs of (expr, expr Utils.Pos.marked) Bindlib.mbinder Utils.Pos.marked * typ Utils.Pos.marked list
| EApp of expr Utils.Pos.marked * expr Utils.Pos.marked list
| EAssert of expr Utils.Pos.marked
| EOp of operator
| EDefault of expr Utils.Pos.marked list * expr Utils.Pos.marked * expr Utils.Pos.marked
| EIfThenElse of expr Utils.Pos.marked * expr Utils.Pos.marked * expr Utils.Pos.marked
| ErrorOnEmpty of expr Utils.Pos.marked
The expressions use the Bindlib library, based on higher-order abstract syntax
type scope_let_kind =
| DestructuringInputStruct
(*
*)let x = input.field
| ScopeVarDefinition
(*
*)let x = error_on_empty e
| SubScopeVarDefinition
(*
*)let s.x = fun _ -> e
orlet s.x = error_on_empty e
for input-only subscope variables.| CallingSubScope
(*
*)let result = s ({ x = s.x; y = s.x; ...})
| DestructuringSubScopeResults
(*
*)let s.x = result.x
*| Assertion
(*
*)let _ = assert e
This kind annotation signals that the let-binding respects a structural invariant. These invariants concern the shape of the expression in the let-binding, and are documented below.
type scope_let = {
scope_let_var : expr Bindlib.var Utils.Pos.marked;
scope_let_kind : scope_let_kind;
scope_let_typ : typ Utils.Pos.marked;
scope_let_expr : expr Utils.Pos.marked Bindlib.box;
}
A scope let-binding has all the information necessary to make a proper let-binding expression, plus an annotation for the kind of the let-binding that comes from the compilation of a Scopelang.Ast
statement.
type scope_body = {
scope_body_lets : scope_let list;
scope_body_result : expr Utils.Pos.marked Bindlib.box;
scope_body_arg : expr Bindlib.var;
scope_body_input_struct : StructName.t;
scope_body_output_struct : StructName.t;
}
Instead of being a single expression, we give a little more ad-hoc structure to the scope body by decomposing it in an ordered list of let-bindings, and a result expression that uses the let-binded variables.
type program = {
decl_ctx : decl_ctx;
scopes : (ScopeName.t * expr Bindlib.var * scope_body) list;
}
Helpers
Variables
val make_abs :
vars ->
expr Utils.Pos.marked Bindlib.box ->
Utils.Pos.t ->
typ Utils.Pos.marked list ->
Utils.Pos.t ->
expr Utils.Pos.marked Bindlib.box
val make_app :
expr Utils.Pos.marked Bindlib.box ->
expr Utils.Pos.marked Bindlib.box list ->
Utils.Pos.t ->
expr Utils.Pos.marked Bindlib.box
val make_let_in :
Var.t ->
typ Utils.Pos.marked ->
expr Utils.Pos.marked Bindlib.box ->
expr Utils.Pos.marked Bindlib.box ->
Utils.Pos.t ->
expr Utils.Pos.marked Bindlib.box
Other
AST manipulation helpers
val build_whole_scope_expr :
decl_ctx ->
scope_body ->
Utils.Pos.t ->
expr Utils.Pos.marked Bindlib.box
Usage: build_whole_scope_expr ctx body scope_position
where scope_position
corresponds to the line of the scope declaration for instance.
Usage: build_whole_program_expr program main_scope
builds an expression corresponding to the main program and returning the main scope as a function.
Used by the optimizer to know when to stop
Traverses all the scopes and retrieves all the types for the variables that may appear in scope or subscope variable definitions, giving them as a big map.