diff nworker.rhope @ 21:e9272f7ebd26

Limited compilation from dataflow graph to C backend
author Mike Pavone <pavone@retrodev.com>
date Tue, 23 Jun 2009 01:16:04 -0400
parents b715532225c0
children 914ad38f9b59
line wrap: on
line diff
--- a/nworker.rhope	Wed May 27 21:42:37 2009 -0400
+++ b/nworker.rhope	Tue Jun 23 01:16:04 2009 -0400
@@ -189,7 +189,6 @@
 			met? <- Yes
 		}
 	}{
-		Print[[ref]Index >>]
 		met? <- No
 	}
 }
@@ -248,20 +247,73 @@
 	out <- [worker]_Dependency Groups[no deps, no deps, [()]Append[no deps]]
 }
 
+Format Input@NWorker[worker,noderef:out]
+{
+	node <- [[worker]Nodes >>]Index[[noderef]Index >>]
+	If[[[node]Type >>] = ["call"]]
+	{
+		out <- AddRef[ [[["__result_"]Append[[noderef]Index >>]]Append["_"]]Append[[noderef]IO Num >>] ]
+	}{
+		If[[[node]Type >>] = ["input"]]
+		{
+			input name <- [[worker]Inputs >>]Index[ [node]Data >> ]
+			out <- AddRef[input name] 
+		}
+	}
+}
+
+Collect Input@NWorker[worker,nodeinput:out]
+{
+	inputchoices <- Map[nodeinput, ["Format Input"]Set Input[0, worker]]
+	[inputchoices]First
+	{
+		first <- [inputchoices]Index[~]
+		[inputchoices]Next[~]
+		{
+			out <- _Fold[inputchoices, ~, first, "OrValue"]
+		}{
+			out <- Val[first]
+		}
+	}{
+		out <- No
+	}
+}
+
+Collect Inputs@NWorker[worker,node:out]
+{
+	out <- Map[[node]Wires To>>, ["Collect Input"]Set Input[0, worker]]
+}
+
+Save Result[func,num,node index:out]
+{
+	out var <- [[["__result_"]Append[node index]]Append["_"]]Append[num]
+	out <- [[func]Allocate Var[out var, "Any Type"]
+		]Move[Result[num], out var]
+}
+
 Compile Node@NWorker[worker,program,func,nodes,current:out]
 {
 	Print[[node]Type >>]
-	node <- [[worker]Nodes >>]Index[[nodes]Index[current]]
+	node index <- [nodes]Index[current]
+	node <- [[worker]Nodes >>]Index[node index]
 	If[[[node]Type >>] = ["call"]]
 	{
+		inputs <- [worker]Collect Inputs[node]
 		[program]Method?[[[node]Data >>]Name >>]
 		{
-			nfunc <- [func]Method Call[[[node]Data >>]Name >>, ()]
+			with call <- [func]Method Call[[[node]Data >>]Name >>, inputs]
 		}{
-			nfunc <- [func]Call[[[node]Data >>]Name >>, ()]
+			with call <- [func]Call[[[node]Data >>]Name >>, inputs]
 		}
+		nfunc <- Fold[["Save Result"]Set Input[2, node index], with call, Range[0, [node]Outputs >>]]
 	}{
-		nfunc <- Val[func]
+		If[[[node]Type >>] = ["output"]]
+		{
+			inputs <- [worker]Collect Inputs[node]
+			nfunc <- [func]Move[[inputs]Index[0], [[worker]Outputs >>]Index[ [node]Data >> ] ]
+		}{
+			nfunc <- Val[func]
+		}
 	}
 	[nodes]Next[current]
 	{
@@ -288,9 +340,14 @@
 	}
 }
 
+Release Var[func,type,name:out]
+{
+	out <- [func]Release[name]
+}
+
 Compile Worker@NWorker[worker,program,name:out]
 {
-	func <- [program]Create Function[name,[worker]Inputs >>, [worker]Outputs >>, [worker]Convention >>]
+	func <- Fold["Null", [program]Create Function[name,[worker]Inputs >>, [worker]Outputs >>, [worker]Convention >>], [worker]Outputs >>]
 	groups <- [worker]Dependency Groups
 	[groups]First
 	{
@@ -298,7 +355,7 @@
 	}{
 		final func <- Val[func]
 	}
-	out <- [program]Store Function[final func]
+	out <- [program]Store Function[Fold["Release Var", final func, [final func]Variables >>]]
 }
 
 Test[:out]
@@ -320,12 +377,12 @@
 	}}}}}}
 }
 
-Test Compile[:out]
+Test Graph to Backend[:out]
 {
-	out <- [Test[]]Compile Worker[C Program[] "Test"]
+	out <- [Test[]]Compile Worker[C Program[], "Test"]
 }
 
 Main[]
 {
-	Pretty Print[Test Compile[], ""]
+	Pretty Print[Test Graph to Backend[], ""]
 }