Theory Eval
section "Standard semantics"
theory Eval
imports HOLCF HOLCFUtils CPSScheme
begin
text ‹
We begin by giving the standard semantics for our language. Although this is not actually used to show any results, it is helpful to see that the later algorithms ``look similar'' to the evaluation code and the relation between calls done during evaluation and calls recorded by the control flow graph.
›
text ‹
We follow the definition in Figure 3.1 and 3.2 of Shivers' dissertation, with the clarifications from Section 4.1. As explained previously, our set of values encompasses just the integers, there is no separate value for \textit{false}. Also, values and procedures are not distinguished by the type system.
Due to recursion, one variable can have more than one currently valid binding, and due to closures all bindings can possibly be accessed. A simple call stack is therefore not sufficient. Instead we have a \textit{contour counter}, which is increased in each evaluation step. It can also be thought of as a time counter. The variable environment maps tuples of variables and contour counter to values, thus allowing a variable to have more than one active binding. A contour environment lists the currently visible binding for each binding position and is preserved when a lambda expression is turned into a closure.
›
type_synonym contour = nat
type_synonym benv = "label ⇀ contour"
type_synonym closure = "lambda × benv"
text ‹
The set of semantic values consist of the integers, closures, primitive operations and a special value ‹Stop›. This is passed as an argument to the program and represents the terminal continuation. When this value occurs in the first position of a call, the program terminates.
›