Mercurial > repos > rhope
diff compile_old.rhope @ 184:c6ba9fe45910
Strip _c from filenames of current compiler
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 27 Jul 2011 21:28:43 -0700 |
parents | compile_old_c.rhope@daf1ffaf7c2c |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/compile_old.rhope Wed Jul 27 21:28:43 2011 -0700 @@ -0,0 +1,113 @@ + +Import parser_old.rhope +Import cbackend.rhope +Import jsbackend.rhope + +Other Short[arg,list:out] +{ + If[[arg]=["-"]] + { + out <- list + }{ + rest,last <- [arg]Slice[ [[arg]Length]-[1] ] + out <- Other Short[rest, [list]Append[last]] + } +} + +Check Short Val[short,args,cur,shortopts,curopts:fname,opts,next,nofname] +{ + If[[cur]<[[[args]Length]-[1]]] + { + val <- [args]Index[cur] + nidx <- [cur]+[1] + }{ + val <- Yes + nidx <- Val[cur] + } + fname,opts,next,nofname <- Parse Args[args,nidx,shortopts,_Set Short[shortopts,curopts,short,val]] +} + +_Set Short[shortopts,dict,short,val:out] +{ + [shortopts]Index[short] + { + out <- [dict]Set[~, val] + }{ + Print[["Unrecognized short option: "]Append[short]] + out <- dict + } +} + +Parse Args[args,cur,shortopts,curopts:fname,opts,next,nofname] +{ + arg,nofname <- [args]Index[cur] + { + If[[~]Starts With["-"]] + { + If[[arg]Starts With["--"]] + { + ,,after <- [arg]Partition["="] + { + [~]Slice[2] {} + { nextopts <- [curopts]Set[~, after] } + } {} {} { + [arg]Slice[2] {} + { nextopts <- [curopts]Set[~, Yes] } + } + fname,opts,next,nofname <- Parse Args[args,[cur]+[1],shortopts,nextopts] + }{ + rest,last <- [arg]Slice[ [[arg]Length]-[1] ] + fname,opts,next,nofname <- Check Short Val[last,args, [cur]+[1], shortopts, + Fold[_Set Short[shortopts,?,?,Yes], curopts, Other Short[rest, ()]]] + } + }{ + fname <- Val[arg] + opts <- curopts + next <- [cur]+[1] + } + } +} + +Main[args] +{ + + 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 <- Val[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"] + } +} +