1 (* Title: HOL/Library/Code_Integer.thy
3 Author: Florian Haftmann, TU Muenchen
6 header {* Pretty integer literals for code generation *}
9 imports Plain "~~/src/HOL/Code_Eval" "~~/src/HOL/Presburger"
13 HOL numeral expressions are mapped to integer literals
14 in target languages, using predefined target language
15 operations for abstract integer operations.
20 (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 true) ["SML", "OCaml", "Haskell"]
31 code_const "Int.Pls" and "Int.Min" and "Int.Bit0" and "Int.Bit1"
32 (SML "raise/ Fail/ \"Pls\""
33 and "raise/ Fail/ \"Min\""
34 and "!((_);/ raise/ Fail/ \"Bit0\")"
35 and "!((_);/ raise/ Fail/ \"Bit1\")")
36 (OCaml "failwith/ \"Pls\""
37 and "failwith/ \"Min\""
38 and "!((_);/ failwith/ \"Bit0\")"
39 and "!((_);/ failwith/ \"Bit1\")")
40 (Haskell "error/ \"Pls\""
43 and "error/ \"Bit1\"")
46 (SML "IntInf.- ((_), 1)")
47 (OCaml "Big'_int.pred'_big'_int")
48 (Haskell "!(_/ -/ 1)")
51 (SML "IntInf.+ ((_), 1)")
52 (OCaml "Big'_int.succ'_big'_int")
53 (Haskell "!(_/ +/ 1)")
55 code_const "op + \<Colon> int \<Rightarrow> int \<Rightarrow> int"
56 (SML "IntInf.+ ((_), (_))")
57 (OCaml "Big'_int.add'_big'_int")
58 (Haskell infixl 6 "+")
60 code_const "uminus \<Colon> int \<Rightarrow> int"
62 (OCaml "Big'_int.minus'_big'_int")
65 code_const "op - \<Colon> int \<Rightarrow> int \<Rightarrow> int"
66 (SML "IntInf.- ((_), (_))")
67 (OCaml "Big'_int.sub'_big'_int")
68 (Haskell infixl 6 "-")
70 code_const "op * \<Colon> int \<Rightarrow> int \<Rightarrow> int"
71 (SML "IntInf.* ((_), (_))")
72 (OCaml "Big'_int.mult'_big'_int")
73 (Haskell infixl 7 "*")
75 code_const "eq_class.eq \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
76 (SML "!((_ : IntInf.int) = _)")
77 (OCaml "Big'_int.eq'_big'_int")
78 (Haskell infixl 4 "==")
80 code_const "op \<le> \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
81 (SML "IntInf.<= ((_), (_))")
82 (OCaml "Big'_int.le'_big'_int")
83 (Haskell infix 4 "<=")
85 code_const "op < \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
86 (SML "IntInf.< ((_), (_))")
87 (OCaml "Big'_int.lt'_big'_int")
90 code_reserved SML IntInf
91 code_reserved OCaml Big_int
95 lemma [code, code del]:
96 "(Code_Eval.term_of \<Colon> int \<Rightarrow> term) = Code_Eval.term_of" ..
98 code_const "Code_Eval.term_of \<Colon> int \<Rightarrow> term"
99 (SML "HOLogic.mk'_number/ HOLogic.intT")