package catala

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Scopelang.AstSource

Abstract syntax tree of the scope language

Identifiers

Sourcemodule ScopeName = Dcalc.Ast.ScopeName
Sourcemodule ScopeMap : Map.S with type key = ScopeName.t
Sourcemodule ScopeVarSet : Set.S with type elt = ScopeVar.t
Sourcemodule ScopeVarMap : Map.S with type key = ScopeVar.t
Sourcemodule StructName = Dcalc.Ast.StructName
Sourcemodule StructMap = Dcalc.Ast.StructMap
Sourcemodule StructFieldName = Dcalc.Ast.StructFieldName
module StructFieldMapLift : sig ... end
Sourcemodule EnumName = Dcalc.Ast.EnumName
Sourcemodule EnumMap = Dcalc.Ast.EnumMap
Sourcemodule EnumConstructor = Dcalc.Ast.EnumConstructor
module EnumConstructorMapLift : sig ... end

Abstract syntax tree

Sourcetype typ =
  1. | TLit of Dcalc.Ast.typ_lit
  2. | TStruct of StructName.t
  3. | TEnum of EnumName.t
  4. | TArrow of typ Utils.Marked.pos * typ Utils.Marked.pos
  5. | TArray of typ
  6. | TAny
Sourcemodule Typ : Set.OrderedType with type t = typ
Sourcetype marked_expr = expr Utils.Marked.pos

The expressions use the Bindlib library, based on higher-order abstract syntax

Sourceand expr =
  1. | ELocation of location
  2. | EVar of expr Bindlib.var
  3. | EStruct of StructName.t * marked_expr StructFieldMap.t
  4. | EStructAccess of marked_expr * StructFieldName.t * StructName.t
  5. | EEnumInj of marked_expr * EnumConstructor.t * EnumName.t
  6. | EMatch of marked_expr * EnumName.t * marked_expr EnumConstructorMap.t
  7. | ELit of Dcalc.Ast.lit
  8. | EAbs of (expr, marked_expr) Bindlib.mbinder * typ Utils.Marked.pos list
  9. | EApp of marked_expr * marked_expr list
  10. | EOp of Dcalc.Ast.operator
  11. | EDefault of marked_expr list * marked_expr * marked_expr
  12. | EIfThenElse of marked_expr * marked_expr * marked_expr
  13. | EArray of marked_expr list
  14. | ErrorOnEmpty of marked_expr
Sourcemodule Expr : Set.OrderedType with type t = expr
Sourcemodule ExprMap : Map.S with type key = expr
Sourceval locations_used : expr Utils.Marked.pos -> LocationSet.t
Sourcetype io_input =
  1. | NoInput
    (*

    For an internal variable defined only in the scope, and does not appear in the input.

    *)
  2. | OnlyInput
    (*

    For variables that should not be redefined in the scope, because they appear in the input.

    *)
  3. | Reentrant
    (*

    For variables defined in the scope that can also be redefined by the caller as they appear in the input.

    *)

This type characterizes the three levels of visibility for a given scope variable with regards to the scope's input and possible redefinitions inside the scope..

Sourcetype io = {
  1. io_output : bool Utils.Marked.pos;
    (*

    true is present in the output of the scope.

    *)
  2. io_input : io_input Utils.Marked.pos;
}

Characterization of the input/output status of a scope variable.

Sourcetype scope_decl = {
  1. scope_decl_name : ScopeName.t;
  2. scope_sig : (typ Utils.Marked.pos * io) ScopeVarMap.t;
  3. scope_decl_rules : rule list;
}
Sourcetype program = {
  1. program_scopes : scope_decl ScopeMap.t;
  2. program_enums : enum_ctx;
  3. program_structs : struct_ctx;
}

Variable helpers

Sourcemodule Var : sig ... end
Sourcemodule VarMap : Map.S with type key = Var.t
Sourcetype vars = expr Bindlib.mvar
Sourceval make_var : Var.t Utils.Marked.pos -> expr Utils.Marked.pos Bindlib.box
Sourceval make_abs : vars -> expr Utils.Marked.pos Bindlib.box -> typ Utils.Marked.pos list -> Utils.Pos.t -> expr Utils.Marked.pos Bindlib.box
Sourceval make_app : expr Utils.Marked.pos Bindlib.box -> expr Utils.Marked.pos Bindlib.box list -> Utils.Pos.t -> expr Utils.Marked.pos Bindlib.box
Sourceval make_let_in : Var.t -> typ Utils.Marked.pos -> expr Utils.Marked.pos Bindlib.box -> expr Utils.Marked.pos Bindlib.box -> expr Utils.Marked.pos Bindlib.box

make_default ?pos exceptions just cons builds a term semantically equivalent to <exceptions | just :- cons> (the EDefault constructor) while avoiding redundant nested constructions. The position is extracted from just by default.

Note that, due to the simplifications taking place, the result might not be of the form EDefault:

  • <true :- x> is rewritten as x
  • <ex | true :- def>, when def is a default term <j :- c> without exceptions, is collapsed into <ex | def>
  • <ex | false :- _>, when ex is a single exception, is rewritten as ex
OCaml

Innovation. Community. Security.