diff nworker.rhope @ 37:640f541e9116

Added support for type declarations on user defined workers and added a few more methods to Int32 in the runtime for the C backend
author Mike Pavone <pavone@retrodev.com>
date Mon, 05 Oct 2009 23:12:43 -0400
parents 495dddadd058
children 789a146a48e1
line wrap: on
line diff
--- a/nworker.rhope	Sat Oct 03 03:18:15 2009 -0400
+++ b/nworker.rhope	Mon Oct 05 23:12:43 2009 -0400
@@ -258,7 +258,9 @@
 	Convention
 	Nodes
 	Inputs
+	Input Types
 	Outputs
+	Output Types
 	Uses
 	NodeResults
 	Free Temps
@@ -266,7 +268,7 @@
 
 NWorker[convention:out]
 {
-	out <- [[[[Build["NWorker"]]Convention <<[convention]]Nodes <<[()]]Inputs <<[()]]Outputs <<[()]
+	out <- [[[[[[Build["NWorker"]]Convention <<[convention]]Nodes <<[()]]Inputs <<[()]]Outputs <<[()]]Input Types <<[()]]Output Types <<[()]
 }
 
 Add Node@NWorker[worker,type,data,inputs,outputs:out,node index]
@@ -287,14 +289,30 @@
 
 Add Input@NWorker[worker,name,number:out,node index]
 {
+	out,node index <- [worker]Add Typed Input[name,number,Type Instance["Any Type"]]
+}
+
+Add Typed Input@NWorker[worker,name,number,type:out,node index]
+{
 	,node index <- [worker]Add Node["input",number,0,1]
-	{ out <- [~]Inputs <<[[[~]Inputs >>]Set[number,name]] }
+	{ 
+		out <- [[~]Inputs <<[[[~]Inputs >>]Set[number,name]]
+		]Input Types <<[[[~]Input Types >>]Set[number,type]]
+	}
 }
 
 Add Output@NWorker[worker,name,number:out,node index]
 {
+	out,node index <- [worker]Add Typed Output[name,number,Type Instance["Any Type"]]
+}
+
+Add Typed Output@NWorker[worker,name,number,type:out,node index]
+{
 	,node index <- [worker]Add Node["output",number,1,0]
-	{ out <- [~]Outputs <<[[[~]Outputs >>]Set[number,name]] }
+	{ 
+		out <- [[~]Outputs <<[[[~]Outputs >>]Set[number,name]]
+		]Output Types <<[[[~]Output Types >>]Set[number,type]]
+	}
 }
 
 Add Object Get@NWorker[worker,fieldname:out,node index]
@@ -441,7 +459,7 @@
 		}{
 			If[[[node]Type >>] = ["const"]]
 			{
-				If[[Type Of[[node]Data >>]] = ["Type Literal"]]
+				If[[Type Of[[node]Data >>]] = ["Type Instance"]]
 				{
 					//TODO: Support parametric types
 					datstring <- [[node]Data >>]Name >>
@@ -578,7 +596,7 @@
 			If[[[node]Type >>] = ["const"]]
 			{
 				//TODO: Handle list constants
-				If[[Type Of[[node]Data >>]] = ["Type Literal"]]
+				If[[Type Of[[node]Data >>]] = ["Type Instance"]]
 				{
 					//TODO: Support parametric types
 					datstring <- [[node]Data >>]Name >>
@@ -672,7 +690,7 @@
 {
 	Print[["Compiling: "]Append[name]]
 	{
-	ifunc <- [program]Create Function[name,[worker]Inputs >>, [worker]Outputs >>, [worker]Convention >>]
+	ifunc <- Fold["Set Output Type", Fold["Set Input Type", [program]Create Function[name,[worker]Inputs >>, [worker]Outputs >>, [worker]Convention >>], [worker]Input Types >>], [worker]Output Types >>]
 	
 	res vars <- [worker]Result Vars
 	func <- Fold["Set Null", Fold["Set Null", Fold[["Allocate Var"]Set Input[2, "Any Type"], ifunc, res vars], res vars], [worker]Outputs >>]
@@ -684,7 +702,7 @@
 	}{
 		final func <- Val[func]
 	}
-	out <- [program]Store Function[Fold[["Release Var"]Set Input[0, worker], final func, res vars]]
+	out <- [program]Store Function[Fold["Release", Fold[["Release Var"]Set Input[0, worker], final func, res vars], [worker]Inputs >>]]
 	}
 }
 
@@ -776,7 +794,7 @@
 Make Special@NBlueprint[bp,backend,func name,bp name,pop worker:out]
 {
 	func <- [[backend]Create Function[func name,("obj"),(),"cdecl"]
-		]Set Input Type[0, bp name]
+		]Set Input Type[bp name, 0]
 	out <- [backend]Store Function[Fold[pop worker, func, [bp]Fields >>]]
 }
 
@@ -787,16 +805,16 @@
 	name <- [field]Index[0]
 	type <- [field]Index[1]
 	,getref <- [[[[backend]Create Function[ [[[name]Append[" >>"]]Append["@"]]Append[type name], ("obj"), ("out"), "rhope"]
-		]Set Input Type[0, type name]
-		]Set Output Type[0, type]
+		]Set Input Type[type name, 0]
+		]Set Output Type[type, 0]
 		]Read Field["obj", name]
-	{ getter <- [~]Do AddRef[getref, "out"]
+	{ getter <- [[~]Do AddRef[getref, "out"]]Release["obj"]
 	{ Print["Got getter"] } }
 		
 	,origref <- [[[[[[backend]Create Function[ [[[name]Append[" <<"]]Append["@"]]Append[type name], ("obj","newval"), ("out"), "rhope"]
-		]Set Input Type[0, type name]
-		]Set Input Type[1, type]
-		]Set Output Type[0, type name]
+		]Set Input Type[type name, 0]
+		]Set Input Type[type, 1]
+		]Set Output Type[type name, 0]
 		]Copy["obj"]
 		]Read Field["obj", name]
 	{ 
@@ -895,14 +913,16 @@
 
 Register Builtins@NProgram[prog:out]
 {
-	out <- [[[[[[[[[prog]Register Worker["+@Int32", "rhope", 2, 1]
+	out <- [[[[[[[[[[[prog]Register Worker["+@Int32", "rhope", 2, 1]
 	]Register Worker["-@Int32", "rhope", 2, 1]
 	]Register Worker["*@Int32", "rhope", 2, 1]
 	]Register Worker["/@Int32", "rhope", 2, 1]
+	]Register Worker["LShift@Int32", "rhope", 2, 1]
+	]Register Worker["RShift@Int32", "rhope", 2, 1]
 	]Register Worker["Print", "rhope", 1, 1]
 	]Register Worker["If@Yes No", "rhope", 1, 2]
 	]Register Worker["<@Int32", "rhope", 2, 1]
-	]Register Worker[">@Int32", "rhope", 1, 1]
+	]Register Worker[">@Int32", "rhope", 2, 1]
 	]Register Worker["Build", "rhope", 1, 1]
 }