SCM Repository
Annotation of /trunk/src/driver/main.sml
Parent Directory
|
Revision Log
Revision 93 - (view) (download)
1 : | jhr | 33 | (* main.sml |
2 : | * | ||
3 : | * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu) | ||
4 : | * All rights reserved. | ||
5 : | *) | ||
6 : | |||
7 : | structure Main : sig | ||
8 : | |||
9 : | val main : (string * string list) -> OS.Process.status | ||
10 : | |||
11 : | jhr | 35 | val test : string -> unit |
12 : | |||
13 : | jhr | 33 | end = struct |
14 : | |||
15 : | fun err s = TextIO.output (TextIO.stdErr, s) | ||
16 : | fun err1 c = TextIO.output1 (TextIO.stdErr, c) | ||
17 : | fun errnl s = (err s; err1 #"\n") | ||
18 : | |||
19 : | jhr | 35 | fun quitWithError () = raise Fail "error" |
20 : | jhr | 33 | |
21 : | (* check for errors and report them if there are any *) | ||
22 : | fun checkForErrors errStrm = ( | ||
23 : | Error.report (TextIO.stdErr, errStrm); | ||
24 : | if Error.anyErrors errStrm | ||
25 : | jhr | 35 | then quitWithError () |
26 : | jhr | 33 | else ()) |
27 : | |||
28 : | fun doFile filename = let | ||
29 : | val errStrm = Error.mkErrStream filename | ||
30 : | val inS = TextIO.openIn filename | ||
31 : | jhr | 86 | val checkTypes = Typechecker.check errStrm |
32 : | jhr | 33 | in |
33 : | case Parser.parseFile (errStrm, inS) | ||
34 : | jhr | 35 | of NONE => (checkForErrors errStrm; quitWithError ()) |
35 : | jhr | 93 | | SOME pt => let |
36 : | val _ = checkForErrors errStrm; | ||
37 : | val ast = (checkTypes pt) handle Typechecker.Error => AST.Program[] | ||
38 : | in | ||
39 : | checkForErrors errStrm; | ||
40 : | ASTPP.output (TextIO.stdOut, ast) (* DEBUG *) | ||
41 : | end | ||
42 : | jhr | 33 | (* end case *); |
43 : | TextIO.closeIn inS | ||
44 : | end | ||
45 : | |||
46 : | fun main (name: string, args: string list) = | ||
47 : | jhr | 35 | (List.app doFile args; OS.Process.success) |
48 : | jhr | 33 | handle exn => ( |
49 : | err (concat [ | ||
50 : | "uncaught exception ", General.exnName exn, " [", General.exnMessage exn, "]\n"]); | ||
51 : | List.app (fn s => err (concat [" raised at ", s, "\n"])) | ||
52 : | (SMLofNJ.exnHistory exn); | ||
53 : | jhr | 35 | quitWithError()) |
54 : | jhr | 33 | |
55 : | jhr | 35 | fun test file = (main ("", [file]); print "** Success!!\n") |
56 : | |||
57 : | jhr | 33 | end |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |