# HG changeset patch # User haftmann # Date 1166426493 -3600 # Node ID e871f57b1adbdf74b4379bae820a530805c8ff19 # Parent 96a601bc59d88b7790b79a7e91ee068c71d520bd now testing executable content of nearly all HOL diff -r 96a601bc59d8 -r e871f57b1adb src/HOL/ex/Codegenerator.thy --- a/src/HOL/ex/Codegenerator.thy Mon Dec 18 08:21:32 2006 +0100 +++ b/src/HOL/ex/Codegenerator.thy Mon Dec 18 08:21:33 2006 +0100 @@ -2,74 +2,38 @@ Author: Florian Haftmann, TU Muenchen *) -header {* Test and Examples for code generator *} +header {* Tests and examples for code generator *} theory Codegenerator -imports Main Records +imports + Main + Records + AssocList + Binomial + Commutative_Ring + GCD + List_Prefix + Nat_Infinity + NatPair + Nested_Environment + Permutation + Primes + Product_ord + SetsAndFunctions + State_Monad + While_Combinator + Word + (*a lot of stuff to test*) begin -subsection {* booleans *} - -definition - xor :: "bool \ bool \ bool" where - "xor p q = ((p | q) & \ (p & q))" - -subsection {* natural numbers *} - definition n :: nat where "n = 42" -subsection {* pairs *} - -definition - swap :: "'a * 'b \ 'b * 'a" where - "swap p = (let (x, y) = p in (y, x))" - -definition - appl :: "('a \ 'b) * 'a \ 'b" where - "appl p = (let (f, x) = p in f x)" - -definition - snd_three :: "'a * 'b * 'c => 'b" where - "snd_three a = id (\(a, b, c). b) a" - -lemma [code]: - "swap (x, y) = (y, x)" - unfolding swap_def Let_def by auto - -lemma [code]: - "appl (f, x) = f x" - unfolding appl_def Let_def by auto - -subsection {* integers *} - definition k :: "int" where "k = -42" -function - fac :: "int => int" where - "fac j = (if j <= 0 then 1 else j * (fac (j - 1)))" - by pat_completeness auto -termination by (relation "measure nat") auto - -subsection {* sums *} - -subsection {* options *} - -subsection {* lists *} - -definition - ps :: "nat list" where - "ps = [2, 3, 5, 7, 11]" - -definition - qs :: "nat list" where - "qs == rev ps" - -subsection {* mutual datatypes *} - datatype mut1 = Tip | Top mut2 and mut2 = Tip | Top mut1 @@ -83,16 +47,10 @@ "mut2 mut2.Tip = mut2.Tip" "mut2 (mut2.Top x) = mut2.Top (mut1 x)" -subsection {* records *} - -subsection {* equalities *} - -subsection {* strings *} - definition "mystring = ''my home is my castle''" -subsection {* nested lets and such *} +text {* nested lets and such *} definition "abs_let x = (let (y, z) = x in (\u. case u of () \ (y + y)))" @@ -110,84 +68,14 @@ "apply_tower = (\x. x (\x. x (\x. x)))" definition - "keywords fun datatype class instance funa classa = - Suc fun + datatype * class mod instance - funa - classa" + "keywords fun datatype x instance funa classa = + Suc fun + datatype * x mod instance - funa - classa" hide (open) const keywords definition "shadow keywords = keywords @ [Codegenerator.keywords 0 0 0 0 0 0]" -code_gen - xor -code_gen - "0::nat" "1::nat" -code_gen - Pair fst snd Let split swap snd_three -code_gen - "op + :: nat \ nat \ nat" - "op - :: nat \ nat \ nat" - "op * :: nat \ nat \ nat" - "op < :: nat \ nat \ bool" - "op <= :: nat \ nat \ bool" -code_gen - appl -code_gen - Inl Inr -code_gen - None Some -code_gen - hd tl "op @" ps qs -code_gen - mut1 mut2 -code_gen - remove1 - null - replicate - rotate1 - rotate - splice -code_gen - remdups - "distinct" - filter -code_gen - foo1 foo3 -code_gen - mystring -code_gen - apply_tower Codegenerator.keywords shadow base_case -code_gen - abs_let nested_let case_let -code_gen "0::int" "1::int" - (SML) (Haskell) -code_gen n - (SML) (Haskell) -code_gen fac - (SML) (Haskell) -code_gen - k - "op + :: int \ int \ int" - "op - :: int \ int \ int" - "op * :: int \ int \ int" - "op < :: int \ int \ bool" - "op <= :: int \ int \ bool" - fac - "op div :: int \ int \ int" - "op mod :: int \ int \ int" - (SML) (Haskell) -code_gen - "op = :: bool \ bool \ bool" - "op = :: nat \ nat \ bool" - "op = :: int \ int \ bool" - "op = :: ('a\eq) * ('b\eq) \ 'a * 'b \ bool" - "op = :: ('a\eq) + ('b\eq) \ 'a + 'b \ bool" - "op = :: ('a\eq) option \ 'a option \ bool" - "op = :: ('a\eq) list \ 'a list \ bool" - "op = :: mut1 \ mut1 \ bool" - "op = :: mut2 \ mut2 \ bool" - "op = :: ('a\eq) point_scheme \ 'a point_scheme \ bool" - -code_gen (SML #) (Haskell -) +code_gen "*" (Haskell -) (SML #) end \ No newline at end of file