Dcalc.AstSourceAbstract syntax tree of the default calculus intermediate representation
Abstract syntax tree for the default calculus
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| TAnytype lit = | LBool of bool| LEmptyError| LInt of Runtime.integer| LRat of Runtime.decimal| LMoney of Runtime.money| LUnit| LDate of date| LDuration of durationtype unop = | Not| Minus of op_kind| Log of log_entry * Utils.Uid.MarkedString.info list| Length| IntToRat| GetDay| GetMonth| GetYeartype expr = | EVar of expr Bindlib.var Utils.Pos.marked| ETuple of expr Utils.Pos.marked list * StructName.t optionThe MarkedString.info is the former struct field name
| ETupleAccess of expr Utils.Pos.marked
* int
* StructName.t option
* typ Utils.Pos.marked listThe MarkedString.info is the former struct field name
| EInj of expr Utils.Pos.marked * int * EnumName.t * typ Utils.Pos.marked listThe MarkedString.info is the former enum case name
| EMatch of expr Utils.Pos.marked * expr Utils.Pos.marked list * EnumName.tThe 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.markedThe expressions use the Bindlib library, based on higher-order abstract syntax
type scope_let_kind = | DestructuringInputStructlet x = input.field
| ScopeVarDefinitionlet x = error_on_empty e
| SubScopeVarDefinitionlet s.x = fun _ -> e or let s.x = error_on_empty e for input-only subscope variables.
| CallingSubScopelet result = s ({ x = s.x; y = s.x; ...})
| DestructuringSubScopeResultslet s.x = result.x *
| Assertionlet _ = 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;}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.boxval make_app :
expr Utils.Pos.marked Bindlib.box ->
expr Utils.Pos.marked Bindlib.box list ->
Utils.Pos.t ->
expr Utils.Pos.marked Bindlib.boxval 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.boxval build_whole_scope_expr :
decl_ctx ->
scope_body ->
Utils.Pos.t ->
expr Utils.Pos.marked Bindlib.boxUsage: 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.