src/HOL/Library/Code_Integer.thy
author haftmann
Tue Jan 15 16:19:23 2008 +0100 (2008-01-15)
changeset 25919 8b1c0d434824
parent 25767 852bce03412a
child 25928 042e877d9841
permissions -rw-r--r--
joined theories IntDef, Numeral, IntArith to theory Int
haftmann@24999
     1
(*  Title:      HOL/Library/Code_Integer.thy
haftmann@24999
     2
    ID:         $Id$
haftmann@24999
     3
    Author:     Florian Haftmann, TU Muenchen
haftmann@24999
     4
*)
haftmann@24999
     5
haftmann@24999
     6
header {* Pretty integer literals for code generation *}
haftmann@24999
     7
haftmann@24999
     8
theory Code_Integer
haftmann@25919
     9
imports Int
haftmann@24999
    10
begin
haftmann@24999
    11
haftmann@24999
    12
text {*
haftmann@24999
    13
  HOL numeral expressions are mapped to integer literals
haftmann@24999
    14
  in target languages, using predefined target language
haftmann@24999
    15
  operations for abstract integer operations.
haftmann@24999
    16
*}
haftmann@24999
    17
haftmann@24999
    18
code_type int
haftmann@24999
    19
  (SML "IntInf.int")
haftmann@24999
    20
  (OCaml "Big'_int.big'_int")
haftmann@24999
    21
  (Haskell "Integer")
haftmann@24999
    22
haftmann@24999
    23
code_instance int :: eq
haftmann@24999
    24
  (Haskell -)
haftmann@24999
    25
haftmann@24999
    26
setup {*
haftmann@24999
    27
  fold (fn target => CodeTarget.add_pretty_numeral target true
haftmann@24999
    28
    @{const_name number_int_inst.number_of_int}
haftmann@25919
    29
    @{const_name Int.B0} @{const_name Int.B1}
haftmann@25919
    30
    @{const_name Int.Pls} @{const_name Int.Min}
haftmann@25919
    31
    @{const_name Int.Bit}
haftmann@24999
    32
  ) ["SML", "OCaml", "Haskell"]
haftmann@24999
    33
*}
haftmann@24999
    34
haftmann@25919
    35
code_const "Int.Pls" and "Int.Min" and "Int.Bit"
haftmann@24999
    36
  (SML "raise/ Fail/ \"Pls\""
haftmann@24999
    37
     and "raise/ Fail/ \"Min\""
haftmann@24999
    38
     and "!((_);/ (_);/ raise/ Fail/ \"Bit\")")
haftmann@24999
    39
  (OCaml "failwith/ \"Pls\""
haftmann@24999
    40
     and "failwith/ \"Min\""
haftmann@24999
    41
     and "!((_);/ (_);/ failwith/ \"Bit\")")
haftmann@24999
    42
  (Haskell "error/ \"Pls\""
haftmann@24999
    43
     and "error/ \"Min\""
haftmann@24999
    44
     and "error/ \"Bit\"")
haftmann@24999
    45
haftmann@25919
    46
code_const Int.pred
haftmann@24999
    47
  (SML "IntInf.- ((_), 1)")
haftmann@24999
    48
  (OCaml "Big'_int.pred'_big'_int")
haftmann@24999
    49
  (Haskell "!(_/ -/ 1)")
haftmann@24999
    50
haftmann@25919
    51
code_const Int.succ
haftmann@24999
    52
  (SML "IntInf.+ ((_), 1)")
haftmann@24999
    53
  (OCaml "Big'_int.succ'_big'_int")
haftmann@24999
    54
  (Haskell "!(_/ +/ 1)")
haftmann@24999
    55
haftmann@24999
    56
code_const "op + \<Colon> int \<Rightarrow> int \<Rightarrow> int"
haftmann@24999
    57
  (SML "IntInf.+ ((_), (_))")
haftmann@24999
    58
  (OCaml "Big'_int.add'_big'_int")
haftmann@24999
    59
  (Haskell infixl 6 "+")
haftmann@24999
    60
haftmann@24999
    61
code_const "uminus \<Colon> int \<Rightarrow> int"
haftmann@24999
    62
  (SML "IntInf.~")
haftmann@24999
    63
  (OCaml "Big'_int.minus'_big'_int")
haftmann@24999
    64
  (Haskell "negate")
haftmann@24999
    65
haftmann@24999
    66
code_const "op - \<Colon> int \<Rightarrow> int \<Rightarrow> int"
haftmann@24999
    67
  (SML "IntInf.- ((_), (_))")
haftmann@24999
    68
  (OCaml "Big'_int.sub'_big'_int")
haftmann@24999
    69
  (Haskell infixl 6 "-")
haftmann@24999
    70
haftmann@24999
    71
code_const "op * \<Colon> int \<Rightarrow> int \<Rightarrow> int"
haftmann@24999
    72
  (SML "IntInf.* ((_), (_))")
haftmann@24999
    73
  (OCaml "Big'_int.mult'_big'_int")
haftmann@24999
    74
  (Haskell infixl 7 "*")
haftmann@24999
    75
haftmann@24999
    76
code_const "op = \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
haftmann@24999
    77
  (SML "!((_ : IntInf.int) = _)")
haftmann@24999
    78
  (OCaml "Big'_int.eq'_big'_int")
haftmann@24999
    79
  (Haskell infixl 4 "==")
haftmann@24999
    80
haftmann@24999
    81
code_const "op \<le> \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
haftmann@24999
    82
  (SML "IntInf.<= ((_), (_))")
haftmann@24999
    83
  (OCaml "Big'_int.le'_big'_int")
haftmann@24999
    84
  (Haskell infix 4 "<=")
haftmann@24999
    85
haftmann@24999
    86
code_const "op < \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
haftmann@24999
    87
  (SML "IntInf.< ((_), (_))")
haftmann@24999
    88
  (OCaml "Big'_int.lt'_big'_int")
haftmann@24999
    89
  (Haskell infix 4 "<")
haftmann@24999
    90
haftmann@24999
    91
code_reserved SML IntInf
haftmann@24999
    92
code_reserved OCaml Big_int
haftmann@24999
    93
haftmann@24999
    94
end