package catala
Install
Dune Dependency
Authors
Maintainers
Sources
md5=8f891209d18b6540df9c34b2d1a6a783
sha512=737770b87a057674bceefe77e8526720732552f51f424afcebcb6a628267eab522c4fd993caca1ae8ed7ace65a4a87e485af10c1676e51ca5939509a1b841ac2
doc/shared_ast.html
Default calculus
This module contains a generic AST structure, various type definitions and helpers that are reused in various passes of the compiler.
The Shared_ast.Definitions
module
The main module Shared_ast
is exposed at top-level of the library (so that open Shared_ast
gives access to the structures). It defines literals, operators, and in particular the type Shared_ast.naked_gexpr
.
The Shared_ast.naked_gexpr
type regroups all the cases for the Dcalc and Lcalc ASTs, with unconstrained annotations (used for positions, types, etc.). A GADT is used to eliminate irrelevant cases, so that e.g. (dcalc, _) naked_gexpr
doesn't have the ERaise
and ECatch
cases, while (lcalc, _) naked_gexpr
doesn't have EDefault
.
For example, Lcalc expressions are then defined as type 'm naked_expr = (Shared_ast.lcalc, 'm) Shared_ast.naked_gexpr
.
This makes it possible to write a single function that works on the different ASTs, by having it take a ('a, _) naked_gexpr
as input, while retaining a much stricter policy than polymorphic variants.
The module additionally defines the encompassing scope
and program
structures that are also shared between different compiler passes.
Helper library
The Shared_ast.Var
defines 'e Var.Set.t
and ('e, _) Var.Map.t
types that are useful to handle variables for the different 'e
expression types without re-instanciating Set.Make
and Map.Make
each time.
Shared_ast.Expr
contains various helpers to build well-formed expressions, and for traversal.
The following modules are dedicated to handling the program structure around expressions. Note that these don't make sense for the early compiler passes (up to Scopelang
).
Shared_ast.Scope
Functions handling the code item structures ofshared_ast
, in particular the scopesShared_ast.Program