11 |
11 |
12 (*To exit the system with an exit code -- an alternative to ^D *) |
12 (*To exit the system with an exit code -- an alternative to ^D *) |
13 fun exit 0 = OS.Process.exit OS.Process.success |
13 fun exit 0 = OS.Process.exit OS.Process.success |
14 | exit _ = OS.Process.exit OS.Process.failure; |
14 | exit _ = OS.Process.exit OS.Process.failure; |
15 fun quit () = exit 0; |
15 fun quit () = exit 0; |
16 |
|
17 structure Int = Integer; |
|
18 |
|
19 (*To change the current directory*) |
|
20 val cd = OS.FileSys.chDir; |
|
21 |
16 |
22 (*To limit the printing depth [divided by 2 for comparibility with Poly/ML]*) |
17 (*To limit the printing depth [divided by 2 for comparibility with Poly/ML]*) |
23 fun print_depth n = (Compiler.Control.Print.printDepth := n div 2; |
18 fun print_depth n = (Compiler.Control.Print.printDepth := n div 2; |
24 Compiler.Control.Print.printLength := n); |
19 Compiler.Control.Print.printLength := n); |
25 |
20 |
49 val _ = (Compiler.Control.Print.printLength := 1000; |
44 val _ = (Compiler.Control.Print.printLength := 1000; |
50 Compiler.Control.Print.printDepth := 350; |
45 Compiler.Control.Print.printDepth := 350; |
51 Compiler.Control.Print.stringDepth := 250; |
46 Compiler.Control.Print.stringDepth := 250; |
52 Compiler.Control.Print.signatures := 2); |
47 Compiler.Control.Print.signatures := 2); |
53 |
48 |
54 (*** Character/string functions which are compatibel with 0.93 and Poly/ML ***) |
49 (*** Character/string functions which are compatible with 0.93 and Poly/ML ***) |
55 |
50 |
56 val ord = Char.ord o hd o explode; |
51 fun ord s = Char.ord (String.sub(s,0)); |
57 val chr = str o Char.chr; |
52 val chr = str o Char.chr; |
58 val explode = (map str) o String.explode; |
53 val explode = (map str) o String.explode; |
59 val implode = String.concat; |
54 val implode = String.concat; |
60 |
55 |
61 |
56 |
81 |
76 |
82 |
77 |
83 (*** File handling ***) |
78 (*** File handling ***) |
84 |
79 |
85 (*Get time of last modification; if file doesn't exist return an empty string*) |
80 (*Get time of last modification; if file doesn't exist return an empty string*) |
86 local |
81 fun file_info "" = "" |
87 open Timer; |
82 | file_info name = Time.toString |
88 open Posix.FileSys; |
83 (Posix.FileSys.ST.mtime (Posix.FileSys.stat name)) |
89 in |
84 handle _ => ""; |
90 fun file_info "" = "" |
|
91 | file_info name = Time.toString (ST.mtime (stat name)) handle _ => ""; |
|
92 |
85 |
93 val delete_file = unlink; |
|
94 end; |
|
95 |
|
96 (*Get pathname of current working directory *) |
|
97 fun pwd () = OS.FileSys.getDir (); |
|
98 |
86 |
99 |
87 |
100 (*** ML command execution ***) |
88 (*** ML command execution ***) |
101 |
89 |
102 fun use_string commands = |
90 fun use_string commands = |
103 Compiler.Interact.use_stream (open_string (implode commands)); |
91 Compiler.Interact.use_stream (open_string (implode commands)); |
104 |
92 |
|
93 (*For later versions of Standard ML of New Jersey use... |
|
94 val use_string = Compiler.Interact.useStream o TextIO.openString o implode; |
|
95 *) |
105 |
96 |
106 (*** System command execution ***) |
97 (*** System command execution ***) |
107 |
98 |
108 (*Execute an Unix command which doesn't take any input from stdin and |
99 (*Execute an Unix command which doesn't take any input from stdin and |
109 sends its output to stdout. |
100 sends its output to stdout. |
110 This could be done more easily by Unix.execute, but that function |
101 This could be done more easily by Unix.execute, but that function |
111 doesn't use the PATH.*) |
102 doesn't use the PATH.*) |
112 fun execute command = |
103 fun execute command = |
113 let val tmp_name = "isa_converted.tmp" |
104 let val tmp_name = "isa_converted.tmp" |
114 val is = (OS.Process.system (command ^ " > " ^ tmp_name); |
105 val is = (OS.Process.system (command ^ " > " ^ tmp_name); |
115 open_in tmp_name); |
106 TextIO.openIn tmp_name); |
116 val result = input (is, 999999); |
107 val result = TextIO.inputAll is; |
117 in close_in is; |
108 in TextIO.closeIn is; |
118 delete_file tmp_name; |
109 OS.FileSys.remove tmp_name; |
119 result |
110 result |
120 end; |
111 end; |
121 |
112 |
122 |
113 (*For exporting images. The short name saves space in Makefiles*) |
123 (*For use in Makefiles -- saves space*) |
|
124 fun xML filename banner = |
114 fun xML filename banner = |
125 let val runtime = List.hd (SMLofNJ.getAllArgs()) |
115 let open SMLofNJ |
126 val exec_file = IO.open_out filename |
116 val runtime = hd (SMLofNJ.getAllArgs()) |
127 |
117 and exec_file = TextIO.openOut filename |
128 val _ = IO.output (exec_file, |
118 in |
129 String.concat |
119 TextIO.output (*Write a shell script to invoke the actual image*) |
130 ["#!/bin/sh\n", |
120 (exec_file, |
131 runtime, " @SMLdebug=/dev/null @SMLload=", filename, |
121 String.concat |
132 ".heap\n"]) |
122 ["#!/bin/sh\n", runtime, |
133 (*"@SMLdebug=..." sends GC messages to /dev/null*) |
123 " @SMLdebug=/dev/null", (*suppresses GC messages*) |
134 |
124 " @SMLload=", filename, ".heap\n"]); |
135 val _ = IO.close_out exec_file; |
125 TextIO.closeOut exec_file; |
136 val _ = OS.Process.system ("chmod a+x " ^ filename) |
126 OS.Process.system ("chmod a+x " ^ filename); |
137 in exportML (filename^".heap"); |
127 exportML (filename^".heap"); |
138 print(banner^"\n") |
128 print(banner^"\n") |
139 end; |
129 end; |