Mercurial > repos > rhope
diff 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 |
line wrap: on
line diff
--- a/compile_old_c.rhope Sun Nov 14 03:09:49 2010 -0500 +++ b/compile_old_c.rhope Sun Nov 14 23:07:55 2010 -0500 @@ -71,40 +71,43 @@ Main[args] { - fname,options <- Parse Args[args,1,[Dictionary[]]Set["b", "backend"],Dictionary[]] - { - file <- [File[~]]Open["r"] - text <- String[[file]Read[[file]Length]] - params <- Parser[] - Print[["Parsing "]Append[fname]] - Null[text, params, Parse Program[], 0] - { - Print["Parsing imports"] - Process Imports[~, params] - { - tree <- [~]Workers << [ Map[[~]Workers >>, Check Worker Literals[?, ~]] ] - { Print["Compiling"] } - } - backmap <- [[Dictionary[] - ]Set["javascript", JS Program[?]] - ]Set["c", C Program[?]] - sel <- [options]Index["backend"] - { - backend <- [backmap]Index[~]{} - { - Print[[["Unknown backend '"]Append[sel]]Append["' selected. Defaulting to C backend."]] - backend <- C Program[?] - } - }{ backend <- C Program[?] } - compiled <- [Tree to Program Native[tree]]Compile Program[Call[backend]] - { Print["Compiled program to backend"] } - outfname <- [compiled]Text Filename[fname] - outfile <- [File[outfname]]Truncate - [[compiled]Text]Write to File[outfile] - { Print[["Wrote output to "]Append[outfname]] } - } - }{}{}{ - Print["You must provide a file name to compile"] - } + fname,options <- Parse Args[args,1,[Dictionary[]]Set["b", "backend"],Dictionary[]] + { + backmap <- [[Dictionary[] + ]Set["javascript", JS Program[?]] + ]Set["c", C Program[?]] + sel <- [options]Index["backend"] + { + makeback <- [backmap]Index[~]{} + { + Print[[["Unknown backend '"]Append[sel]]Append["' selected. Defaulting to C backend."]] + makeback <- C Program[?] + } + }{ makeback <- C Program[?] } + backend <- Call[makeback] + + file <- [File[~]]Open["r"] + text <- String[[file]Read[[file]Length]] + params <- Parser[] + Print[["Parsing "]Append[fname]] + Null[text, params, [backend]Set Stdlib Imports[Parse Program[]], 0] + { + Print["Parsing imports"] + Process Imports[~, params] + { + tree <- [~]Workers << [ Map[[~]Workers >>, Check Worker Literals[?, ~]] ] + { Print["Compiling"] } + } + + compiled <- [Tree to Program Native[tree, [backend]Supported Number Types]]Compile Program[backend] + { Print["Compiled program to backend"] } + outfname <- [compiled]Text Filename[fname] + outfile <- [File[outfname]]Truncate + [[compiled]Text]Write to File[outfile] + { Print[["Wrote output to "]Append[outfname]] } + } + }{}{}{ + Print["You must provide a file name to compile"] + } }