diff nworker.rhope @ 74:a844c623c7df

Add support for Worker type
author Mike Pavone <pavone@retrodev.com>
date Thu, 01 Jul 2010 21:32:08 -0400
parents 6a1a7d5cc2d9
children 0083b2f7b3c7
line wrap: on
line diff
--- a/nworker.rhope	Sat Jun 19 23:13:41 2010 -0400
+++ b/nworker.rhope	Thu Jul 01 21:32:08 2010 -0400
@@ -192,22 +192,24 @@
 }
 
 Wire To@NWorker Node[node,from,output,pre input:out]
-{
+{
+	existing cons <- [[node]Wires To >>]Index[input] {}
+	{ existing cons <- () }
 	input <- [pre input]+[1]
 	out <- [node]Wires To <<[
 		[[node]Wires To >>]Set[input,
-			[[[node]Wires To >>]Index[input]
-			]Append[Node Ref[from,output]]
+			[existing cons]Append[Node Ref[from,output]]
 		]
 	]
 }
 
 Wire From@NWorker Node[node,to,input,output:out]
-{
+{
+	existing cons <- [[node]Wires From >>]Index[output] {}
+	{ exist cons <- () }
 	out <- [node]Wires From <<[
 		[[node]Wires From >>]Set[output,
-			[[[node]Wires From >>]Index[output]
-			]Append[Node Ref[to,input]]
+			[existing cons]Append[Node Ref[to,input]]
 		]
 	]
 }
@@ -344,25 +346,31 @@
 Infer Types Node[nodelist,node,index,prog,worker:out]
 {
 	If[[[node]Type >>] = ["const"]]
-	{
+	{
+		const type <- Type Of[[node]Data >>]
 		//Temporary hack
-		If[[Type Of[[node]Data >>]] = ["Whole Number"]]
+		If[[const type] = ["Whole Number"]]
 		{
 			outtype <- Type Instance["Int32"]
 		}{
-			If[[Type Of[[node]Data >>]] = ["Type Instance"]]
+			If[[const type] = ["Type Instance"]]
 			{
 				outtype <- Type Instance["Blueprint"]
 			}{
-				If[[Type Of[[node]Data >>]] = ["Machine Integer"]]
+				If[[const type] = ["Machine Integer"]]
 				{
 					If[[[node]Data >>]Signed? >>]
 					{ base <- "Int" }
 					{ base <- "UInt" }
 					
 					outtype <- Type Instance[[base]Append[ [[node]Data >>]Size >> ]]
-				}{
-					outtype <- Type Instance[Type Of[[node]Data >>]]
+				}{
+					If[[const type] = ["Worker Literal"]]
+					{
+						outtype <- Type Instance["Worker"]
+					}{
+						outtype <- Type Instance[const type]
+					}
 				}
 			}
 		}
@@ -637,8 +645,18 @@
 						{ s <- "i" }
 						{ s <- "u" }
 						datstring <- [[[[node]Data >>]Value >>]Append[s]]Append[[[node]Data >>]Size >>]
-					}{
-						datstring <- [node]Data >>
+					}{
+						If[[Type Of[[node]Data >>]] = ["Worker Literal"]]
+						{
+							If[[[[[node]Data >>]Args >>]Length] > [0]]
+							{
+								datstring <- [[["Arg "]Append[[noderef]Index >>]]Append[" "]]Append[[worker]Name >>]
+							}{
+								datstring <- [[node]Data >>]Name >>
+							}
+						}{
+							datstring <- [node]Data >>
+						}
 					}
 				}
 				out <- Constant[[[Type Of[[node]Data >>]]Append["_"]]Append[datstring]]
@@ -767,8 +785,18 @@
 						{ s <- "i" }
 						{ s <- "u" }
 						datstring <- [[[[node]Data >>]Value >>]Append[s]]Append[[[node]Data >>]Size >>]
-					}{
-						datstring <- [node]Data >>
+					}{
+						If[[Type Of[[node]Data >>]] = ["Worker Literal"]]
+						{
+							If[[[[[node]Data >>]Args >>]Length] > [0]]
+							{
+								datstring <- [[["Arg "]Append[node index]]Append[" "]]Append[[worker]Name >>]
+							}{
+								datstring <- [[node]Data >>]Name >>
+							}
+						}{
+							datstring <- [node]Data >>
+						}
 					}
 				}
 				nfunc <- [func]Register Constant[[[Type Of[[node]Data >>]]Append["_"]]Append[datstring], [node]Data >>]
@@ -1076,8 +1104,13 @@
 }
 
 _Compile Blueprint Methods[type,junk,name:out]
-{
-	out <- [type]Add Method[name]
+{
+	If[[[name]=["Call"]] And [[[type]Name >>] = ["Worker"]]]
+	{
+		out <- type
+	}{
+		out <- [type]Add Method[name]
+	}
 }
 
 Make Init[func,field:out]
@@ -1284,13 +1317,14 @@
 
 Register Builtins@NProgram[prog:out]
 {
-	registered <- [[[[[prog]Register Worker["Print", "rhope", 1, 1]
+	registered <- [[[[[[prog]Register Worker["Print", "rhope", 1, 1]
 	]Register Worker["If@Boolean", "rhope", 1, 2]
 	]Register Worker["Build", "rhope", 1, 1]
-	]Register Worker["Blueprint Of", "rhope", 1, 1]
+	]Register Worker["Blueprint Of", "rhope", 1, 1]
+	]Register Worker["Call@Worker", "rhope", 1, 2] //We're using 2 because we need to assume that the outputs are conditional
 	]Register Number Methods
 	
-	out <- [[[[registered]Bind Worker["If@Boolean",
+	out <- [[[[[registered]Bind Worker["If@Boolean",
 		[[[[[NWorker["rhope"]
 		]Inputs <<[("condition")]
 		]Input Types <<[ [()]Append[Type Instance["Boolean"]] ]
@@ -1317,7 +1351,14 @@
 		]Input Types <<[ [()]Append[Type Instance["Any Type"]]]
 		]Outputs <<[("type")]
 		]Output Types <<[ [()]Append[Type Instance["Blueprint"]]]
-		]Builtin? <<[Yes]]
+		]Builtin? <<[Yes]]
+	]Bind Worker["Call@Worker",
+		[[[[[NWorker["rhope"]
+		]Inputs <<[("worker")]
+		]Input Types <<[ [()]Append[Type Instance["Worker"]] ]
+		]Outputs <<[("ret1","ret2")]
+		]Output Types <<[ [[()]Append[Type Instance["Any Type"]]]Append[Type Instance["Any Type"]] ]
+		]Builtin? << [Yes]]
 }
 
 Find Worker@NProgram[prog, name:out,notfound]