src/Pure/NJ.ML
author wenzelm
Tue Aug 23 19:31:05 1994 +0200 (1994-08-23)
changeset 573 2fa5ef27bd0a
parent 396 18c9c28d0f7e
child 907 61fcac0e50fc
permissions -rw-r--r--
removed constant _constrain from Pure sig;
     1 (*  Title:      Pure/NJ
     2     ID:         $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   1993  University of Cambridge
     5 
     6 Compatibility file for Standard ML of New Jersey.
     7 *)
     8 
     9 (*** Poly/ML emulation ***)
    10 
    11 (*To exit the system -- an alternative to ^D *)
    12 fun quit () = System.Unsafe.CInterface.exit 0;
    13 
    14 (*To change the current directory*)
    15 val cd = System.Directory.cd;
    16 
    17 (*To limit the printing depth [divided by 2 for comparibility with Poly/ML]*)
    18 fun print_depth n = (System.Control.Print.printDepth := n div 2;
    19                      System.Control.Print.printLength := n);
    20 
    21 
    22 (*Interface for toplevel pretty printers, see also Pure/install_pp.ML*)
    23 
    24 fun make_pp path pprint =
    25   let
    26     open System.PrettyPrint;
    27 
    28     fun pp pps obj =
    29       pprint obj
    30         (add_string pps, begin_block pps INCONSISTENT,
    31           fn wd => add_break pps (wd, 0), fn () => add_newline pps,
    32           fn () => end_block pps);
    33   in
    34     (path, pp)
    35   end;
    36 
    37 fun install_pp (path, pp) = System.PrettyPrint.install_pp path pp;
    38 
    39 
    40 (*** New Jersey ML parameters ***)
    41 
    42 (* Suppresses Garbage Collection messages;  default was 2 *)
    43 System.Control.Runtime.gcmessages := 0;
    44 
    45 (*redefine to flush its output immediately -- temporary patch suggested
    46   by Kim Dam Petersen*)
    47 val output = fn(s, t) => (output(s, t); flush_out s);
    48 
    49 (*Dummy version of the Poly/ML function*)
    50 fun commit() = ();
    51 
    52 (*For use in Makefiles -- saves space*)
    53 fun xML filename banner = (exportML filename;  print(banner^"\n"));
    54 
    55 (*** Timing functions ***)
    56 
    57 (*Print microseconds, suppressing trailing zeroes*)
    58 fun umakestring 0 = ""
    59   | umakestring n = chr(ord"0" + n div 100000) ^
    60                     umakestring(10 * (n mod 100000));
    61 
    62 (*A conditional timing function: applies f to () and, if the flag is true,
    63   prints its runtime. *)
    64 fun cond_timeit flag f =
    65   if flag then
    66     let fun string_of_time (System.Timer.TIME {sec, usec}) =
    67             makestring sec ^ "." ^ (if usec=0 then "0" else umakestring usec)
    68         open System.Timer;
    69         val start = start_timer()
    70         val result = f();
    71         val nongc = check_timer(start)
    72         and gc = check_timer_gc(start);
    73         val both = add_time(nongc, gc)
    74     in  print("Non GC " ^ string_of_time nongc ^
    75                "   GC " ^ string_of_time gc ^
    76                "  both "^ string_of_time both ^ " secs\n");
    77         result
    78     end
    79   else f();
    80 
    81 
    82 (*** File handling ***)
    83 
    84 (*Get time of last modification.*)
    85 local
    86     open System.Timer;
    87     open System.Unsafe.SysIO;
    88 in
    89   fun file_info "" = ""
    90     | file_info name = makestring (mtime (PATH name));
    91 
    92   val delete_file = unlink;
    93 end;
    94 
    95 (*Get pathname of current working directory *)
    96 fun pwd () = System.Directory.getWD ();
    97 
    98 
    99 (*** ML command execution ***)
   100 
   101 fun use_string commands = 
   102   System.Compile.use_stream (open_string (implode commands));
   103