src/Tools/Metis/src/PortableMlton.sml
changeset 23442 028e39e5e8f3
child 23510 4521fead5609
equal deleted inserted replaced
23441:ee218296d635 23442:028e39e5e8f3
       
     1 (* ========================================================================= *)
       
     2 (* MLTON SPECIFIC FUNCTIONS                                                  *)
       
     3 (* Copyright (c) 2002-2006 Joe Hurd, distributed under the GNU GPL version 2 *)
       
     4 (* ========================================================================= *)
       
     5 
       
     6 structure Portable :> Portable =
       
     7 struct
       
     8 
       
     9 (* ------------------------------------------------------------------------- *)
       
    10 (* The ML implementation.                                                    *)
       
    11 (* ------------------------------------------------------------------------- *)
       
    12 
       
    13 val ml = "mlton";
       
    14 
       
    15 (* ------------------------------------------------------------------------- *)
       
    16 (* Pointer equality using the run-time system.                               *)
       
    17 (* ------------------------------------------------------------------------- *)
       
    18 
       
    19 val pointerEqual = MLton.eq;
       
    20 
       
    21 (* ------------------------------------------------------------------------- *)
       
    22 (* Timing function applications a la Mosml.time.                             *)
       
    23 (* ------------------------------------------------------------------------- *)
       
    24 
       
    25 fun time f x =
       
    26     let
       
    27       fun p t =
       
    28           let
       
    29             val s = Time.fmt 3 t
       
    30           in
       
    31             case size (List.last (String.fields (fn x => x = #".") s)) of
       
    32               3 => s
       
    33             | 2 => s ^ "0"
       
    34             | 1 => s ^ "00"
       
    35             | _ => raise Fail "Portable.time"
       
    36           end
       
    37 
       
    38       val c = Timer.startCPUTimer ()
       
    39 
       
    40       val r = Timer.startRealTimer ()
       
    41 
       
    42       fun pt () =
       
    43           let
       
    44             val {usr,sys} = Timer.checkCPUTimer c
       
    45             val real = Timer.checkRealTimer r
       
    46           in
       
    47             print
       
    48               ("User: " ^ p usr ^ "  System: " ^ p sys ^
       
    49                "  Real: " ^ p real ^ "\n")
       
    50           end
       
    51 
       
    52       val y = f x handle e => (pt (); raise e)
       
    53 
       
    54       val () = pt ()
       
    55     in
       
    56       y
       
    57     end;
       
    58 
       
    59 end
       
    60 
       
    61 (* ------------------------------------------------------------------------- *)
       
    62 (* Quotations a la Moscow ML.                                                *)
       
    63 (* ------------------------------------------------------------------------- *)
       
    64 
       
    65 datatype 'a frag = QUOTE of string | ANTIQUOTE of 'a;