src/HOL/Library/Pretty_Int.thy
author haftmann
Thu, 26 Apr 2007 13:32:59 +0200
changeset 22799 ed7d53db2170
parent 22767 125363bf7518
child 22803 5129e02f4df2
permissions -rw-r--r--
moved code generation pretty integers and characters to separate theories
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22767
125363bf7518 initial commit
haftmann
parents:
diff changeset
     1
(*  ID:         $Id$
125363bf7518 initial commit
haftmann
parents:
diff changeset
     2
    Author:     Florian Haftmann, TU Muenchen
125363bf7518 initial commit
haftmann
parents:
diff changeset
     3
*)
125363bf7518 initial commit
haftmann
parents:
diff changeset
     4
125363bf7518 initial commit
haftmann
parents:
diff changeset
     5
header {* Pretty integer literals for code generation *}
125363bf7518 initial commit
haftmann
parents:
diff changeset
     6
125363bf7518 initial commit
haftmann
parents:
diff changeset
     7
theory Pretty_Int
125363bf7518 initial commit
haftmann
parents:
diff changeset
     8
imports IntArith
125363bf7518 initial commit
haftmann
parents:
diff changeset
     9
begin
125363bf7518 initial commit
haftmann
parents:
diff changeset
    10
125363bf7518 initial commit
haftmann
parents:
diff changeset
    11
text {*
125363bf7518 initial commit
haftmann
parents:
diff changeset
    12
  HOL numeral expressions are mapped to integer literals
125363bf7518 initial commit
haftmann
parents:
diff changeset
    13
  in target languages, using predefined target language
125363bf7518 initial commit
haftmann
parents:
diff changeset
    14
  operations for abstract integer operations.
125363bf7518 initial commit
haftmann
parents:
diff changeset
    15
*}
125363bf7518 initial commit
haftmann
parents:
diff changeset
    16
125363bf7518 initial commit
haftmann
parents:
diff changeset
    17
code_type int
125363bf7518 initial commit
haftmann
parents:
diff changeset
    18
  (SML "IntInf.int")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    19
  (OCaml "Big'_int.big'_int")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    20
  (Haskell "Integer")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    21
125363bf7518 initial commit
haftmann
parents:
diff changeset
    22
setup {*
125363bf7518 initial commit
haftmann
parents:
diff changeset
    23
  fold (fn target => CodegenSerializer.add_pretty_numeral target
125363bf7518 initial commit
haftmann
parents:
diff changeset
    24
    (@{const_name number_of}, @{typ "int \<Rightarrow> int"})
125363bf7518 initial commit
haftmann
parents:
diff changeset
    25
    @{const_name Numeral.B0} @{const_name Numeral.B1}
125363bf7518 initial commit
haftmann
parents:
diff changeset
    26
    @{const_name Numeral.Pls} @{const_name Numeral.Min}
125363bf7518 initial commit
haftmann
parents:
diff changeset
    27
    @{const_name Numeral.Bit}
125363bf7518 initial commit
haftmann
parents:
diff changeset
    28
  ) ["SML", "OCaml", "Haskell"]
125363bf7518 initial commit
haftmann
parents:
diff changeset
    29
*}
125363bf7518 initial commit
haftmann
parents:
diff changeset
    30
125363bf7518 initial commit
haftmann
parents:
diff changeset
    31
code_const "Numeral.Pls" and "Numeral.Min" and "Numeral.Bit"
125363bf7518 initial commit
haftmann
parents:
diff changeset
    32
  (SML "raise/ Fail/ \"Pls\""
125363bf7518 initial commit
haftmann
parents:
diff changeset
    33
     and "raise/ Fail/ \"Min\""
125363bf7518 initial commit
haftmann
parents:
diff changeset
    34
     and "!((_);/ (_);/ raise/ Fail/ \"Bit\")")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    35
  (OCaml "failwith/ \"Pls\""
125363bf7518 initial commit
haftmann
parents:
diff changeset
    36
     and "failwith/ \"Min\""
125363bf7518 initial commit
haftmann
parents:
diff changeset
    37
     and "!((_);/ (_);/ failwith/ \"Bit\")")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    38
  (Haskell "error/ \"Pls\""
125363bf7518 initial commit
haftmann
parents:
diff changeset
    39
     and "error/ \"Min\""
125363bf7518 initial commit
haftmann
parents:
diff changeset
    40
     and "error/ \"Bit\"")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    41
