Module Compiler_util2

module Compiler_util2: sig .. end

Support code for writing a simple compiler.


type id = string 
val pp_id : Format.formatter -> id -> Ppx_deriving_runtime.unit
val show_id : id -> Ppx_deriving_runtime.string
type op2 = 
| LT
| GT
| Eq
| Add
| Sub
| Mul
| Div
| Mod
val pp_op2 : Format.formatter -> op2 -> Ppx_deriving_runtime.unit
val show_op2 : op2 -> Ppx_deriving_runtime.string
type const = 
| Int of int
| Bool of bool
val pp_const : Format.formatter -> const -> Ppx_deriving_runtime.unit
val show_const : const -> Ppx_deriving_runtime.string
type exp = 
| Id of id
| Const of const
| Op2 of op2 * exp * exp
| If of exp * exp * exp
| Let of id * exp * exp
| Fun of id * id list * exp
| App of exp * exp list
| MkArray of exp * exp
| GetArray of exp * exp
| SetArray of exp * exp * exp
| Seq of exp * exp
| Abort
val pp_exp : Format.formatter -> exp -> Ppx_deriving_runtime.unit
val show_exp : exp -> Ppx_deriving_runtime.string
type value = 
| Int of int
| Bool of bool
| Array of value array
| Closure of (value list -> value)
module IdSet: Set.S  with type elt = id
val from_string : string -> exp
val from_file : string -> exp
val show_value : value -> id
val eval : exp -> value

eval e evaluates e with an interpreter. The interpreter throws exceptions if e has type errors, free variables, etc.

val free_vars : exp -> IdSet.t

free_vars e produces the free variables of e.

val subst : id ->
exp -> exp -> exp

subst x u e substitutes all occurrences of x with u in []e. The * function assumes that u has no free variables.