Commit | Line | Data |
---|---|---|
234b917a AC |
1 | (* HCoop Domtool (http://hcoop.sourceforge.net/) |
2 | * Copyright (c) 2006, Adam Chlipala | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the GNU General Public License | |
6 | * as published by the Free Software Foundation; either version 2 | |
7 | * of the License, or (at your option) any later version. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License | |
15 | * along with this program; if not, write to the Free Software | |
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
dac62e84 | 17 | *) |
234b917a AC |
18 | |
19 | (* Main interface *) | |
20 | ||
21 | structure Main :> MAIN = struct | |
22 | ||
492c1cff | 23 | open Ast Print |
234b917a AC |
24 | |
25 | val dmy = ErrorMsg.dummyLoc | |
26 | ||
27 | val tInit = (TAction ((CRoot, dmy), | |
28 | StringMap.empty, | |
29 | StringMap.empty), | |
30 | dmy) | |
d189ec0e AC |
31 | |
32 | ||
234b917a | 33 | |
d189ec0e | 34 | fun check' G fname = |
a3698041 | 35 | let |
d189ec0e | 36 | (*val _ = print ("Check " ^ fname ^ "\n")*) |
a3698041 AC |
37 | val prog = Parse.parse fname |
38 | in | |
39 | if !ErrorMsg.anyErrors then | |
d189ec0e | 40 | G |
a3698041 | 41 | else |
d189ec0e | 42 | Tycheck.checkFile G tInit prog |
a3698041 AC |
43 | end |
44 | ||
d189ec0e | 45 | fun basis () = |
234b917a | 46 | let |
d189ec0e AC |
47 | val dir = Posix.FileSys.opendir Config.libRoot |
48 | ||
49 | fun loop files = | |
50 | case Posix.FileSys.readdir dir of | |
d612d62c AC |
51 | NONE => (Posix.FileSys.closedir dir; |
52 | files) | |
d189ec0e AC |
53 | | SOME fname => |
54 | if String.isSuffix ".dtl" fname then | |
d612d62c AC |
55 | loop (OS.Path.joinDirFile {dir = Config.libRoot, |
56 | file = fname} | |
d189ec0e AC |
57 | :: files) |
58 | else | |
59 | loop files | |
60 | ||
61 | val files = loop [] | |
62 | val files = Order.order files | |
63 | in | |
64 | foldl (fn (fname, G) => check' G fname) Env.empty files | |
65 | end | |
66 | ||
67 | fun check fname = | |
68 | let | |
69 | val _ = ErrorMsg.reset () | |
70 | ||
71 | val b = basis () | |
234b917a AC |
72 | in |
73 | if !ErrorMsg.anyErrors then | |
d189ec0e | 74 | (b, NONE) |
234b917a AC |
75 | else |
76 | let | |
d189ec0e | 77 | val prog = Parse.parse fname |
234b917a | 78 | in |
492c1cff | 79 | if !ErrorMsg.anyErrors then |
d189ec0e | 80 | (Env.empty, NONE) |
492c1cff | 81 | else |
d189ec0e AC |
82 | let |
83 | val G' = Tycheck.checkFile b tInit prog | |
84 | in | |
85 | (G', #3 prog) | |
86 | end | |
234b917a AC |
87 | end |
88 | end | |
89 | ||
d189ec0e | 90 | fun reduce fname = |
a3698041 | 91 | let |
d189ec0e | 92 | val (G, body) = check fname |
a3698041 AC |
93 | in |
94 | if !ErrorMsg.anyErrors then | |
d189ec0e | 95 | NONE |
a3698041 | 96 | else |
d189ec0e AC |
97 | case body of |
98 | SOME body => | |
99 | let | |
100 | val body' = Reduce.reduceExp G body | |
101 | in | |
102 | (*printd (PD.hovBox (PD.PPS.Rel 0, | |
103 | [PD.string "Result:", | |
104 | PD.space 1, | |
105 | p_exp body']))*) | |
106 | SOME body' | |
107 | end | |
108 | | _ => NONE | |
a3698041 AC |
109 | end |
110 | ||
d189ec0e AC |
111 | fun eval fname = |
112 | case reduce fname of | |
113 | (SOME body') => | |
114 | if !ErrorMsg.anyErrors then | |
115 | () | |
116 | else | |
117 | Eval.exec StringMap.empty body' | |
118 | | NONE => () | |
119 | ||
234b917a | 120 | end |