diff nworker.rhope @ 75:0083b2f7b3c7

Partially working implementation of List. Modified build scripts to allow use of other compilers. Fixed some bugs involving method implementations on different types returning different numbers of outputs. Added Fold to the 'builtins' in the comipler.
author Mike Pavone <pavone@retrodev.com>
date Tue, 06 Jul 2010 07:52:59 -0400
parents a844c623c7df
children 2e2e55fc12f9
line wrap: on
line diff
--- a/nworker.rhope	Thu Jul 01 21:32:08 2010 -0400
+++ b/nworker.rhope	Tue Jul 06 07:52:59 2010 -0400
@@ -149,14 +149,16 @@
 {
 	Name
 	Convention
-	Inputs
-	Outputs
+	Inputs
+	Min Inputs
+	Outputs
+	Min Outputs
 	Is Method?
 }
 
 Worker Ref[name,convention,inputs,outputs,ismethod?:out]
 {
-	out <- [[[[[Build["Worker Ref"]]Name <<[name]]Convention <<[convention]]Inputs <<[inputs]]Outputs <<[outputs]]Is Method? <<[ismethod?]
+	out <- [[[[[[[Build["Worker Ref"]]Name <<[name]]Convention <<[convention]]Inputs <<[inputs]]Outputs <<[outputs]]Is Method? <<[ismethod?]]Min Inputs <<[inputs]]Min Outputs <<[outputs]
 }
 
 Blueprint Node Ref