125363bf7518 initial commit
haftmann
parents:
diff changeset
    42
code_const Numeral.pred
125363bf7518 initial commit
haftmann
parents:
diff changeset
    43
  (SML "IntInf.- ((_), 1)")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    44
  (OCaml "Big'_int.pred'_big'_int")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    45
  (Haskell "!(_/ -/ 1)")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    46
125363bf7518 initial commit
haftmann
parents:
diff changeset
    47
code_const Numeral.succ
125363bf7518 initial commit
haftmann
parents:
diff changeset
    48
  (SML "IntInf.+ ((_), 1)")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    49
  (OCaml "Big'_int.succ'_big'_int")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    50
  (Haskell "!(_/ +/ 1)")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    51
125363bf7518 initial commit
haftmann
parents:
diff changeset
    52
code_const "op + \<Colon> int \<Rightarrow> int \<Rightarrow> int"
125363bf7518 initial commit
haftmann
parents:
diff changeset
    53
  (SML "IntInf.+ ((_), (_))")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    54
  (OCaml "Big'_int.add'_big'_int")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    55
  (Haskell infixl 6 "+")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    56
125363bf7518 initial commit
haftmann
parents:
diff changeset
    57
code_const "uminus \<Colon> int \<Rightarrow> int"
125363bf7518 initial commit
haftmann
parents:
diff changeset
    58
  (SML "IntInf.~")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    59
  (OCaml "Big'_int.minus'_big'_int")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    60
  (Haskell "negate")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    61
125363bf7518 initial commit
haftmann
parents:
diff changeset
    62
code_const "op - \<Colon> int \<Rightarrow> int \<Rightarrow> int"
125363bf7518 initial commit
haftmann
parents:
diff changeset
    63
  (SML "IntInf.- ((_), (_))")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    64
  (OCaml "Big'_int.sub'_big'_int")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    65
  (Haskell infixl 6 "-")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    66
125363bf7518 initial commit
haftmann
parents:
diff changeset
    67
code_const "op * \<Colon> int \<Rightarrow> int \<Rightarrow> int"
125363bf7518 initial commit
haftmann
parents:
diff changeset
    68
  (SML "IntInf.* ((_), (_))")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    69
  (OCaml "Big'_int.mult'_big'_int")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    70
  (Haskell infixl 7 "*")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    71
125363bf7518 initial commit
haftmann
parents:
diff changeset
    72
code_const "op = \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
125363bf7518 initial commit
haftmann
parents:
diff changeset
    73
  (SML "!((_ : IntInf.int) = _)")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    74
  (OCaml "Big'_int.eq'_big'_int")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    75
  (Haskell infixl 4 "==")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    76
125363bf7518 initial commit
haftmann
parents:
diff changeset
    77
code_const "op \<le> \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
125363bf7518 initial commit
haftmann
parents:
diff changeset
    78
  (SML "IntInf.<= ((_), (_))")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    79
  (OCaml "Big'_int.le'_big'_int")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    80
  (Haskell infix 4 "<=")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    81
125363bf7518 initial commit
haftmann
parents:
diff changeset
    82
code_const "op < \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
125363bf7518 initial commit
haftmann
parents:
diff changeset
    83
  (SML "IntInf.< ((_), (_))")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    84
  (OCaml "Big'_int.lt'_big'_int")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    85
  (Haskell infix 4 "<")
125363bf7518 initial commit
haftmann
parents:
diff changeset
    86
125363bf7518 initial commit
haftmann
parents:
diff changeset
    87
code_reserved SML IntInf
125363bf7518 initial commit
haftmann
parents:
diff changeset
    88
code_reserved OCaml Big_int
125363bf7518 initial commit
haftmann
parents:
diff changeset
    89
125363bf7518 initial commit
haftmann
parents:
diff changeset
    90
end