diff nworker_c.rhope @ 118:b3f56e1d54a0

Merged changes from interpreted version of compiler to compiled version
author Mike Pavone <pavone@retrodev.com>
date Fri, 15 Oct 2010 00:55:02 -0400
parents 4d089503fb51
children cd25171e1bb2
line wrap: on
line diff
--- a/nworker_c.rhope	Thu Oct 14 22:37:20 2010 -0400
+++ b/nworker_c.rhope	Fri Oct 15 00:55:02 2010 -0400
@@ -482,9 +482,27 @@
 	out,node index <- [worker]Add Typed Input[name,number,Type Instance["Any Type"]]
 }
 
+Add Anon Input@NWorker[worker,number:out]
+{
+	If[[number]>[Length[[worker]Inputs >>]]]
+	{
+		prepped <- [worker]Add Anon Input[[number]-[1]]
+	}{
+		prepped <- Val[worker]
+	}
+	out <- out <- [[prepped]Inputs <<[[[prepped]Inputs >>]Set[number,[" unnamed"]Append[String[number]]]]
+		]Input Types <<[[[prepped]Input Types >>]Set[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]
+	If[[number]>[Length[[worker]Inputs >>]]]
+	{
+		prepped <- [worker]Add Anon Input[[number]-[1]]
+	}{
+		prepped <- Val[worker]
+	}
+	,node index <- [prepped]Add Node["input",number,0,1]
 	{ 
 		out <- [[~]Inputs <<[[[~]Inputs >>]Set[number,name]]
 		]Input Types <<[[[~]Input Types >>]Set[number,type]]
@@ -882,7 +900,7 @@
 				[conditions]For Backend
 				{
 					stream <- [[withconst]Instruction Stream
-						]Move[Constant[constname], Result Var Name[0, node index]]
+						]Move[Strip Addref[Constant[constname]], Result Var Name[0, node index]]
 					nfunc <- [withconst]Do If[~, stream]
 				}{
 					nfunc <- Val[withconst]
@@ -1082,6 +1100,27 @@
 	}
 }
 
+Release Raw Inputs[func,input type,index,inputs,outputs:out]
+{
+	If[[[input type]Variant >>] = ["Raw Pointer"]]
+	{
+		name <- [inputs]Index[index]
+		If[[input type]Mutable? >>]
+		{
+			[outputs]Find[=[?,[inputs]Index[index]]]
+			{
+				out <- func
+			}{
+				out <- [func]Release[name]	
+			}
+		}{
+			out <- [func]Release[name]
+		}
+	}{
+		out <- func
+	}
+}
+
 FParams[input:out]
 {
 	iname <- [input]Index[0]
@@ -1164,8 +1203,9 @@
 	
 	Fold[FInputs[?, ?, ?, [worker]Inputs >>], rfunc, [worker]Input Types >>]
 	{ [~]Call Foreign[name, [worker]Convention >>, Map[Zip[[worker]Inputs >>, [worker]Input Types >>], FParams[?]], rparam]
+	{ Fold[Release Raw Inputs[?, ?, ?, [worker]Inputs >>, [worker]Outputs >>], ~, [worker]Input Types >>]
 	{ Fold[Save Foreign Result[?, ?, ?, [worker]Output Types >>, [worker]Inputs >>, [worker]Input Types >>], ~, [worker]Outputs >>]
-	{ out <- [program]Store Function[~] }}}
+	{ out <- [program]Store Function[~] }}}}
 }		
 
 Compile Worker@NWorker[worker,program,name:out]
@@ -1364,8 +1404,17 @@
 {
 	//Rhope identifiers can't start with spaces, so we can use identifiers that start with spaces for special functions
 	init name <- [" init "]Append[name]
-	copy name <- [" copy "]Append[name]
-	cleanup name <- [" cleanup "]Append[name]
+	[("Array","Boxed Array","Worker")]Find[=[?,name]]
+	{
+		[("internalarraynaked","internalarrayboxed","internalworker")]Index[~]
+		{
+			copy name <- [~]Append["copy"]
+			cleanup name <- [~]Append["cleanup"]
+		}
+	}{
+		copy name <- [" copy "]Append[name]
+		cleanup name <- [" cleanup "]Append[name]
+	}
 	type <- [[[Fold[_Compile Blueprint Methods[?], Fold[_Compile Blueprint Fields[?], [backend]Create Type[name], [bp]Fields >>], [bp]Methods >>]
 	]Init <<[init name]
 	]Copy <<[copy name]
@@ -1377,14 +1426,17 @@
 Compile Special@NBlueprint[bp,backend,name:out]
 {
 	init name <- [" init "]Append[name]
-	copy name <- [" copy "]Append[name]
-	cleanup name <- [" cleanup "]Append[name]
-	got specials <- [bp]Make Special[
-				[bp]Make Special[
-					[bp]Make Special[backend, init name, name, Make Init[?]], 
-					copy name, name, Make Copy[?]], 
-			cleanup name, name, Make Cleanup[?]]
-	out <- Fold[Getters Setters[?, ?, name], got specials, [bp]Fields >>]
+	[("Array","Boxed Array","Worker")]Find[=[?,name]]
+	{
+		after copyclean <- Val[backend]
+	}{		
+		copy name <- [" copy "]Append[name]
+		cleanup name <- [" cleanup "]Append[name]
+		after copyclean <- [bp]Make Special[
+					[bp]Make Special[backend, copy name, name, Make Copy[?]], 
+				cleanup name, name, Make Cleanup[?]]
+	}
+	out <- Fold[Getters Setters[?, ?, name], [bp]Make Special[after copyclean, init name, name, Make Init[?]], [bp]Fields >>]
 }
 
 Blueprint NProgram