doc-src/TutorialI/CodeGen/document/CodeGen.tex
changeset 8771 026f37a86ea7
parent 8746 ccbb5e0dccdf
child 9145 9f7b8de5bfaf
--- a/doc-src/TutorialI/CodeGen/document/CodeGen.tex	Sun Apr 23 11:41:45 2000 +0200
+++ b/doc-src/TutorialI/CodeGen/document/CodeGen.tex	Tue Apr 25 08:09:10 2000 +0200
@@ -16,17 +16,17 @@
 ~~~~~~~~~~~~~~~~~~~~~|~Bex~{"}'v~binop{"}~~{"}('a,'v)expr{"}~~{"}('a,'v)expr{"}%
 \begin{isamarkuptext}%
 \noindent
-The three constructors represent constants, variables and the combination of
-two subexpressions with a binary operation.
+The three constructors represent constants, variables and the application of
+a binary operation to two subexpressions.
 
 The value of an expression w.r.t.\ an environment that maps variables to
 values is easily defined:%
 \end{isamarkuptext}%
-\isacommand{consts}~value~::~{"}('a~{\isasymRightarrow}~'v)~{\isasymRightarrow}~('a,'v)expr~{\isasymRightarrow}~'v{"}\isanewline
+\isacommand{consts}~value~::~{"}('a,'v)expr~{\isasymRightarrow}~('a~{\isasymRightarrow}~'v)~{\isasymRightarrow}~'v{"}\isanewline
 \isacommand{primrec}\isanewline
-{"}value~env~(Cex~v)~=~v{"}\isanewline
-{"}value~env~(Vex~a)~=~env~a{"}\isanewline
-{"}value~env~(Bex~f~e1~e2)~=~f~(value~env~e1)~(value~env~e2){"}%
+{"}value~(Cex~v)~env~=~v{"}\isanewline
+{"}value~(Vex~a)~env~=~env~a{"}\isanewline
+{"}value~(Bex~f~e1~e2)~env~=~f~(value~e1~env)~(value~e2~env){"}%
 \begin{isamarkuptext}%
 The stack machine has three instructions: load a constant value onto the
 stack, load the contents of a certain address onto the stack, and apply a
@@ -37,19 +37,20 @@
 ~~~~~~~~~~~~~~~~~~~~~~~|~Load~'a\isanewline
 ~~~~~~~~~~~~~~~~~~~~~~~|~Apply~{"}'v~binop{"}%
 \begin{isamarkuptext}%
-The execution of the stack machine is modelled by a function \isa{exec}
-that takes a store (modelled as a function from addresses to values, just
-like the environment for evaluating expressions), a stack (modelled as a
-list) of values, and a list of instructions, and returns the stack at the end
-of the execution---the store remains unchanged:%
+The execution of the stack machine is modelled by a function
+\isa{exec} that takes a list of instructions, a store (modelled as a
+function from addresses to values, just like the environment for
+evaluating expressions), and a stack (modelled as a list) of values,
+and returns the stack at the end of the execution---the store remains
+unchanged:%
 \end{isamarkuptext}%
-\isacommand{consts}~exec~::~{"}('a{\isasymRightarrow}'v)~{\isasymRightarrow}~'v~list~{\isasymRightarrow}~('a,'v)instr~list~{\isasymRightarrow}~'v~list{"}\isanewline
+\isacommand{consts}~exec~::~{"}('a,'v)instr~list~{\isasymRightarrow}~('a{\isasymRightarrow}'v)~{\isasymRightarrow}~'v~list~{\isasymRightarrow}~'v~list{"}\isanewline
 \isacommand{primrec}\isanewline
-{"}exec~s~vs~[]~=~vs{"}\isanewline
-{"}exec~s~vs~(i\#is)~=~(case~i~of\isanewline
-~~~~Const~v~~{\isasymRightarrow}~exec~s~(v\#vs)~is\isanewline
-~~|~Load~a~~~{\isasymRightarrow}~exec~s~((s~a)\#vs)~is\isanewline
-~~|~Apply~f~~{\isasymRightarrow}~exec~s~(~(f~(hd~vs)~(hd(tl~vs)))\#(tl(tl~vs))~)~is){"}%
+{"}exec~[]~s~vs~=~vs{"}\isanewline
+{"}exec~(i\#is)~s~vs~=~(case~i~of\isanewline
+~~~~Const~v~~{\isasymRightarrow}~exec~is~s~(v\#vs)\isanewline
+~~|~Load~a~~~{\isasymRightarrow}~exec~is~s~((s~a)\#vs)\isanewline
+~~|~Apply~f~~{\isasymRightarrow}~exec~is~s~((f~(hd~vs)~(hd(tl~vs)))\#(tl(tl~vs)))){"}%
 \begin{isamarkuptext}%
 \noindent
 Recall that \isa{hd} and \isa{tl}
@@ -72,12 +73,12 @@
 Now we have to prove the correctness of the compiler, i.e.\ that the
 execution of a compiled expression results in the value of the expression:%
 \end{isamarkuptext}%
-\isacommand{theorem}~{"}exec~s~[]~(comp~e)~=~[value~s~e]{"}%
+\isacommand{theorem}~{"}exec~(comp~e)~s~[]~=~[value~e~s]{"}%
 \begin{isamarkuptext}%
 \noindent
 This theorem needs to be generalized to%
 \end{isamarkuptext}%
-\isacommand{theorem}~{"}{\isasymforall}vs.~exec~s~vs~(comp~e)~=~(value~s~e)~\#~vs{"}%
+\isacommand{theorem}~{"}{\isasymforall}vs.~exec~(comp~e)~s~vs~=~(value~e~s)~\#~vs{"}%
 \begin{isamarkuptxt}%
 \noindent
 which is proved by induction on \isa{e} followed by simplification, once
@@ -85,7 +86,7 @@
 instruction sequences:%
 \end{isamarkuptxt}%
 \isacommand{lemma}~exec\_app[simp]:\isanewline
-~~{"}{\isasymforall}vs.~exec~s~vs~(xs@ys)~=~exec~s~(exec~s~vs~xs)~ys{"}%
+~~{"}{\isasymforall}vs.~exec~(xs@ys)~s~vs~=~exec~ys~s~(exec~xs~s~vs){"}%
 \begin{isamarkuptxt}%
 \noindent
 This requires induction on \isa{xs} and ordinary simplification for the
@@ -105,7 +106,7 @@
 \noindent
 Although this is more compact, it is less clear for the reader of the proof.
 
-We could now go back and prove \isa{exec s [] (comp e) = [value s e]}
+We could now go back and prove \isa{exec (comp e) s [] = [value e s]}
 merely by simplification with the generalized version we just proved.
 However, this is unnecessary because the generalized version fully subsumes
 its instance.%