This module implements two interpreters for the functional language defined so far,
-
Krivine Machine (in closure form) that implements Call by Name semantics for function calls
- Given an expression
e
, environmentE
to evaluatee
in, and the type for each binding inE
as a list of (variable name, type), the machine first checks that the bindings inE
are properly typed. Then, it packagese
and its environmentE
into a closure and evaluates the closure starting with an empty stack (see thekrv_mc
function in a5_krivine.ml)
val krv_mc: closure -> stack -> answer (* Helper for krivine_machine *) val krivine_machine: expr -> environment -> environment bindings' types -> answer
- Given an expression
-
SECD Machine that implements Call by Value semantics for function calls
- Given an expression
e
, environmentE
to evaluatee
in, and the type for each binding inE
as a list of (variable name, type), the machine first checks that the bindings inE
are properly typed. Then, it compiles the expressione
into a compiled list of opcodes in Reverse Polish Notation and evaluates this compiled list usingE
and starting with an empty stack and empty dump (see thesecd
function in a5_secd.ml)
val compile: expr -> opcode list val secd: stack -> environment -> opcode list -> dump -> answer (* Helper for secd_machine *) val secd_machine: expr -> environment -> environment bindings' types -> answer
- Given an expression