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")
22 code_instance int :: eq
26 fold (Numeral.add_code @{const_name number_int_inst.number_of_int}
27 true true) ["SML", "OCaml", "Haskell"]
30 code_const "Int.Pls" and "Int.Min" and "Int.Bit0" and "Int.Bit1"
31 (SML "raise/ Fail/ \"Pls\""
32 and "raise/ Fail/ \"Min\""
33 and "!((_);/ raise/ Fail/ \"Bit0\")"
34 and "!((_);/ raise/ Fail/ \"Bit1\")")
35 (OCaml "failwith/ \"Pls\""
36 and "failwith/ \"Min\""
37 and "!((_);/ failwith/ \"Bit0\")"
38 and "!((_);/ failwith/ \"Bit1\")")
39 (Haskell "error/ \"Pls\""
42 and "error/ \"Bit1\"")
45 (SML "IntInf.- ((_), 1)")
46 (OCaml "Big'_int.pred'_big'_int")
47 (Haskell "!(_/ -/ 1)")
50 (SML "IntInf.+ ((_), 1)")
51 (OCaml "Big'_int.succ'_big'_int")
52 (Haskell "!(_/ +/ 1)")
54 code_const "op + \<Colon> int \<Rightarrow> int \<Rightarrow> int"
55 (SML "IntInf.+ ((_), (_))")
56 (OCaml "Big'_int.add'_big'_int")
57 (Haskell infixl 6 "+")
59 code_const "uminus \<Colon> int \<Rightarrow> int"
61 (OCaml "Big'_int.minus'_big'_int")
64 code_const "op - \<Colon> int \<Rightarrow> int \<Rightarrow> int"
65 (SML "IntInf.- ((_), (_))")
66 (OCaml "Big'_int.sub'_big'_int")
67 (Haskell infixl 6 "-")
69 code_const "op * \<Colon> int \<Rightarrow> int \<Rightarrow> int"
70 (SML "IntInf.* ((_), (_))")
71 (OCaml "Big'_int.mult'_big'_int")
72 (Haskell infixl 7 "*")
75 (SML "(fn k => fn l =>/ IntInf.divMod/ (IntInf.abs k,/ IntInf.abs l))")
76 (OCaml "(fun k -> fun l ->/ Big'_int.quomod'_big'_int/ (Big'_int.abs'_big'_int k)/ (Big'_int.abs'_big'_int l))")
77 (Haskell "(\\k l ->/ divMod/ (abs k)/ (abs l))")
79 code_const "eq_class.eq \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
80 (SML "!((_ : IntInf.int) = _)")
81 (OCaml "Big'_int.eq'_big'_int")
82 (Haskell infixl 4 "==")
84 code_const "op \<le> \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
85 (SML "IntInf.<= ((_), (_))")
86 (OCaml "Big'_int.le'_big'_int")
87 (Haskell infix 4 "<=")
89 code_const "op < \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
90 (SML "IntInf.< ((_), (_))")
91 (OCaml "Big'_int.lt'_big'_int")
94 code_const Code_Numeral.int_of
95 (SML "IntInf.fromInt")
99 code_reserved SML IntInf
101 text {* Evaluation *}
103 code_const "Code_Eval.term_of \<Colon> int \<Rightarrow> term"
104 (Eval "HOLogic.mk'_number/ HOLogic.intT")