src/HOL/Library/Code_Integer.thy
changeset 24999 1dbe785ed529
child 25767 852bce03412a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/HOL/Library/Code_Integer.thy	Fri Oct 12 10:26:18 2007 +0200
     1.3 @@ -0,0 +1,99 @@
     1.4 +(*  Title:      HOL/Library/Code_Integer.thy
     1.5 +    ID:         $Id$
     1.6 +    Author:     Florian Haftmann, TU Muenchen
     1.7 +*)
     1.8 +
     1.9 +header {* Pretty integer literals for code generation *}
    1.10 +
    1.11 +theory Code_Integer
    1.12 +imports IntArith Code_Index
    1.13 +begin
    1.14 +
    1.15 +text {*
    1.16 +  HOL numeral expressions are mapped to integer literals
    1.17 +  in target languages, using predefined target language
    1.18 +  operations for abstract integer operations.
    1.19 +*}
    1.20 +
    1.21 +code_type int
    1.22 +  (SML "IntInf.int")
    1.23 +  (OCaml "Big'_int.big'_int")
    1.24 +  (Haskell "Integer")
    1.25 +
    1.26 +code_instance int :: eq
    1.27 +  (Haskell -)
    1.28 +
    1.29 +setup {*
    1.30 +  fold (fn target => CodeTarget.add_pretty_numeral target true
    1.31 +    @{const_name number_int_inst.number_of_int}
    1.32 +    @{const_name Numeral.B0} @{const_name Numeral.B1}
    1.33 +    @{const_name Numeral.Pls} @{const_name Numeral.Min}
    1.34 +    @{const_name Numeral.Bit}
    1.35 +  ) ["SML", "OCaml", "Haskell"]
    1.36 +*}
    1.37 +
    1.38 +code_const "Numeral.Pls" and "Numeral.Min" and "Numeral.Bit"
    1.39 +  (SML "raise/ Fail/ \"Pls\""
    1.40 +     and "raise/ Fail/ \"Min\""
    1.41 +     and "!((_);/ (_);/ raise/ Fail/ \"Bit\")")
    1.42 +  (OCaml "failwith/ \"Pls\""
    1.43 +     and "failwith/ \"Min\""
    1.44 +     and "!((_);/ (_);/ failwith/ \"Bit\")")
    1.45 +  (Haskell "error/ \"Pls\""
    1.46 +     and "error/ \"Min\""
    1.47 +     and "error/ \"Bit\"")
    1.48 +
    1.49 +code_const Numeral.pred
    1.50 +  (SML "IntInf.- ((_), 1)")
    1.51 +  (OCaml "Big'_int.pred'_big'_int")
    1.52 +  (Haskell "!(_/ -/ 1)")
    1.53 +
    1.54 +code_const Numeral.succ
    1.55 +  (SML "IntInf.+ ((_), 1)")
    1.56 +  (OCaml "Big'_int.succ'_big'_int")
    1.57 +  (Haskell "!(_/ +/ 1)")
    1.58 +
    1.59 +code_const "op + \<Colon> int \<Rightarrow> int \<Rightarrow> int"
    1.60 +  (SML "IntInf.+ ((_), (_))")
    1.61 +  (OCaml "Big'_int.add'_big'_int")
    1.62 +  (Haskell infixl 6 "+")
    1.63 +
    1.64 +code_const "uminus \<Colon> int \<Rightarrow> int"
    1.65 +  (SML "IntInf.~")
    1.66 +  (OCaml "Big'_int.minus'_big'_int")
    1.67 +  (Haskell "negate")
    1.68 +
    1.69 +code_const "op - \<Colon> int \<Rightarrow> int \<Rightarrow> int"
    1.70 +  (SML "IntInf.- ((_), (_))")
    1.71 +  (OCaml "Big'_int.sub'_big'_int")
    1.72 +  (Haskell infixl 6 "-")
    1.73 +
    1.74 +code_const "op * \<Colon> int \<Rightarrow> int \<Rightarrow> int"
    1.75 +  (SML "IntInf.* ((_), (_))")
    1.76 +  (OCaml "Big'_int.mult'_big'_int")
    1.77 +  (Haskell infixl 7 "*")
    1.78 +
    1.79 +code_const "op = \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
    1.80 +  (SML "!((_ : IntInf.int) = _)")
    1.81 +  (OCaml "Big'_int.eq'_big'_int")
    1.82 +  (Haskell infixl 4 "==")
    1.83 +
    1.84 +code_const "op \<le> \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
    1.85 +  (SML "IntInf.<= ((_), (_))")
    1.86 +  (OCaml "Big'_int.le'_big'_int")
    1.87 +  (Haskell infix 4 "<=")
    1.88 +
    1.89 +code_const "op < \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
    1.90 +  (SML "IntInf.< ((_), (_))")
    1.91 +  (OCaml "Big'_int.lt'_big'_int")
    1.92 +  (Haskell infix 4 "<")
    1.93 +
    1.94 +code_const index_of_int and int_of_index
    1.95 +  (SML "IntInf.toInt" and "IntInf.fromInt")
    1.96 +  (OCaml "Big'_int.int'_of'_big'_int" and "Big'_int.big'_int'_of'_int")
    1.97 +  (Haskell "_" and "_")
    1.98 +
    1.99 +code_reserved SML IntInf
   1.100 +code_reserved OCaml Big_int
   1.101 +
   1.102 +end
   1.103 \ No newline at end of file