doc-src/TutorialI/CodeGen/CodeGen.thy
changeset 10971 6852682eaf16
parent 10885 90695f46440b
child 11428 332347b9b942
equal deleted inserted replaced
10970:7917e66505a4 10971:6852682eaf16
    47 text{*
    47 text{*
    48 The execution of the stack machine is modelled by a function
    48 The execution of the stack machine is modelled by a function
    49 @{text"exec"} that takes a list of instructions, a store (modelled as a
    49 @{text"exec"} that takes a list of instructions, a store (modelled as a
    50 function from addresses to values, just like the environment for
    50 function from addresses to values, just like the environment for
    51 evaluating expressions), and a stack (modelled as a list) of values,
    51 evaluating expressions), and a stack (modelled as a list) of values,
    52 and returns the stack at the end of the execution---the store remains
    52 and returns the stack at the end of the execution --- the store remains
    53 unchanged:
    53 unchanged:
    54 *}
    54 *}
    55 
    55 
    56 consts exec :: "('a,'v)instr list \<Rightarrow> ('a\<Rightarrow>'v) \<Rightarrow> 'v list \<Rightarrow> 'v list";
    56 consts exec :: "('a,'v)instr list \<Rightarrow> ('a\<Rightarrow>'v) \<Rightarrow> 'v list \<Rightarrow> 'v list";
    57 primrec
    57 primrec
   108 automatic case splitting as well, which finishes the proof:
   108 automatic case splitting as well, which finishes the proof:
   109 *}
   109 *}
   110 apply(induct_tac xs, simp, simp split: instr.split);
   110 apply(induct_tac xs, simp, simp split: instr.split);
   111 (*<*)done(*>*)
   111 (*<*)done(*>*)
   112 text{*\noindent
   112 text{*\noindent
   113 Note that because \isaindex{auto} performs simplification, it can
   113 Note that because both \isaindex{simp_all} and \isaindex{auto} perform simplification, they can
   114 also be modified in the same way @{text simp} can. Thus the proof can be
   114 be modified in the same way @{text simp} can. Thus the proof can be
   115 rewritten as
   115 rewritten as
   116 *}
   116 *}
   117 (*<*)
   117 (*<*)
   118 declare exec_app[simp del];
   118 declare exec_app[simp del];
   119 lemma [simp]: "\<forall>vs. exec (xs@ys) s vs = exec ys s (exec xs s vs)"; 
   119 lemma [simp]: "\<forall>vs. exec (xs@ys) s vs = exec ys s (exec xs s vs)"; 
   120 (*>*)
   120 (*>*)
   121 apply(induct_tac xs, auto split: instr.split);
   121 apply(induct_tac xs, simp_all split: instr.split);
   122 (*<*)done(*>*)
   122 (*<*)done(*>*)
   123 text{*\noindent
   123 text{*\noindent
   124 Although this is more compact, it is less clear for the reader of the proof.
   124 Although this is more compact, it is less clear for the reader of the proof.
   125 
   125 
   126 We could now go back and prove \isa{exec (comp e) s [] = [value e s]}
   126 We could now go back and prove \isa{exec (comp e) s [] = [value e s]}