src/Tools/Metis/src/PortablePolyml.sml
author wenzelm
Sat, 09 Jul 2011 21:53:27 +0200
changeset 43721 fad8634cee62
parent 39502 cffceed8e7fa
child 72004 913162a47d9f
permissions -rw-r--r--
echo prover input via raw_messages, for improved protocol tracing;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     1
(* ========================================================================= *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     2
(* POLY/ML SPECIFIC FUNCTIONS                                                *)
39502
cffceed8e7fa fix license
blanchet
parents: 39501
diff changeset
     3
(* Copyright (c) 2008 Joe Hurd, distributed under the BSD License            *)
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     4
(* ========================================================================= *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     5
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     6
structure Portable :> Portable =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     7
struct
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     8
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
     9
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    10
(* The ML implementation.                                                    *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    11
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    12
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    13
val ml = "polyml";
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    14
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    15
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    16
(* Pointer equality using the run-time system.                               *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    17
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    18
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    19
fun pointerEqual (x : 'a, y : 'a) = PolyML.pointerEq(x,y);
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    20
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    21
(* ------------------------------------------------------------------------- *)
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39429
diff changeset
    22
(* Marking critical sections of code.                                        *)
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39429
diff changeset
    23
(* ------------------------------------------------------------------------- *)
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39429
diff changeset
    24
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39429
diff changeset
    25
fun critical f () = f ();
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39429
diff changeset
    26
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39429
diff changeset
    27
(* ------------------------------------------------------------------------- *)
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39429
diff changeset
    28
(* Generating random values.                                                 *)
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39429
diff changeset
    29
(* ------------------------------------------------------------------------- *)
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39429
diff changeset
    30
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39429
diff changeset
    31
val randomWord = Random.nextWord;
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39429
diff changeset
    32
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39429
diff changeset
    33
val randomBool = Random.nextBool;
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39429
diff changeset
    34
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39429
diff changeset
    35
val randomInt = Random.nextInt;
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39429
diff changeset
    36
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39429
diff changeset
    37
val randomReal = Random.nextReal;
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39429
diff changeset
    38
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39429
diff changeset
    39
(* ------------------------------------------------------------------------- *)
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    40
(* Timing function applications.                                             *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    41
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    42
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    43
fun time f x =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    44
    let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    45
      fun p t =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    46
          let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    47
            val s = Time.fmt 3 t
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    48
          in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    49
            case size (List.last (String.fields (fn x => x = #".") s)) of
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    50
              3 => s
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    51
            | 2 => s ^ "0"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    52
            | 1 => s ^ "00"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    53
            | _ => raise Fail "Portable.time"
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    54
          end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    55
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    56
      val c = Timer.startCPUTimer ()
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    57
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    58
      val r = Timer.startRealTimer ()
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    59
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    60
      fun pt () =
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    61
          let
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    62
            val {usr,sys} = Timer.checkCPUTimer c
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    63
            val real = Timer.checkRealTimer r
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    64
          in
39443
e330437cd22a copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents: 39429
diff changeset
    65
            print
39348
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    66
              ("User: " ^ p usr ^ "  System: " ^ p sys ^
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    67
               "  Real: " ^ p real ^ "\n")
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    68
          end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    69
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    70
      val y = f x handle e => (pt (); raise e)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    71
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    72
      val () = pt ()
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    73
    in
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    74
      y
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    75
    end;
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    76
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    77
end
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    78
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    79
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    80
(* Quotations a la Moscow ML.                                                *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    81
(* ------------------------------------------------------------------------- *)
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    82
6f9c9899f99f new version of the Metis files
blanchet
parents:
diff changeset
    83
datatype 'a frag = QUOTE of string | ANTIQUOTE of 'a;