diff interp.rhope @ 174:0c7c5671fcd3

Start work on interpreter
author Mike Pavone <pavone@retrodev.com>
date Thu, 19 May 2011 23:30:07 -0700
parents
children
line wrap: on
line diff
--- /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[]]
+}