Mercurial > repos > rhope
view geninterp.rhope @ 189:d0e3a13c1bd9 default tip
Remove old calculator example
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 07 Oct 2011 00:24:04 -0700 |
parents | 03e4fa277291 |
children |
line wrap: on
line source
Import parser_old_c.rhope Import cbackend_c.rhope Worker Set[lines,worker:out] { If[[[worker]Name >>]Starts With["_"]] { out <- lines }{ If[[[worker]Name >>]=["Call@Worker"]] { out <- lines } { out <- [lines]Append[ [[[["\t\t]Set[\""]Append[[worker]Name >>]]Append["\", "]]Append[[worker]Name >>]]Append["[?]]"] ] } } } Get Constant Type[func,const:out] { out <- func } Get Var Type[func,varname:out] { out <- func } Main[args] { fname <- [args]Index[1] { 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[[~]Worker Refs >>, Check Worker Literals[?, ~]] ] { Print["Compiling"] } } program <- Tree to Program Native[tree, [C Program[]]Supported Number Types] lines <- Fold[Worker Set[?], (), [program]Workers >>] out text <- [[[Fold[Append[?, "["], "Func Lookup[:out]\n{\n\tout <- ", Range[0, Length[lines]]] ]Append["Dictionary[]\n"] ]Append[[lines]Join["\n"]] ]Append["\n}\n"] outname <- [args]Index[2] {} { outname <- "interplookup.rhope" } outfile <- [[File[outname]]Open["w"]]Truncate [[out text]Write to File[outfile] ]Close } }{ Print["You must provide a file name to compile"] } }