changeset 174:0c7c5671fcd3

Start work on interpreter
author Mike Pavone <pavone@retrodev.com>
date Thu, 19 May 2011 23:30:07 -0700
parents e769b2e0facc
children 03e4fa277291
files geninterp.rhope interp.rhope
diffstat 2 files changed, 111 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /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"]
+	}
+}
+
--- /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[]]
+}