module Eval: sig .. end
Contains the core functions to evaluate 3110Caml expressions.
val vcompare : Ast.value -> Ast.value -> int
vcompare is the analog to OCaml's Pervasives.compare. It
compares two Ast.values, x,y and outputs 1 if x > y, 0
if x=y and -1 if x<y. The comparison operators are with
respect to the "natural" ordering of each type.
val concat : Ast.environment -> Ast.environment -> Ast.environment
concat env env' concatenates the environments env and
env'. It outputs a new environment containing the bindings of both
env and env'.
val pattern_match : Ast.value -> Ast.pattern -> bool * Ast.environment
pattern_match v p takes the value
v and the pattern
p and
outputs the following data:
- A
bool that indicates
whether the v matches the pattern p.
- An environment that
contains the bindings of the variables in the pattern that witness
the match.
val update : Ast.id -> Ast.value -> Ast.environment -> unit
update x v env updates the value of the identifier x to the
value v in the environment env.
val eval : Ast.expr -> Ast.environment -> Ast.value
eval contains the main logic for evaluating 3110Caml
expressions. The evaluation model that we use is the
environment model.
val eval_arith : Ast.expr -> Ast.expr -> Ast.environment -> (int -> int -> int) -> Ast.value
eval_arith is a helper function used to evaluate purely
arithmetic expressions in 3110Caml. The arguments are two arithmetic
expressions, and an environment that has assignments to their
respective free variables, and a function that is used to combine
the two Int values of the expressions after evaluation.
val eval_bool : Ast.expr ->
Ast.expr -> Ast.environment -> (bool -> bool -> bool) -> Ast.value
eval_bool is similar to eval_arith, but is used for boolean
expressions.
val eval_comp : Ast.expr -> Ast.expr -> Ast.environment -> (int -> int -> bool) -> Ast.value
eval_comp is similar to eval_arith, but is used for
expressions involving the polymorphic comparison operators.