changeset 88:f69987c58fa8

Merge
author Mike Pavone <pavone@retrodev.com>
date Fri, 30 Jul 2010 19:52:54 -0400
parents 3c4325e6298f (current diff) a163250b8885 (diff)
children 5a195ee08eac
files cbackend.rhope
diffstat 4 files changed, 103 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/cbackend.rhope	Fri Jul 30 01:48:59 2010 -0400
+++ b/cbackend.rhope	Fri Jul 30 19:52:54 2010 -0400
@@ -1224,7 +1224,7 @@
 									]Append[", "]
 									]Append[size]
 									]Append[", "]
-									]Append[[[value]Args >>]Length]
+									]Append[Fold[["+"]Set Input[0, 1], 0, [value]Args >>]]
 									]Append[")"]
 						}{
 							out <- "UnhandledLiteralType"
@@ -1282,16 +1282,12 @@
 
 _Dispatch Switch Sub[text, num, name:out]
 {
-	out <- [[[[[[[[[text
-		]Append["\tcase RES_"]
+	out <- [[[[[text
+		]Append["\tResumeEntry("]
 		]Append[num]
-		]Append["_"]
+		]Append[","]
 		]Append[name]
-		]Append[": goto r"]
-		]Append[num]
-		]Append["_"]
-		]Append[name]
-		]Append[";\\\n"]
+		]Append[")\\\n"]
 }
 
 _Dispatch Switch[text,func,raw name:out]
@@ -1299,7 +1295,7 @@
 	If[[[func]Convention >>] = ["rhope"]]
 	{
 		name <- Escape Rhope Name[raw name]
-		out <- [[text]Append[ [[[["\tcase FUNC_"]Append[name]]Append[": goto f_"]]Append[name]]Append[";\\\n"] ]
+		out <- [[text]Append[ [["\tDispatchEntry("]Append[name]]Append[")\\\n"] ]
 			]Append[Fold[["_Dispatch Switch Sub"]Set Input[2, name], "", Range[1, [func]Resume Index >>]]]
 	}{
 		out <- text
@@ -1309,7 +1305,7 @@
 _Dispatch Switch Methods[text,id,raw name:out]
 {
 	name <- Escape Rhope Name[raw name]
-	out <- [text]Append[ [[[["\tcase FUNC_"]Append[name]]Append[": goto f_"]]Append[name]]Append[";\\\n"] ]
+	out <- [text]Append[ [["\tDispatchEntry("]Append[name]]Append[")\\\n"] ]
 }
 
 _Dispatch Enum Sub[text, num, name:out]
@@ -1346,11 +1342,11 @@
 			[Fold["_Dispatch Enum Methods", "", all methods]]Append["\tFUNC_Build,\n\tFUNC_BlueprintSP_Of,\n\tFUNC_ID,\n\tFUNC_BlueprintSP_FromSP_ID,\n"], 
 			[program]Functions >>]]
 		]Append["\tEND\n} funcids;\n\n"]
-		]Append["#define DISPATCH switch(func) { \\\n"]
+		]Append["#define DispatchEntries \\\n"] 
 		]Append[Fold["_Dispatch Switch", 
-			[Fold["_Dispatch Switch Methods", "", all methods]]Append["\tcase FUNC_Build: goto f_Build;\\\n\tcase FUNC_BlueprintSP_Of: goto f_BlueprintSP_Of;\\\n\tcase FUNC_ID: goto f_ID;\\\n\tcase FUNC_BlueprintSP_FromSP_ID: goto f_BlueprintSP_FromSP_ID;\\\n"], 
+			[Fold["_Dispatch Switch Methods", "", all methods]]Append["\tDispatchEntry(Build)\\\n\tDispatchEntry(BlueprintSP_Of)\\\n\tDispatchEntry(ID)\\\n\tDispatchEntry(BlueprintSP_FromSP_ID)\\\n"], 
 			[program]Functions >>]]
-		]Append["\tcase END: goto DO_END;\\\n}\n\n"]
+		]Append["\tEndEntry\n\n"]
 }
 
 Not Native[func:out]
