Theory AbsCF
section "Abstract nonstandard semantics"
theory AbsCF
imports HOLCF HOLCFUtils CPSScheme Utils SetMap
begin
default_sort type
text ‹
After having defined the exact meaning of a control graph, we now alter the algorithm into a statically computable. We note that the contour pointer in the exact semantics is taken from an infinite set. This is unavoidable, as recursion depth is unbounded. But if this were not the case and the set were finite, the function would be calculable, having finite range and domain.
Therefore, we make the set of contour counter values finite and accept that this makes our result less exact, but calculable. We also do not work with values any more but only remember, for each variable, what possible lambdas can occur there. Because we do not have exact values any more, in a conditional expression, both branches are taken.
We want to leave the exact choice of the finite contour set open for now. Therefore, we define a type class capturing the relevant definitions and the fact that the set is finite. Isabelle expects type classes to be non-empty, so we show that the ‹unit› type is in this type class.
›
class contour = finite +
fixes nb_a :: "'a ⇒ label ⇒ 'a" ("\<anb>")
and a_initial_contour :: 'a ("\<abinit>")
instantiation unit :: contour
begin
definition "\<anb> _ _ = ()"
definition "\<abinit> = ()"
instance by standard auto
end
text ‹
Analogous to the previous section, we define types for binding environments, closures, procedures, semantic values (which are now sets of possible procedures) and variable environment. Their types are parametrized by the chosen set of abstract contours.
The abstract variable environment is a partial map to sets in Shivers' dissertation. As he does not need to distinguish between a key not in the map and a key mapped to the empty set, this presentation is redundant. Therefore, I encoded this as a function from keys to sets of values. The theory @{theory "Shivers-CFA.SetMap"} contains functions and lemmas to work with such maps, symbolized by an appended dot (e.g. ‹{}.›, ‹∪.›).
›
type_synonym 'c a_benv = "label ⇀ 'c" ("_ \<abenv>" [1000])
type_synonym 'c a_closure = "lambda × 'c \<abenv>" ("_ \<aclosure>" [1000])