@@ -182,9 +184,11 @@
 {
 	Type
 	Data
-	Inputs
+	Inputs
+	Min Inputs
 	Input Types
-	Outputs
+	Outputs
+	Min Outputs
 	Output Types
 	Wires From
 	Wires To
@@ -257,11 +261,13 @@
 
 NWorker Node[type,data,inputs,outputs:out]
 {
-	out <- [[[[[[[[[Build["NWorker Node"]
+	out <- [[[[[[[[[[[Build["NWorker Node"]
 		]Type <<[type]
 		]Data <<[data]
-		]Inputs <<[inputs]
-		]Outputs <<[outputs]
+		]Inputs <<[inputs]
+		]Min Inputs <<[inputs]
+		]Outputs <<[outputs]
+		]Min Outputs <<[outputs]
 		]Wires From <<[List of Lists[outputs]]
 		]Wires To <<[List of Lists[[inputs]+[1]]]
 		]Conditions <<[AndSet[]]
@@ -294,6 +300,12 @@
 {
 	out <- [worker]Nodes <<[[[worker]Nodes >>]Append[NWorker Node[type,data,inputs,outputs]]]
 	node index <- [[worker]Nodes >>]Length
+}
+
+Add Full Node@NWorker[worker,type,data,inputs,min inputs,outputs,min outputs:out,node index]
+{
+	out <- [worker]Nodes <<[[[worker]Nodes >>]Append[ [[NWorker Node[type,data,inputs,outputs]]Min Inputs <<[min inputs]]Min Outputs <<[min outputs] ]]
+	node index <- [[worker]Nodes >>]Length
 }
 
 Propagate Type[nodelist,dest,prog,worker,type:out]
@@ -461,7 +473,7 @@
 
 Add Worker Call@NWorker[worker,tocall:out,node index]
 {
-	out, node index <- [worker]Add Node["call",tocall,[tocall]Inputs >>,[tocall]Outputs >>]
+	out, node index <- [worker]Add Full Node["call",tocall,[tocall]Inputs >>, [tocall]Min Inputs >>,[tocall]Outputs >>, [tocall]Min Outputs >>]
 }
 
 Add Constant@NWorker[worker,constant:out,node index]
@@ -717,27 +729,67 @@
 		]Move[Result[num], out var]
 	*/
 	out <- [func]Move[Result[num], out var]	
+}
+
+Save Maybe Result[func,num,node index:out]
+{
+	out var <- [[["__result_"]Append[node index]]Append["_"]]Append[num]
+	out <- [func]Move[Check Result[num], out var]
+}
+
+Max Used Output[node,cur:out]
+{
+	If[[cur] < [0]]
+	{
+		out <- cur
+	}{
+		[[[node]Wires From >>]Index[cur]]Index[0]
+		{
+			out <- cur
+		}{
+			out <- Max Used Output[node, [cur]-[1]]
+		}
+	}
 }
 
 Compile Call Node[node,program,func,inputs,node index:out]
 {
 	If[[[node]Type >>] = ["getfield"]]
 	{
-		with call <- [func]Get Field Call[[node]Data >>, [inputs]Index[0]]
+		with call <- [func]Get Field Call[[node]Data >>, [inputs]Index[0]]
+		save outs <- [node]Outputs >>
+		out <- Val[after save]
 	}{
 		If[[[node]Type >>] = ["setfield"]]
 		{
-			with call <- [func]Set Field Call[[node]Data >>, [inputs]Index[0], [inputs]Index[1]]
+			with call <- [func]Set Field Call[[node]Data >>, [inputs]Index[0], [inputs]Index[1]]
+			save outs <- [node]Outputs >>
+			out <- Val[after save]
 		}{
 			[program]Method?[[[node]Data >>]Name >>]
 			{
 				with call <- [func]Method Call[[[node]Data >>]Name >>, inputs]
 			}{
 				with call <- [func]Call[[[node]Data >>]Name >>, inputs]
+			}
+			first unused <- [Max Used Output[node, [[node]Outputs >>]-[1]]]+[1]
+			If[[first unused] > [[node]Min Outputs >>]]
+			{
+				save outs <- [node]Min Outputs >>
+				after maybe <- Fold[["Save Maybe Result"]Set Input[2, node index], after save, Range[save outs, first unused]]
+			}{
+				save outs <- Val[first unused]
+				after maybe <- Val[after save]
+			}
+			If[[first unused] < [[node]Outputs >>]]
+			{
+				out <- [after maybe]Discard Outputs[first unused]
+			}{
+				out <- Val[after maybe]
 			}
 		}
 	}
-	out <- Fold[["Save Result"]Set Input[2, node index], with call, Range[0, [node]Outputs >>]]
+	after save <- Fold[["Save Result"]Set Input[2, node index], with call, Range[0, save outs]]
 }
 
 Compile Node@NWorker[worker,program,func,nodes,current:out,out worker]
@@ -870,8 +922,14 @@
 Node Result Vars[vars,node,index:out]
 {
 	[("call","getfield","setfield")]Find[[node]Type >>]
-	{
-		out <- Fold[["Result Var"]Set Input[2, index], vars, Range[0, [node]Outputs >>]]
+	{
+		If[[[node]Type >>]=["call"]]
+		{
+			save outs <- [Max Used Output[node, [[node]Outputs >>]-[1]]]+[1]
+		}{
+			save outs <- [node]Outputs >>
+		}
+		out <- Fold[["Result Var"]Set Input[2, index], vars, Range[0, save outs]]
 	}{
 		out <- vars
 	}
@@ -1300,19 +1358,26 @@
 }
 
 Register Worker@NProgram[prog, name, convention, inputs, outputs: out]
-{
+{
+	[[prog]Worker Refs >>]Index[name]
+	{
+		ref <- [[[[~]Inputs <<[ Max[[~]Inputs >>, inputs] ]
+		]Min Inputs <<[ Min[[~]Min Inputs >>, inputs] ]
+		]Outputs <<[ Max[[~]Outputs >>, outputs] ]
+		]Min Outputs <<[ Min[[~]Min Outputs >>, outputs] ]
+	}{
+		ref <- Worker Ref[name, convention, inputs, outputs, No]
+	}
 	after reg <- [prog]Worker Refs <<[ 
-		[ [prog]Worker Refs >> ]Set[name, 
-			Worker Ref[name, convention, inputs, outputs, No]
-		]
-	]
-		parts <- [name]Split["@"]
-		[parts]Index[1]
-		{
-			out <- [after reg]Register Method@NProgram[[parts]Index[0], convention, inputs, outputs]
-		}{
-			out <- Val[after reg]
-		}
+		[ [prog]Worker Refs >> ]Set[name, ref]
	]
+
+	parts <- [name]Split["@"]
+	[parts]Index[1]
+	{
+		out <- [after reg]Register Method@NProgram[[parts]Index[0], convention, inputs, outputs]
+	}{
+		out <- Val[after reg]
+	}
 }
 
 Register Builtins@NProgram[prog:out]