1 | // |
---|
2 | // Copyright (C) 1999, 2000 Refal+ Development Group |
---|
3 | // |
---|
4 | // Refal+ is free software; you can redistribute it and/or modify |
---|
5 | // it under the terms of the GNU General Public License as published by |
---|
6 | // the Free Software Foundation; either version 2 of the License, or |
---|
7 | // (at your option) any later version. |
---|
8 | // |
---|
9 | // Refal+ 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 Refal+; if not, write to the Free Software |
---|
16 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | // |
---|
18 | // $Source$ |
---|
19 | // $Revision: 1825 $ |
---|
20 | // $Date: 2005-12-29 01:57:15 +0000 (Thu, 29 Dec 2005) $ |
---|
21 | |
---|
22 | // rfpc.rfi |
---|
23 | $use "rfp_src"; // rfp_src.rfi |
---|
24 | $use "rfp_err"; // rfp_err.rfi |
---|
25 | $use "rfp_lex"; // rfp_lex.rfi |
---|
26 | $use "rfp_parse"; // rfp_parse.rfi |
---|
27 | $use "rfp_debug"; // rfp_debug.rfi |
---|
28 | $use "rfp_compile"; // rfp_compile.rfi |
---|
29 | $use "rfp_asail_cpp"; //rfp_asail_cpp.rfi |
---|
30 | $use "rfp_asail_java"; //rfp_asail_java.rfi |
---|
31 | $use "rfp_as2as"; |
---|
32 | $use "rfp_check"; |
---|
33 | $use "rfp_helper"; |
---|
34 | $use "rfp_format"; |
---|
35 | $use "rfp_asail_optim"; //rfp_asail_optim.rfi |
---|
36 | |
---|
37 | $use StdIO; |
---|
38 | $use Box; |
---|
39 | $use Dos; |
---|
40 | $use Arithm; |
---|
41 | $use Table; |
---|
42 | $use Convert; |
---|
43 | $use Class; |
---|
44 | $use Access; |
---|
45 | $use Compare; |
---|
46 | $use CppMangle; |
---|
47 | |
---|
48 | $const RevDate = ('$Revision: 1825 $') ('$Date: 2005-12-29 01:57:15 +0000 (Thu, 29 Dec 2005) $'); |
---|
49 | $func Version = e.version; |
---|
50 | |
---|
51 | // information about available compiler options |
---|
52 | $box Options; |
---|
53 | |
---|
54 | // put information about compiler options in the &Options box |
---|
55 | $func Init-Options = ; |
---|
56 | |
---|
57 | // display help screen |
---|
58 | $func Display-Help = ; |
---|
59 | |
---|
60 | $func RFP-Parse-Args (e.files) (e.prevarg) s.index = e.files; |
---|
61 | $func RFP-Set-Path = ; |
---|
62 | |
---|
63 | // initialize tables |
---|
64 | $func Get-Ready-To-Work e.Items = ; |
---|
65 | |
---|
66 | $func CPP-Pretty-Print s.inner-call? s.channel (e.indent) e.expr = ; |
---|
67 | |
---|
68 | // print information about compilation stages when -verbose option was |
---|
69 | // supplied on command line |
---|
70 | $func Verbose e.string = ; |
---|
71 | |
---|
72 | $func Open-Channel e.name (e.ext) = s.channel s.need-close?; |
---|
73 | |
---|
74 | $func Find-Includes = e.includes; |
---|
75 | |
---|
76 | |
---|
77 | Main = |
---|
78 | <Init-Options>, |
---|
79 | <RFP-Parse-Args () () 1> :: e.files, |
---|
80 | <RFP-Set-Path>, |
---|
81 | <Store &Error-Counter 0>, |
---|
82 | <Store &Warning-Counter 0>, |
---|
83 | // <PrintLN e.files>, |
---|
84 | e.files : { |
---|
85 | /*empty*/ = |
---|
86 | { |
---|
87 | <In-Table? &RFP-Options HELP>; |
---|
88 | <PrintLN 'Refal+ compiler ' <Version>>, |
---|
89 | 'Usage: rfpc' :: e.start, |
---|
90 | <Length e.start> :: s.st-len, |
---|
91 | <Print e.start>, |
---|
92 | <Box> :: s.len, |
---|
93 | <Store s.len s.st-len>, |
---|
94 | { |
---|
95 | <? &Options> : e (((e.next) e) t e.descr) e, |
---|
96 | <"<=" (<Length e.next>) (3)>, |
---|
97 | { |
---|
98 | e.descr : (e.arg) e = ' [-' e.next ' <' e.arg '>]'; |
---|
99 | ' [-' e.next ']'; |
---|
100 | } :: e.next, |
---|
101 | <Length e.next> :: s.n-len, |
---|
102 | <"+" <To-Int <? s.len>> s.n-len> :: s.new, |
---|
103 | { |
---|
104 | <">" (s.new) (64)> = |
---|
105 | <Store s.len <"+" s.st-len s.n-len>>, |
---|
106 | <PrintLN>, |
---|
107 | <Print <Repeat s.st-len ' '>>; |
---|
108 | <Store s.len s.new>; |
---|
109 | }, |
---|
110 | <Print e.next>, |
---|
111 | $fail; |
---|
112 | <PrintLN ' file ...'>; |
---|
113 | }, |
---|
114 | <PrintLN>, |
---|
115 | <PrintLN! &StdErr 'No input files specified'>; |
---|
116 | }; |
---|
117 | e01 (e.file) e02, |
---|
118 | { |
---|
119 | e.file : $r e.basename '.' e.ext = e.basename (' .' e.ext); |
---|
120 | e.file (); |
---|
121 | } :: e.in-basename (e.ext), |
---|
122 | { |
---|
123 | e01 : /*empty*/, <Lookup &RFP-Options NAME>; |
---|
124 | e.in-basename; |
---|
125 | } :: e.basename, |
---|
126 | { |
---|
127 | e.basename : $r e.dirname &RFP-Dir-Separator e.filename = |
---|
128 | (e.dirname) e.filename; |
---|
129 | () e.basename; |
---|
130 | } :: (e.dirname) e.filename, |
---|
131 | { |
---|
132 | <Channel? e.basename> = e.in-basename; |
---|
133 | e.basename; |
---|
134 | } :: e.headname, |
---|
135 | <Subst (&RFP-Dir-Separator) (('_')) e.headname> :: e.headname, |
---|
136 | <Rfp2Cpp <To-Word e.headname>> :: e.headname, |
---|
137 | { |
---|
138 | e.ext : \{ ' .rf'; ' .rfi'; } = |
---|
139 | <Verbose "parsing started" >, |
---|
140 | <RFP-Lexer e.file> :: e.tokens, |
---|
141 | <Store &RFP-Token-Stack e.tokens>, |
---|
142 | <RFP-Parser> :: t.as, |
---|
143 | <Verbose "parsing finished">, |
---|
144 | AS-REFAL t.as; |
---|
145 | e.ext : ' .asr' = |
---|
146 | <Channel> :: s.channel, |
---|
147 | <Open-File s.channel e.file R>, |
---|
148 | AS-REFAL <Read! s.channel>; |
---|
149 | e.ext : ' .ast' = |
---|
150 | <Channel> :: s.channel, |
---|
151 | <Open-File s.channel e.file R>, |
---|
152 | AS-TRANSFORMED <Read! s.channel>; |
---|
153 | e.ext : ' .asi' = |
---|
154 | <Channel> :: s.channel, |
---|
155 | <Open-File s.channel e.file R>, |
---|
156 | AS-AIL (AS-AIL AS-AIL <Read! s.channel> <Read! s.channel>); |
---|
157 | <PrintLN! &StdErr "Error: unknown extension" e.ext " in " e.file> = $fail; |
---|
158 | } : s.type (s.tag t.ModuleName e.Items), |
---|
159 | { |
---|
160 | s.type : AS-AIL; |
---|
161 | <Get-Ready-To-Work e.Items>; |
---|
162 | }, |
---|
163 | s.type e.Items $iter s.type : { |
---|
164 | AS-REFAL = |
---|
165 | { |
---|
166 | <In-Table? &RFP-Options AS-REFAL> = |
---|
167 | <Open-Channel e.basename ('.asr')> :: s.channel s.need-close?, |
---|
168 | <RFP-Pretty-Print s.channel () (s.tag t.ModuleName e.Items)>, |
---|
169 | { s.need-close? : 1 = <Close-Channel s.channel>;; };; |
---|
170 | }, |
---|
171 | <? &Error-Counter> : 0, |
---|
172 | { |
---|
173 | <In-Table? &RFP-Options NO-CHECK>; |
---|
174 | <Verbose "syntax check started">, |
---|
175 | <RFP-Check e.Items>, |
---|
176 | <Verbose "syntax check finished"> = |
---|
177 | <? &Error-Counter> : 0; |
---|
178 | }, |
---|
179 | \{ |
---|
180 | <In-Table? &RFP-Options CC>; |
---|
181 | <In-Table? &RFP-Options HH>; |
---|
182 | <In-Table? &RFP-Options JAVA>; |
---|
183 | <In-Table? &RFP-Options AS-AIL>; |
---|
184 | <In-Table? &RFP-Options AS-TRANSFORMED>; |
---|
185 | }, |
---|
186 | { |
---|
187 | <In-Table? &RFP-Options DBG> = |
---|
188 | <Verbose "debug-text generation started">, |
---|
189 | <RFP-Debug e.Items> :: e.Items, |
---|
190 | <Verbose "debug-text generation finished">, |
---|
191 | e.Items; |
---|
192 | e.Items; |
---|
193 | } :: e.Items, |
---|
194 | { |
---|
195 | <In-Table? &RFP-Options NO-TRANSFORM> = e.Items; |
---|
196 | <Verbose "as-to-as transformation started">, |
---|
197 | <RFP-As2As-Transform e.Items> :: e.Items, |
---|
198 | <Verbose "as-to-as transformation finished">, |
---|
199 | e.Items; |
---|
200 | } :: e.Items, |
---|
201 | AS-TRANSFORMED e.Items; |
---|
202 | AS-TRANSFORMED = |
---|
203 | { |
---|
204 | <In-Table? &RFP-Options AS-TRANSFORMED> = |
---|
205 | <Open-Channel e.basename ('.ast')> :: s.channel s.need-close?, |
---|
206 | <RFP-Pretty-Print s.channel () (s.tag t.ModuleName e.Items)>, |
---|
207 | { s.need-close? : 1 = <Close-Channel s.channel>;; };; |
---|
208 | }, |
---|
209 | \{ |
---|
210 | <In-Table? &RFP-Options CC>; |
---|
211 | <In-Table? &RFP-Options HH>; |
---|
212 | <In-Table? &RFP-Options JAVA>; |
---|
213 | <In-Table? &RFP-Options AS-AIL>; |
---|
214 | }, |
---|
215 | <Verbose "compilation to abstract imperative language started">, |
---|
216 | <RFP-Compile e.Items> : (INTERFACE e.interf) (MODULE e.module), |
---|
217 | <Verbose "compilation to abstract imperative language finished">, |
---|
218 | AS-AIL |
---|
219 | (INTERFACE t.ModuleName e.interf) (MODULE t.ModuleName e.module); |
---|
220 | AS-AIL = |
---|
221 | { |
---|
222 | <In-Table? &RFP-Options AS-AIL> = |
---|
223 | <Open-Channel e.basename ('.asi')> :: s.channel s.need-close?, |
---|
224 | { |
---|
225 | e.Items : e t.item e, |
---|
226 | <RFP-Pretty-Print s.channel () t.item>, |
---|
227 | $fail;; |
---|
228 | }, |
---|
229 | { s.need-close? : 1 = <Close-Channel s.channel>;; };; |
---|
230 | }, |
---|
231 | \{ |
---|
232 | <In-Table? &RFP-Options HH>, |
---|
233 | e.Items : (INTERFACE t.asail-mod-name v.headers) e, |
---|
234 | <Verbose "headers generation started">, |
---|
235 | <RFP-ASAIL-To-CPP t.asail-mod-name v.headers> :: e.headers, |
---|
236 | <Verbose "headers generation finished">, |
---|
237 | <Open-Channel e.basename ('.hh')> :: s.channel s.need-close?, |
---|
238 | <PrintLN! s.channel '#ifndef __' e.headname '_hh__'>, |
---|
239 | <PrintLN! s.channel '#define __' e.headname '_hh__'>, |
---|
240 | <PrintLN! s.channel '\n#include <rf_core.hh>'>, |
---|
241 | <CPP-Pretty-Print 0 s.channel () e.headers>, |
---|
242 | <PrintLN! s.channel '\n#endif // __' e.headname '_hh__'>, |
---|
243 | { s.need-close? : 1 = <Close-Channel s.channel>;; }, |
---|
244 | { |
---|
245 | <In-Table? &RFP-Options CASE-INSENSITIVE>, |
---|
246 | # <Channel? e.basename>, |
---|
247 | <To-Lower e.filename> :: e.lowname, |
---|
248 | # \{ e.filename : e.lowname; } = |
---|
249 | e.basename : e.dir e.filename, |
---|
250 | e.dir e.lowname :: e.lowbase, |
---|
251 | <Open-Channel e.lowbase ('.hh')> :: s.channel s.need-close?, |
---|
252 | <Subst (&RFP-Dir-Separator) (('_')) e.lowbase> :: e.headname, |
---|
253 | <Rfp2Cpp <To-Word e.headname>> :: e.headname, |
---|
254 | <PrintLN! s.channel '#ifndef __' e.headname '_hh__'>, |
---|
255 | <PrintLN! s.channel '#define __' e.headname '_hh__'>, |
---|
256 | <PrintLN! s.channel '\n#include <' e.basename '.hh>'>, |
---|
257 | <PrintLN! s.channel '\nnamespace refal\n{'>, |
---|
258 | <PrintLN! s.channel '\nnamespace ' e.lowname |
---|
259 | ' = ' e.filename ';'>, |
---|
260 | <PrintLN! s.channel '\n}'>, |
---|
261 | <PrintLN! s.channel '\n#endif // __' e.headname '_hh__'>, |
---|
262 | { s.need-close? : 1 = <Close-Channel s.channel>;; };; |
---|
263 | }, |
---|
264 | $fail; |
---|
265 | <In-Table? &RFP-Options CC>, |
---|
266 | e.Items : e (MODULE t.asail-mod-name v.module), |
---|
267 | { |
---|
268 | <In-Table? &RFP-Options NO-OPTIM> = v.module; |
---|
269 | <Verbose "as-ail optimization started">, |
---|
270 | <ASAIL-Optim v.module> :: e.module, |
---|
271 | <Verbose "as-ail optimization finished"> = |
---|
272 | e.module; |
---|
273 | } :: e.module , |
---|
274 | <Verbose "compilation from as-ail to c++ started">, |
---|
275 | <RFP-ASAIL-To-CPP t.asail-mod-name e.module> :: e.module, |
---|
276 | <Verbose "compilation from as-ail to c++ finished">, |
---|
277 | <Open-Channel e.basename ('.cc')> :: s.channel s.need-close?, |
---|
278 | <PrintLN! s.channel '#include <rf_core.hh>'>, |
---|
279 | { |
---|
280 | <Find-Includes> : e (e.include) e, |
---|
281 | <PrintLN! s.channel '#include ' e.include>, |
---|
282 | $fail;; |
---|
283 | }, |
---|
284 | <CPP-Pretty-Print 0 s.channel () e.module>, |
---|
285 | { s.need-close? : 1 = <Close-Channel s.channel>;; }, |
---|
286 | $fail; |
---|
287 | <In-Table? &RFP-Options JAVA>, |
---|
288 | e.Items : (INTERFACE t.asail-mod-name e.headers) (MODULE t e.module), |
---|
289 | { |
---|
290 | <In-Table? &RFP-Options NO-OPTIM> = e.module; |
---|
291 | <Verbose "as-ail optimization started">, |
---|
292 | <ASAIL-Optim e.module> :: e.module, |
---|
293 | <Verbose "as-ail optimization finished"> = |
---|
294 | e.module; |
---|
295 | } :: e.module, |
---|
296 | <Verbose "compilation from as-ail to java started">, |
---|
297 | { |
---|
298 | e.headers (/*e.exports*/) $iter { |
---|
299 | e.headers : (s.decl t.name) e.rest = |
---|
300 | e.rest (e.exports t.name); |
---|
301 | } :: e.headers (e.exports), |
---|
302 | e.headers : /*empty*/ = |
---|
303 | e.exports; |
---|
304 | } :: e.exports, |
---|
305 | <RFP-ASAIL-To-Java t.asail-mod-name (e.exports) e.module> :: (e.inputs) e.module, |
---|
306 | <Verbose "compilation from as-ail to java finished">, |
---|
307 | <Open-Channel e.basename ('.java')> :: s.channel s.need-close?, |
---|
308 | { |
---|
309 | e.dirname : v = |
---|
310 | <PrintLN! s.channel |
---|
311 | 'package '<Subst (&RFP-Dir-Separator) (('.')) e.dirname>';\n'>;; |
---|
312 | }, |
---|
313 | <PrintLN! s.channel 'import org.refal.plus.*;'>, |
---|
314 | { |
---|
315 | e.inputs : e (e.java-module) e, |
---|
316 | <Lookup &RFP-Includes <To-Chars e.java-module>> : { |
---|
317 | BOOT e = 'org.refal.plus.library.'e.java-module; |
---|
318 | LOCAL e.path = |
---|
319 | <Subst (&RFP-Dir-Separator) (('.')) e.path> e.java-module; |
---|
320 | } :: e.java-module, |
---|
321 | <PrintLN! s.channel 'import 'e.java-module';'>, |
---|
322 | $fail;; |
---|
323 | }, |
---|
324 | <CPP-Pretty-Print 0 s.channel () e.module>, |
---|
325 | { s.need-close? : 1 = <Close-Channel s.channel>;; }, |
---|
326 | $fail; |
---|
327 | }; |
---|
328 | } :: s.type e.Items, |
---|
329 | $fail; |
---|
330 | e.all-files-have-gone; |
---|
331 | }; |
---|
332 | |
---|
333 | Init-Options = <Store &Options |
---|
334 | ((('I') ('ipath')) IPATH |
---|
335 | ("dir") "add <dir> to the list of directories to be searched" "for .rfi files") |
---|
336 | ((('B') ('bootpath')) BPATH |
---|
337 | ("dir") "add <dir> to the list of directories to be searched" "for standard library .rfi files") |
---|
338 | ((('ne') ('no-elaborate')) (BIND NO-ELABORATE)) |
---|
339 | ((('nc') ('no-check')) (BIND NO-CHECK) |
---|
340 | "don't perform syntax check") |
---|
341 | ((('nt') ('no-transform')) (BIND NO-TRANSFORM) |
---|
342 | "don't perform AS-to-AS transformations") |
---|
343 | ((('c') ('check')) (BIND CHECK) |
---|
344 | "check only, causes no file creation in the absence" |
---|
345 | "of other output control options") |
---|
346 | ((('no') ('no-optim')) (BIND NO-OPTIM) "don't perform ASAIL-optimization") |
---|
347 | ((('ci') ('comp-item')) COMP-ITEM |
---|
348 | ("item") "compile <item> only, not the whole source" "(may be used several times)") |
---|
349 | ((('h') ('help')) HELP /*"display this help screen"*/) |
---|
350 | ((('v') ('verbose')) (BIND VERBOSE) |
---|
351 | "display information about the stages of compilation") |
---|
352 | ((('u')) (BIND CASE-INSENSITIVE) |
---|
353 | "convert all symbol-words without surrounding quotes" "to upper case") |
---|
354 | ((('o')) NAME |
---|
355 | ("name| - ") "place outputs for file1 into files <name>.* or send" "them to stdout") |
---|
356 | ((('cc')) (BIND CC) |
---|
357 | "output C++ code") |
---|
358 | ((('hh')) (BIND HH) |
---|
359 | "generate header files") |
---|
360 | ((('j') ('java')) (BIND JAVA) |
---|
361 | "output Java code") |
---|
362 | ((('asr') ('as-refal')) (BIND AS-REFAL) |
---|
363 | "output Refal Abstract Syntax") |
---|
364 | ((('ast') ('as-transformed')) (BIND AS-TRANSFORMED) |
---|
365 | "output Refal Abstract Syntax after AS-to-AS" "transformations") |
---|
366 | ((('asi') ('as-ail')) (BIND AS-AIL) |
---|
367 | "output Abstract Syntax of Abstract Imperative" "Language") |
---|
368 | ((('int')) INT ("class_name") "class to use for literal integers") |
---|
369 | ((('replace-module')) REPLACE-MODULE ("m1" "m2") "use module <m2> instead of <m1>") |
---|
370 | ((('d') ('debug')) (BIND DEBUG)) |
---|
371 | ((('dbg')) (BIND DBG) "generate text for debugger") |
---|
372 | >; |
---|
373 | |
---|
374 | Display-Help = |
---|
375 | <Box> :: s.line, |
---|
376 | ' ' :: e.start1, |
---|
377 | 29 :: s.2nd-col, |
---|
378 | <Repeat s.2nd-col ' '> :: e.start2, |
---|
379 | <PrintLN "Refal+ compiler " <Version>>, |
---|
380 | <PrintLN "Copyright blah-blah-blah">, |
---|
381 | <PrintLN>, |
---|
382 | <PrintLN "Usage: rfpc [options] file1 [file2 ...]">, |
---|
383 | <PrintLN "Options:">, |
---|
384 | { |
---|
385 | <? &Options> : e (((e.op) e.opts) t e.descr) e, |
---|
386 | <Store s.line e.start1 '-' e.op>, |
---|
387 | { |
---|
388 | e.opts : e (e.next) e, |
---|
389 | <Put s.line ', -' e.next>, |
---|
390 | $fail;; |
---|
391 | }, |
---|
392 | { |
---|
393 | e.descr : (e.params) e.rest = |
---|
394 | { |
---|
395 | e.params : e s.par e, |
---|
396 | <Put s.line ' <' <To-Chars s.par> '>'>, |
---|
397 | $fail; |
---|
398 | e.rest; |
---|
399 | }; |
---|
400 | e.descr; |
---|
401 | } : \{ |
---|
402 | s.phrase e, |
---|
403 | <PrintLN |
---|
404 | <? s.line> |
---|
405 | <Repeat <"-" s.2nd-col <Length <? s.line>>> ' '> |
---|
406 | s.phrase |
---|
407 | >, |
---|
408 | $fail; |
---|
409 | e s s.phrase e, |
---|
410 | <PrintLN e.start2 s.phrase>, |
---|
411 | $fail; |
---|
412 | };; |
---|
413 | }; |
---|
414 | |
---|
415 | RFP-Parse-Args (e.files) (e.prevarg) s.index = |
---|
416 | { |
---|
417 | <Arg s.index> : v.arg, <"+" s.index 1> :: s.index = |
---|
418 | { |
---|
419 | e.prevarg : v, e.prevarg : |
---|
420 | { |
---|
421 | IPATH = |
---|
422 | <Store &RFP-Include-Path <? &RFP-Include-Path> (v.arg)>, |
---|
423 | { |
---|
424 | $iter |
---|
425 | # \{ |
---|
426 | <? &RFP-Include-Path> : e1 (e2 &RFP-Dir-Separator), |
---|
427 | <Store &RFP-Include-Path e1 (e2)>; |
---|
428 | }; |
---|
429 | }; |
---|
430 | BPATH = |
---|
431 | <Store &RFP-Boot-Path <? &RFP-Boot-Path> (v.arg)>, |
---|
432 | { |
---|
433 | $iter |
---|
434 | # \{ |
---|
435 | <? &RFP-Boot-Path> : e1 (e2 &RFP-Dir-Separator), |
---|
436 | <Store &RFP-Boot-Path e1 (e2)>; |
---|
437 | }; |
---|
438 | }; |
---|
439 | COMP-ITEM = |
---|
440 | { |
---|
441 | <Lookup &RFP-Options ITEMS>; |
---|
442 | /*empty*/; |
---|
443 | } :: e.items, |
---|
444 | <Bind &RFP-Options (ITEMS) (e.items <Make-Name v.arg>)>; |
---|
445 | NAME = |
---|
446 | { |
---|
447 | v.arg : '-' = &StdOut; |
---|
448 | v.arg; |
---|
449 | } :: v.arg, |
---|
450 | <Bind &RFP-Options (NAME) (v.arg)>; |
---|
451 | INT = |
---|
452 | <Bind &RFP-Options (INT) (v.arg)>; |
---|
453 | REPLACE-MODULE = REPLACE-MODULE-2 v.arg; |
---|
454 | REPLACE-MODULE-2 e.mod1 = |
---|
455 | <Bind &RFP-Module-Subst (e.mod1) (v.arg)>; |
---|
456 | } :: e.prevarg, |
---|
457 | <RFP-Parse-Args (e.files) (e.prevarg) s.index>; |
---|
458 | v.arg : '-' e.opt = |
---|
459 | { |
---|
460 | \{ |
---|
461 | <? &Options> : e ((e (e.opt) e) t.action e) e = t.action; |
---|
462 | e.opt : '-' e.o, |
---|
463 | <? &Options> : e ((e (e.o) e) t.action e) e = t.action; |
---|
464 | } : { |
---|
465 | (BIND s.option) = <Bind &RFP-Options (s.option) ()>; |
---|
466 | HELP = <Bind &RFP-Options (HELP) ()>, <Display-Help>; |
---|
467 | s.other = s.other; |
---|
468 | } :: e.prevarg, |
---|
469 | <RFP-Parse-Args (e.files) (e.prevarg) s.index>; |
---|
470 | <PrintLN! &StdErr "Unknown option \"-" e.opt "\"">, |
---|
471 | <RFP-Parse-Args (e.files) () s.index>; |
---|
472 | }; |
---|
473 | <RFP-Parse-Args (e.files (v.arg)) () s.index>; |
---|
474 | }; |
---|
475 | { |
---|
476 | \{ |
---|
477 | <In-Table? &RFP-Options CC>; |
---|
478 | <In-Table? &RFP-Options HH>; |
---|
479 | <In-Table? &RFP-Options JAVA>; |
---|
480 | <In-Table? &RFP-Options AS-REFAL>; |
---|
481 | <In-Table? &RFP-Options AS-TRANSFORMED>; |
---|
482 | <In-Table? &RFP-Options AS-AIL>; |
---|
483 | <In-Table? &RFP-Options CHECK>; |
---|
484 | }; |
---|
485 | <Bind &RFP-Options (CC) ()> <Bind &RFP-Options (HH) ()>; |
---|
486 | }, |
---|
487 | e.files; |
---|
488 | }; |
---|
489 | |
---|
490 | RFP-Set-Path = |
---|
491 | <Store &RFP-Boot-Path <? &RFP-Boot-Path> &RFP-Default-Include-Path>, |
---|
492 | <Store &RFP-Include-Path <? &RFP-Include-Path> <? &RFP-Boot-Path>>; |
---|
493 | |
---|
494 | Get-Ready-To-Work e.Items = |
---|
495 | <RFP-Clear-Table &Fun>, |
---|
496 | <RFP-Clear-Table &Fun?>, |
---|
497 | <RFP-Clear-Table &Const>, |
---|
498 | <RFP-Clear-Table &Object>, |
---|
499 | { |
---|
500 | e.Items : e t.Item e, |
---|
501 | t.Item : (s.Linkage s.ItemType t.Pragma t.ItemName e.ItemBody), |
---|
502 | s.ItemType : { |
---|
503 | FUNC = |
---|
504 | <Left 0 2 e.ItemBody> : (e.in) (e.out), |
---|
505 | &Fun (<Format-Exp e.in>) (<Format-Exp e.out>); |
---|
506 | FUNC? = |
---|
507 | <Left 0 2 e.ItemBody> : (e.in) (e.out), |
---|
508 | &Fun? (<Format-Exp e.in>) (<Format-Exp e.out>); |
---|
509 | CONST = &Const e.ItemBody; |
---|
510 | s = &Object e.ItemBody; |
---|
511 | } :: s.tab e.ItemDef, |
---|
512 | <Bind s.tab (t.ItemName) (s.Linkage s.ItemType t.Pragma e.ItemDef)>, |
---|
513 | $fail;; |
---|
514 | }; |
---|
515 | |
---|
516 | RFP-Pretty-Print s.channel (e.indent) e.expr = e.expr : |
---|
517 | { |
---|
518 | e0 (e1) e2 = |
---|
519 | <Write! s.channel e0>, |
---|
520 | { e.indent : v = <PrintLN! s.channel>;; }, |
---|
521 | <Print! s.channel e.indent '('>, |
---|
522 | <RFP-Pretty-Print s.channel (e.indent ' ') e1>, |
---|
523 | { |
---|
524 | e1 : e (e) e = |
---|
525 | <PrintLN! s.channel>, |
---|
526 | <Print! s.channel e.indent ')'>; |
---|
527 | <Print! s.channel ')'>; |
---|
528 | }, |
---|
529 | { |
---|
530 | e2 : (e) e = ; |
---|
531 | e2 : , e.indent : v = ; |
---|
532 | <PrintLN! s.channel>, <Print! s.channel e.indent>; |
---|
533 | }, |
---|
534 | <RFP-Pretty-Print s.channel (e.indent) e2>; |
---|
535 | v1 = |
---|
536 | <Write! s.channel v1>; |
---|
537 | =; |
---|
538 | }; |
---|
539 | |
---|
540 | $const Tab = ' '; |
---|
541 | |
---|
542 | CPP-Pretty-Print s.inner-call? s.channel (e.indent) e.expr, e.expr : { |
---|
543 | e0 (e1) e2 = |
---|
544 | { s.inner-call? : 0 = <PrintLN! s.channel>;; }, |
---|
545 | { |
---|
546 | e0 : /*empty*/, { |
---|
547 | e1 : LABEL e.label = |
---|
548 | e.indent : e.ind &Tab, |
---|
549 | <PrintLN! s.channel e.ind e.label>; |
---|
550 | <CPP-Pretty-Print 1 s.channel (e.indent) e1>; |
---|
551 | }; |
---|
552 | <PrintLN! s.channel e.indent e0>, |
---|
553 | <CPP-Pretty-Print 1 s.channel (e.indent &Tab) (e1)>; |
---|
554 | }, |
---|
555 | <CPP-Pretty-Print s.inner-call? s.channel (e.indent) e2>; |
---|
556 | v1 = <PrintLN! s.channel e.indent v1>; |
---|
557 | /*empty*/ = /*empty*/; |
---|
558 | }; |
---|
559 | |
---|
560 | Verbose e.string, { |
---|
561 | <In-Table? &RFP-Options VERBOSE> = |
---|
562 | <PrintLN <Time> ": " e.string>;; |
---|
563 | }; |
---|
564 | |
---|
565 | Open-Channel { |
---|
566 | symbol (e), <Channel? symbol> = symbol 0; |
---|
567 | e.name (e.ext) = |
---|
568 | <Channel> :: s.channel, |
---|
569 | { |
---|
570 | <Open-File s.channel e.name e.ext W> = |
---|
571 | s.channel 0; // When we need to close channel ??? |
---|
572 | <PrintLN! &StdErr "Error: cannot open file " e.name e.ext " for writing">, |
---|
573 | <Exit 1>, $fail; |
---|
574 | }; |
---|
575 | }; |
---|
576 | |
---|
577 | Find-Includes = |
---|
578 | <Box> :: s.includes, |
---|
579 | { |
---|
580 | <Domain &RFP-Sources> : e (s.idx) e, |
---|
581 | <Lookup &RFP-Sources s.idx> : e.full-name '.rfi', |
---|
582 | { |
---|
583 | <? &RFP-Include-Path> : e (e.path) e, |
---|
584 | e.full-name : e.path &RFP-Dir-Separator e.name = |
---|
585 | <Put s.includes ('<refal/' e.name '.hh>')>; |
---|
586 | <RFP-Dir-Name <RFP-Source-File-Name 1>> : e.path, |
---|
587 | e.full-name : e.path &RFP-Dir-Separator e.name = |
---|
588 | <Put s.includes ('"' e.name '.hh"')>; |
---|
589 | <Put s.includes ('"' e.full-name '.hh"')>; |
---|
590 | }, |
---|
591 | $fail;; |
---|
592 | }, |
---|
593 | <? s.includes>; |
---|
594 | |
---|
595 | Version = { |
---|
596 | &RevDate : (e ' ' v.rev ' ' e) (e ' ' v.date ' ' e) = '2.0-beta-' v.rev ', ' v.date; |
---|
597 | '2.0-unknown-beta'; |
---|
598 | }; |
---|
599 | |
---|