@@ -1442,7 +1438,12 @@
 {
 	uint16_t resume,idx, vcparam_offset, last_vcparam;
 	context * ct;
-	calldata * cdata, *temp_cdata, *my_cdata;\n\nFuncDef(Build)\nFuncDef(BlueprintSP_Of)\nFuncDef(ID)\nFuncDef(BlueprintSP_FromSP_ID)\n"]
+	calldata * cdata, *temp_cdata, *my_cdata;
+	DispatchVar
+	FuncDef(Build)
+	FuncDef(BlueprintSP_Of)
+	FuncDef(ID)
+	FuncDef(BlueprintSP_FromSP_ID)\n"]
 		]Append[Fold["Local Pointers", "", [program]Functions >>]]
 		]Append["
 	ct = new_context();
--- a/fib.rhope	Fri Jul 30 01:48:59 2010 -0400
+++ b/fib.rhope	Fri Jul 30 19:52:54 2010 -0400
@@ -23,8 +23,7 @@
 Main[args]
 {
 	//Here we get the first command line argument and convert it to a number
-	//Yes I realize this is incredibly ugly looking
-	n <- <String@Whole Number[[args]Index[1]]
+	n <- Int32[[args]Index[1]]
 	//Call our Fib worker and Print the result to the terminal
 	Print[Fib[n]]
 }
--- a/functional.rhope	Fri Jul 30 01:48:59 2010 -0400
+++ b/functional.rhope	Fri Jul 30 19:52:54 2010 -0400
@@ -21,3 +21,73 @@
 	}
 }
 
+_Map[list,worker,cur:out]
+{
+	val <- [list]Index[cur]
+	nlist <- [list]Set[cur, [worker]Call[val, cur]]
+
+	[nlist]Next[cur]
+	{
+		out <- _Map[nlist, worker, ~]
+	}{
+		out <- Val[nlist]
+	}
+}
+
+Map[list,worker:out]
+{
+	[list]First
+	{
+		out <- _Map[list,worker,~]
+	}{
+		out <- list
+	}
+}
+
+_Find[list,pred,cur:loc,not found]
+{
+	val <- [list]Index[cur]
+	If[[pred]Call[val]]
+	{
+		loc <- cur
+	}{
+		,not found <- [list]Next[cur]
+		{ loc,not found <- _Find[list,pred,~] }
+	}
+}
+
+Find[list,pred:loc,not found]
+{
+	,not found <- [list]First
+	{
+		loc <- _Find[list,pred,~]
+	}
+}
+
+_Filter[list,pred,cur,dest:out]
+{
+	val <- [list]Index[cur]
+	If[[pred]Call[val,cur]]
+	{
+		ndest <- [dest]Append[val]
+	}{
+		ndest <- dest
+	}
+	[list]Next[cur]
+	{
+		out <- _Filter[list,pred,~,ndest]
+	}{
+		out <- Val[ndest]
+	}
+}
+
+Filter[list,pred:out]
+{
+	[list]First
+	{
+		out <- _Filter[list,pred,~, List[]]
+	}{
+		out <- list
+	}
+}
+
--- a/runtime/func.h	Fri Jul 30 01:48:59 2010 -0400
+++ b/runtime/func.h	Fri Jul 30 19:52:54 2010 -0400
@@ -14,7 +14,22 @@
 
 
 typedef returntype (*rhope_func)(calldata *);
-typedef void (*special_func) (object *);
+typedef void (*special_func) (object *);
+
+#ifdef MULTI_SWITCH
+#define DispatchEntry(name) case FUNC_##name: goto f_##name;
+#define ResumeEntry(num,name) case RES_##num##_##name: goto r##num##_##name;
+#define DispatchVar
+#define DISPATCH switch(func) { DispatchEntries }
+#define EndEntry case END: goto DO_END;
+#else
+#define DispatchEntry(name) &&f_##name,
+#define ResumeEntry(num,name) &&r##num##_##name,
+#define DispatchVar void * funcs[] = { DispatchEntries };
+#define DISPATCH goto *funcs[func];
+#define EndEntry &&DO_END
+#endif
+
 
 #define MethodName(name,type) f_ ## name ## AT_ ## type