1 (* Title: Pure/NJ1xx.ML
3 Author: Carsten Clasohm, TU Muenchen
4 Copyright 1996 TU Muenchen
6 Compatibility file for Standard ML of New Jersey version 1.xx.
9 (*** Poly/ML emulation ***)
12 (*To exit the system with an exit code -- an alternative to ^D *)
13 fun exit 0 = OS.Process.exit OS.Process.success
14 | exit _ = OS.Process.exit OS.Process.failure;
17 (*To limit the printing depth [divided by 2 for comparibility with Poly/ML]*)
18 fun print_depth n = (Compiler.Control.Print.printDepth := n div 2;
19 Compiler.Control.Print.printLength := n);
21 (*Interface for toplevel pretty printers, see also Pure/install_pp.ML*)
23 fun make_pp path pprint =
25 open Compiler.PrettyPrint;
29 (add_string pps, begin_block pps INCONSISTENT,
30 fn wd => add_break pps (wd, 0), fn () => add_newline pps,
31 fn () => end_block pps);
36 fun install_pp (path, pp) = Compiler.PPTable.install_pp path pp;
39 (*** New Jersey ML parameters ***)
41 (* Suppresses Garbage Collection messages; doesn't work yet *)
42 (*System.Runtime.gc 0;*)
44 val _ = (Compiler.Control.Print.printLength := 1000;
45 Compiler.Control.Print.printDepth := 350;
46 Compiler.Control.Print.stringDepth := 250;
47 Compiler.Control.Print.signatures := 2);
49 (*** Character/string functions which are compatible with 0.93 and Poly/ML ***)
51 fun ord s = Char.ord (String.sub(s,0));
52 val chr = str o Char.chr;
53 val explode = (map str) o String.explode;
54 val implode = String.concat;
57 (*** Timing functions ***)
59 (*A conditional timing function: applies f to () and, if the flag is true,
60 prints its runtime. *)
61 fun cond_timeit flag f =
63 let open Time (*...for Time.toString, Time.+ and Time.- *)
64 val CPUtimer = Timer.startCPUTimer();
65 val {gc=gct1,sys=syst1,usr=usrt1} = Timer.checkCPUTimer(CPUtimer);
67 val {gc=gct2,sys=syst2,usr=usrt2} = Timer.checkCPUTimer(CPUtimer)
68 in print("User " ^ toString (usrt2-usrt1) ^
69 " GC " ^ toString (gct2-gct1) ^
70 " All "^ toString (syst2-syst1 + usrt2-usrt1 + gct2-gct1) ^
78 (*** File handling ***)
80 (*Get time of last modification; if file doesn't exist return an empty string*)
82 | file_info name = Time.toString (OS.FileSys.modTime name) handle _ =>"";
86 (*** ML command execution ***)
89 (*For version 109.21 and later:*)
90 val use_string = Compiler.Interact.useStream o TextIO.openString o implode;
92 (*For versions prior to 109.21:*****
93 fun use_string commands =
94 Compiler.Interact.use_stream (open_string (implode commands));
97 (*** System command execution ***)
99 (*Execute an Unix command which doesn't take any input from stdin and
100 sends its output to stdout.
101 This could be done more easily by Unix.execute, but that function
102 doesn't use the PATH.*)
103 fun execute command =
104 let val tmp_name = "isa_converted.tmp"
105 val is = (OS.Process.system (command ^ " > " ^ tmp_name);
106 TextIO.openIn tmp_name);
107 val result = TextIO.inputAll is;
108 in TextIO.closeIn is;
109 OS.FileSys.remove tmp_name;
113 (*For exporting images. The short name saves space in Makefiles*)
114 fun xML filename banner =
116 val runtime = hd (SMLofNJ.getAllArgs())
117 and exec_file = TextIO.openOut filename
119 TextIO.output (*Write a shell script to invoke the actual image*)
122 ["#!/bin/sh\n", runtime,
123 " @SMLdebug=/dev/null", (*suppresses GC messages*)
124 " @SMLload=", filename, ".heap\n"]);
125 TextIO.closeOut exec_file;
126 OS.Process.system ("chmod a+x " ^ filename);
127 exportML (filename^".heap");
132 val needs_filtered_use = false;