# HG changeset patch # User Mike Pavone # Date 1305873007 25200 # Node ID 0c7c5671fcd30face4ef724d289591df4fbbdad8 # Parent e769b2e0faccc066629afed33fe548f77cf8e0aa Start work on interpreter diff -r e769b2e0facc -r 0c7c5671fcd3 geninterp.rhope --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/geninterp.rhope Thu May 19 23:30:07 2011 -0700 @@ -0,0 +1,65 @@ + +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[[~]Workers >>, 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"] + } +} + diff -r e769b2e0facc -r 0c7c5671fcd3 interp.rhope --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/interp.rhope Thu May 19 23:30:07 2011 -0700 @@ -0,0 +1,46 @@ + +Import interplookup.rhope + +_Get Line[string:out] +{ + char <- Get Char[] + If[[char]=["\n"]] + { + out <- string + }{ + out <- _Get Line[[string]Append[char]] + } +} + +Get Line[:out] +{ + out <- _Get Line[""] +} + +Do Set Input[worker,val,num:out] +{ + out <- [worker]Set Input[num, val] +} + +Interp Loop[lookup:out] +{ + [Get Line[]]Split[" "] + { + fname <- [~]Index[0] + args <- Map[Tail[~, 1], Int32[?]] + } + + [lookup]Index[fname] + { worker <- Fold[Do Set Input[?], ~, args] } + { continue <- Print[["Could not find "]Append[fname]] } + + continue <- Print[worker[]] + + Val[continue] + { out <- Interp Loop[lookup] } +} + +Main[:out] +{ + out <- Interp Loop[Func Lookup[]] +}