comparison geninterp.rhope @ 174:0c7c5671fcd3

Start work on interpreter
author Mike Pavone <pavone@retrodev.com>
date Thu, 19 May 2011 23:30:07 -0700
parents
children 03e4fa277291
comparison
equal deleted inserted replaced
173:e769b2e0facc 174:0c7c5671fcd3
1
2 Import parser_old_c.rhope
3 Import cbackend_c.rhope
4
5 Worker Set[lines,worker:out]
6 {
7 If[[[worker]Name >>]Starts With["_"]]
8 {
9 out <- lines
10 }{
11 If[[[worker]Name >>]=["Call@Worker"]]
12 { out <- lines }
13 { out <- [lines]Append[ [[[["\t\t]Set[\""]Append[[worker]Name >>]]Append["\", "]]Append[[worker]Name >>]]Append["[?]]"] ] }
14 }
15 }
16
17 Get Constant Type[func,const:out]
18 {
19 out <- func
20 }
21
22 Get Var Type[func,varname:out]
23 {
24 out <- func
25 }
26
27 Main[args]
28 {
29
30 fname <- [args]Index[1]
31 {
32 file <- [File[~]]Open["r"]
33 text <- String[[file]Read[[file]Length]]
34 params <- Parser[]
35 Print[["Parsing "]Append[fname]]
36 Null[text, params, Parse Program[], 0]
37 {
38 Print["Parsing imports"]
39 Process Imports[~, params]
40 {
41 tree <- [~]Workers << [ Map[[~]Workers >>, Check Worker Literals[?, ~]] ]
42 { Print["Compiling"] }
43 }
44
45 program <- Tree to Program Native[tree, [C Program[]]Supported Number Types]
46 lines <- Fold[Worker Set[?], (), [program]Workers >>]
47
48 out text <- [[[Fold[Append[?, "["], "Func Lookup[:out]\n{\n\tout <- ", Range[0, Length[lines]]]
49 ]Append["Dictionary[]\n"]
50 ]Append[[lines]Join["\n"]]
51 ]Append["\n}\n"]
52
53
54 outname <- [args]Index[2] {}
55 { outname <- "interplookup.rhope" }
56 outfile <- [[File[outname]]Open["w"]]Truncate
57
58 [[out text]Write to File[outfile]
59 ]Close
60 }
61 }{
62 Print["You must provide a file name to compile"]
63 }
64 }
65