src/Pure/ML-Systems/mosml.ML
author wenzelm
Thu, 06 Jul 2000 00:09:45 +0200
changeset 9254 f8a0e8b9bcd8
child 12108 b6f10dcde803
permissions -rw-r--r--
Compatibility file for Moscow ML 2.00;
     1 (*  Title:      Pure/ML-Systems/mosml.ML
     2     ID:         $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   1999  University of Cambridge
     5 
     6 Compatibility file for Moscow ML 2.00
     7 
     8 NOTE: saving images does not work (yet!?), may run it interactively as follows:
     9 
    10 $ cd .../Pure
    11 $ isabelle RAW_ML_SYSTEM
    12 > val ml_system = "mosml";
    13 > use "ML-Systems/mosml.ML";
    14 > use "ROOT.ML";
    15 *)
    16 
    17 (** ML system related **)
    18 
    19 
    20 (* Poly/ML emulation *)
    21 
    22 load "Bool";
    23 load "Int";
    24 load "Real";
    25 load "ListPair";
    26 
    27 load "OS";
    28 load "Process";
    29 load "FileSys";
    30 
    31 structure OS =
    32   struct
    33   open OS
    34   structure Process = Process
    35   structure FileSys = FileSys
    36   end;
    37  
    38 (*To exit the system with an exit code -- an alternative to ^D *)
    39 fun exit 0 = Process.exit Process.success
    40   | exit _ = Process.exit Process.failure;
    41 
    42 (*limit the printing depth*)
    43 fun print_depth n =
    44  (Meta.printDepth := n div 2;
    45   Meta.printLength := n);
    46 
    47 (*interface for toplevel pretty printers, see also Pure/install_pp.ML*)
    48 (*the documentation refers to an installPP but I couldn't fine it!*)
    49 fun make_pp path pprint = ();
    50 fun install_pp _ = ();
    51 
    52 (*prompts*)
    53 (*n.a.??*)
    54 fun ml_prompts p1 p2 = ();
    55 
    56 
    57 (** Compiler-independent timing functions **)
    58 
    59 load "Timer";
    60 
    61 (*Note start point for timing*)
    62 fun startTiming() = 
    63   let val CPUtimer = Timer.startCPUTimer();
    64       val time = Timer.checkCPUTimer(CPUtimer)
    65   in  (CPUtimer,time)  end;
    66 
    67 (*Finish timing and return string*)
    68 fun endTiming (CPUtimer, {gc,sys,usr}) =
    69   let open Time  (*...for Time.toString, Time.+ and Time.- *)
    70       val {gc=gc2,sys=sys2,usr=usr2} = Timer.checkCPUTimer(CPUtimer)
    71   in  "User " ^ toString (usr2-usr) ^
    72       "  GC " ^ toString (gc2-gc) ^
    73       "  All "^ toString (sys2-sys + usr2-usr + gc2-gc) ^
    74       " secs"
    75       handle Time => ""
    76   end;
    77 
    78 
    79 (* ML command execution *)
    80 
    81 (*Can one redirect 'use' directly to an instream?*)
    82 fun use_text _ _ txt =
    83   let
    84     val tmp_name = FileSys.tmpName ();
    85     val tmp_file = TextIO.openOut tmp_name;
    86   in
    87     TextIO.output (tmp_file, txt);
    88     TextIO.closeOut tmp_file;
    89     use tmp_name;
    90     FileSys.remove tmp_name
    91   end;
    92 
    93 
    94 
    95 (** interrupts **)	(*Note: may get into race conditions*)
    96 
    97 (* FIXME proper implementation available? *)
    98 
    99 exception Interrupt;
   100 
   101 fun mask_interrupt f x = f x;           
   102 fun unmask_interrupt f x = f x;
   103 fun exhibit_interrupt f x = f x;
   104 
   105 
   106 
   107 (** OS related **)
   108 
   109 (* system command execution *)
   110 
   111 (*execute Unix command which doesn't take any input from stdin and
   112   sends its output to stdout; could be done more easily by Unix.execute,
   113   but that function doesn't use the PATH*)
   114 fun execute command =
   115   let
   116     val tmp_name = FileSys.tmpName ();
   117     val is = (Process.system (command ^ " > " ^ tmp_name); TextIO.openIn 
   118 tmp_name);
   119     val result = TextIO.inputAll is;
   120   in
   121     TextIO.closeIn is;
   122     FileSys.remove tmp_name;
   123     result
   124   end;
   125 
   126 (*plain version; with return code*)
   127 fun system cmd =
   128   if Process.system cmd = Process.success then 0 else 1;
   129 
   130 
   131 (* file handling *)
   132 
   133 (*get time of last modification*)
   134 fun file_info name = Time.toString (FileSys.modTime name) handle _ => "";
   135 
   136 
   137 (* getenv *)
   138 
   139 fun getenv var =
   140   (case Process.getEnv var of
   141     NONE => ""
   142   | SOME txt => txt);
   143 
   144 
   145 (* non-ASCII input (see also Thy/use.ML) *)
   146 
   147 val needs_filtered_use = false;