comparison compile_old_c.rhope @ 136:fc3815b7462f

Javascript backend now produces working code for some simple examples, still more of the standard lib that needs to be ported.
author Mike Pavone <pavone@retrodev.com>
date Sun, 14 Nov 2010 23:07:55 -0500
parents 18a4403fe576
children daf1ffaf7c2c
comparison
equal deleted inserted replaced
135:18a4403fe576 136:fc3815b7462f
69 } 69 }
70 70
71 Main[args] 71 Main[args]
72 { 72 {
73 73
74 fname,options <- Parse Args[args,1,[Dictionary[]]Set["b", "backend"],Dictionary[]] 74 fname,options <- Parse Args[args,1,[Dictionary[]]Set["b", "backend"],Dictionary[]]
75 { 75 {
76 file <- [File[~]]Open["r"] 76 backmap <- [[Dictionary[]
77 text <- String[[file]Read[[file]Length]] 77 ]Set["javascript", JS Program[?]]
78 params <- Parser[] 78 ]Set["c", C Program[?]]
79 Print[["Parsing "]Append[fname]] 79 sel <- [options]Index["backend"]
80 Null[text, params, Parse Program[], 0] 80 {
81 { 81 makeback <- [backmap]Index[~]{}
82 Print["Parsing imports"] 82 {
83 Process Imports[~, params] 83 Print[[["Unknown backend '"]Append[sel]]Append["' selected. Defaulting to C backend."]]
84 { 84 makeback <- C Program[?]
85 tree <- [~]Workers << [ Map[[~]Workers >>, Check Worker Literals[?, ~]] ] 85 }
86 { Print["Compiling"] } 86 }{ makeback <- C Program[?] }
87 } 87 backend <- Call[makeback]
88 backmap <- [[Dictionary[] 88
89 ]Set["javascript", JS Program[?]] 89 file <- [File[~]]Open["r"]
90 ]Set["c", C Program[?]] 90 text <- String[[file]Read[[file]Length]]
91 sel <- [options]Index["backend"] 91 params <- Parser[]
92 { 92 Print[["Parsing "]Append[fname]]
93 backend <- [backmap]Index[~]{} 93 Null[text, params, [backend]Set Stdlib Imports[Parse Program[]], 0]
94 { 94 {
95 Print[[["Unknown backend '"]Append[sel]]Append["' selected. Defaulting to C backend."]] 95 Print["Parsing imports"]
96 backend <- C Program[?] 96 Process Imports[~, params]
97 } 97 {
98 }{ backend <- C Program[?] } 98 tree <- [~]Workers << [ Map[[~]Workers >>, Check Worker Literals[?, ~]] ]
99 compiled <- [Tree to Program Native[tree]]Compile Program[Call[backend]] 99 { Print["Compiling"] }
100 { Print["Compiled program to backend"] } 100 }
101 outfname <- [compiled]Text Filename[fname] 101
102 outfile <- [File[outfname]]Truncate 102 compiled <- [Tree to Program Native[tree, [backend]Supported Number Types]]Compile Program[backend]
103 [[compiled]Text]Write to File[outfile] 103 { Print["Compiled program to backend"] }
104 { Print[["Wrote output to "]Append[outfname]] } 104 outfname <- [compiled]Text Filename[fname]
105 } 105 outfile <- [File[outfname]]Truncate
106 }{}{}{ 106 [[compiled]Text]Write to File[outfile]
107 Print["You must provide a file name to compile"] 107 { Print[["Wrote output to "]Append[outfname]] }
108 } 108 }
109 }{}{}{
110 Print["You must provide a file name to compile"]
111 }
109 } 112 }
110 113