| author | bulwahn | 
| Wed, 31 Mar 2010 16:44:41 +0200 | |
| changeset 36052 | c240b2a5df90 | 
| parent 34944 | 970e1466028d | 
| child 37947 | 844977c7abeb | 
| permissions | -rw-r--r-- | 
| 24999 | 1 | (* Title: HOL/Library/Code_Integer.thy | 
| 2 | Author: Florian Haftmann, TU Muenchen | |
| 3 | *) | |
| 4 | ||
| 5 | header {* Pretty integer literals for code generation *}
 | |
| 6 | ||
| 7 | theory Code_Integer | |
| 31203 
5c8fb4fd67e0
moved Code_Index, Random and Quickcheck before Main
 haftmann parents: 
31192diff
changeset | 8 | imports Main | 
| 24999 | 9 | begin | 
| 10 | ||
| 11 | text {*
 | |
| 12 | HOL numeral expressions are mapped to integer literals | |
| 13 | in target languages, using predefined target language | |
| 14 | operations for abstract integer operations. | |
| 15 | *} | |
| 16 | ||
| 17 | code_type int | |
| 18 | (SML "IntInf.int") | |
| 19 | (OCaml "Big'_int.big'_int") | |
| 20 | (Haskell "Integer") | |
| 34899 | 21 | (Scala "BigInt") | 
| 24999 | 22 | |
| 23 | code_instance int :: eq | |
| 24 | (Haskell -) | |
| 25 | ||
| 26 | setup {*
 | |
| 25928 | 27 |   fold (Numeral.add_code @{const_name number_int_inst.number_of_int}
 | 
| 34944 
970e1466028d
code literals: distinguish numeral classes by different entries
 haftmann parents: 
34899diff
changeset | 28 | true Code_Printer.literal_numeral) ["SML", "OCaml", "Haskell", "Scala"] | 
| 34899 | 29 |   #> Numeral.add_code @{const_name number_int_inst.number_of_int}
 | 
| 34944 
970e1466028d
code literals: distinguish numeral classes by different entries
 haftmann parents: 
34899diff
changeset | 30 | true Code_Printer.literal_numeral "Scala" | 
| 24999 | 31 | *} | 
| 32 | ||
| 26086 
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
 huffman parents: 
26009diff
changeset | 33 | code_const "Int.Pls" and "Int.Min" and "Int.Bit0" and "Int.Bit1" | 
| 24999 | 34 | (SML "raise/ Fail/ \"Pls\"" | 
| 35 | and "raise/ Fail/ \"Min\"" | |
| 26086 
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
 huffman parents: 
26009diff
changeset | 36 | and "!((_);/ raise/ Fail/ \"Bit0\")" | 
| 
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
 huffman parents: 
26009diff
changeset | 37 | and "!((_);/ raise/ Fail/ \"Bit1\")") | 
| 24999 | 38 | (OCaml "failwith/ \"Pls\"" | 
| 39 | and "failwith/ \"Min\"" | |
| 26086 
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
 huffman parents: 
26009diff
changeset | 40 | and "!((_);/ failwith/ \"Bit0\")" | 
| 
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
 huffman parents: 
26009diff
changeset | 41 | and "!((_);/ failwith/ \"Bit1\")") | 
| 24999 | 42 | (Haskell "error/ \"Pls\"" | 
| 43 | and "error/ \"Min\"" | |
| 26086 
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
 huffman parents: 
26009diff
changeset | 44 | and "error/ \"Bit0\"" | 
| 
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
 huffman parents: 
26009diff
changeset | 45 | and "error/ \"Bit1\"") | 
| 34899 | 46 | (Scala "!error(\"Pls\")" | 
| 47 | and "!error(\"Min\")" | |
| 48 | and "!error(\"Bit0\")" | |
| 49 | and "!error(\"Bit1\")") | |
| 50 | ||
| 24999 | 51 | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: 
25767diff
changeset | 52 | code_const Int.pred | 
| 24999 | 53 | (SML "IntInf.- ((_), 1)") | 
| 54 | (OCaml "Big'_int.pred'_big'_int") | |
| 55 | (Haskell "!(_/ -/ 1)") | |
| 34899 | 56 | (Scala "!(_/ -/ 1)") | 
| 24999 | 57 | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: 
25767diff
changeset | 58 | code_const Int.succ | 
| 24999 | 59 | (SML "IntInf.+ ((_), 1)") | 
| 60 | (OCaml "Big'_int.succ'_big'_int") | |
| 61 | (Haskell "!(_/ +/ 1)") | |
| 34899 | 62 | (Scala "!(_/ +/ 1)") | 
| 24999 | 63 | |
| 64 | code_const "op + \<Colon> int \<Rightarrow> int \<Rightarrow> int" | |
| 65 | (SML "IntInf.+ ((_), (_))") | |
| 66 | (OCaml "Big'_int.add'_big'_int") | |
| 67 | (Haskell infixl 6 "+") | |
| 34899 | 68 | (Scala infixl 7 "+") | 
| 24999 | 69 | |
| 70 | code_const "uminus \<Colon> int \<Rightarrow> int" | |
| 71 | (SML "IntInf.~") | |
| 72 | (OCaml "Big'_int.minus'_big'_int") | |
| 73 | (Haskell "negate") | |
| 34899 | 74 | (Scala "!(- _)") | 
| 24999 | 75 | |
| 76 | code_const "op - \<Colon> int \<Rightarrow> int \<Rightarrow> int" | |
| 77 | (SML "IntInf.- ((_), (_))") | |
| 78 | (OCaml "Big'_int.sub'_big'_int") | |
| 79 | (Haskell infixl 6 "-") | |
| 34899 | 80 | (Scala infixl 7 "-") | 
| 24999 | 81 | |
| 82 | code_const "op * \<Colon> int \<Rightarrow> int \<Rightarrow> int" | |
| 83 | (SML "IntInf.* ((_), (_))") | |
| 84 | (OCaml "Big'_int.mult'_big'_int") | |
| 85 | (Haskell infixl 7 "*") | |
| 34899 | 86 | (Scala infixl 8 "*") | 
| 24999 | 87 | |
| 29936 | 88 | code_const pdivmod | 
| 34899 | 89 | (SML "IntInf.divMod/ (IntInf.abs _,/ IntInf.abs _)") | 
| 90 | (OCaml "Big'_int.quomod'_big'_int/ (Big'_int.abs'_big'_int _)/ (Big'_int.abs'_big'_int _)") | |
| 34944 
970e1466028d
code literals: distinguish numeral classes by different entries
 haftmann parents: 
