1 (* Title: HOL/Library/Code_Integer.thy
2 Author: Florian Haftmann, TU Muenchen
5 header {* Pretty integer literals for code generation *}
12 HOL numeral expressions are mapped to integer literals
13 in target languages, using predefined target language
14 operations for abstract integer operations.
19 (OCaml "Big'_int.big'_int")
23 code_instance int :: eq
27 fold (Numeral.add_code @{const_name number_int_inst.number_of_int}
28 true Code_Printer.literal_numeral) ["SML", "OCaml", "Haskell", "Scala"]
29 #> Numeral.add_code @{const_name number_int_inst.number_of_int}
30 true Code_Printer.literal_numeral "Scala"
33 code_const "Int.Pls" and "Int.Min" and "Int.Bit0" and "Int.Bit1"
34 (SML "raise/ Fail/ \"Pls\""
35 and "raise/ Fail/ \"Min\""
36 and "!((_);/ raise/ Fail/ \"Bit0\")"
37 and "!((_);/ raise/ Fail/ \"Bit1\")")
38 (OCaml "failwith/ \"Pls\""
39 and "failwith/ \"Min\""
40 and "!((_);/ failwith/ \"Bit0\")"
41 and "!((_);/ failwith/ \"Bit1\")")
42 (Haskell "error/ \"Pls\""
45 and "error/ \"Bit1\"")
46 (Scala "!error(\"Pls\")"
48 and "!error(\"Bit0\")"
49 and "!error(\"Bit1\")")
53 (SML "IntInf.- ((_), 1)")
54 (OCaml "Big'_int.pred'_big'_int")
55 (Haskell "!(_/ -/ 1)")
59 (SML "IntInf.+ ((_), 1)")
60 (OCaml "Big'_int.succ'_big'_int")
61 (Haskell "!(_/ +/ 1)")
64 code_const "op + \<Colon> int \<Rightarrow> int \<Rightarrow> int"
65 (SML "IntInf.+ ((_), (_))")
66 (OCaml "Big'_int.add'_big'_int")
67 (Haskell infixl 6 "+")
70 code_const "uminus \<Colon> int \<Rightarrow> int"
72 (OCaml "Big'_int.minus'_big'_int")
76 code_const "op - \<Colon> int \<Rightarrow> int \<Rightarrow> int"
77 (SML "IntInf.- ((_), (_))")
78 (OCaml "Big'_int.sub'_big'_int")
79 (Haskell infixl 6 "-")
82 code_const "op * \<Colon> int \<Rightarrow> int \<Rightarrow> int"
83 (SML "IntInf.* ((_), (_))")
84 (OCaml "Big'_int.mult'_big'_int")
85 (Haskell infixl 7 "*")
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 _)")
91 (Haskell "divMod/ (abs _)/ (abs _)")
92 (Scala "!(_.abs '/% _.abs)")
94 code_const "eq_class.eq \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
95 (SML "!((_ : IntInf.int) = _)")
96 (OCaml "Big'_int.eq'_big'_int")
97 (Haskell infixl 4 "==")
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 "<=")
104 (Scala infixl 4 "<=")
106 code_const "op < \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
107 (SML "IntInf.< ((_), (_))")
108 (OCaml "Big'_int.lt'_big'_int")
109 (Haskell infix 4 "<")
110 (Scala infixl 4 "<=")
112 code_const Code_Numeral.int_of
113 (SML "IntInf.fromInt")
116 (Scala "!BigInt((_))")
118 text {* Evaluation *}
120 code_const "Code_Evaluation.term_of \<Colon> int \<Rightarrow> term"
121 (Eval "HOLogic.mk'_number/ HOLogic.intT")