34899diff
changeset | 91 | (Haskell "divMod/ (abs _)/ (abs _)") | 
| 34899 | 92 | (Scala "!(_.abs '/% _.abs)") | 
| 29936 | 93 | |
| 28346 
b8390cd56b8f
discontinued special treatment of op = vs. eq_class.eq
 haftmann parents: 
28228diff
changeset | 94 | code_const "eq_class.eq \<Colon> int \<Rightarrow> int \<Rightarrow> bool" | 
| 24999 | 95 | (SML "!((_ : IntInf.int) = _)") | 
| 96 | (OCaml "Big'_int.eq'_big'_int") | |
| 97 | (Haskell infixl 4 "==") | |
| 34899 | 98 | (Scala infixl 5 "==") | 
| 24999 | 99 | |
| 100 | code_const "op \<le> \<Colon> int \<Rightarrow> int \<Rightarrow> bool" | |
| 101 | (SML "IntInf.<= ((_), (_))") | |
| 102 | (OCaml "Big'_int.le'_big'_int") | |
| 103 | (Haskell infix 4 "<=") | |
| 34899 | 104 | (Scala infixl 4 "<=") | 
| 24999 | 105 | |
| 106 | code_const "op < \<Colon> int \<Rightarrow> int \<Rightarrow> bool" | |
| 107 | (SML "IntInf.< ((_), (_))") | |
| 108 | (OCaml "Big'_int.lt'_big'_int") | |
| 109 | (Haskell infix 4 "<") | |
| 34899 | 110 | (Scala infixl 4 "<=") | 
| 24999 | 111 | |
| 31205 
98370b26c2ce
String.literal replaces message_string, code_numeral replaces (code_)index
 haftmann parents: 
31203diff
changeset | 112 | code_const Code_Numeral.int_of | 
| 31192 | 113 | (SML "IntInf.fromInt") | 
| 31377 | 114 | (OCaml "_") | 
| 31192 | 115 | (Haskell "toEnum") | 
| 34944 
970e1466028d
code literals: distinguish numeral classes by different entries
 haftmann parents: 
34899diff
changeset | 116 | (Scala "!BigInt((_))") | 
| 24999 | 117 | |
| 28228 | 118 | text {* Evaluation *}
 | 
| 119 | ||
| 32657 | 120 | code_const "Code_Evaluation.term_of \<Colon> int \<Rightarrow> term" | 
| 31192 | 121 | (Eval "HOLogic.mk'_number/ HOLogic.intT") | 
| 28228 | 122 | |
| 24999 | 123 | end |