diff nworker_c.rhope @ 139:a68e6828d896

Global stores and transactions are working. Definately leaks memory on retries. Probably a fair number of bugs to work out. However, a basic test program works.
author Mike Pavone <pavone@retrodev.com>
date Fri, 19 Nov 2010 04:04:14 -0500
parents fc3815b7462f
children c14698c512f1
line wrap: on
line diff
--- a/nworker_c.rhope	Tue Nov 16 21:53:18 2010 -0500
+++ b/nworker_c.rhope	Fri Nov 19 04:04:14 2010 -0500
@@ -296,7 +296,7 @@
 
 NWorker[convention:out]
 {
-	out <- [[[[[[[[[Build[NWorker()]]Convention <<[convention]]Nodes <<[()]]Inputs <<[()]]Outputs <<[()]]Input Types <<[()]]Output Types <<[()]]Name <<["Anonymous"]]Builtin? <<[No]]Library << [""]
+	out <- [[[[[[[[[[Build[NWorker()]]Convention <<[convention]]Nodes <<[()]]Inputs <<[()]]Outputs <<[()]]Input Types <<[()]]Output Types <<[()]]Name <<["Anonymous"]]Builtin? <<[No]]Library << [""]]Uses <<[()]
 }
 
 String@NWorker[worker:out]
@@ -393,62 +393,68 @@
 				out <- nodelist
 
 			}{
-				[node]Has Input Types?
+				If[[[node]Type >>] = ["getglobal"]]
 				{
-					If[[[node]Type >>] = ["setfield"]]
+					nextnode <- [node]Output Types <<[ [()]Append[Type Instance["Any Type"]] ]
+				}{
+					[node]Has Input Types?
 					{
-						nextnode <- [node]Output Types <<[ [()]Append[ [[[node]Input Types >>]Index[0]]Index[0] ] ]
-					}{
-						If[[[node]Type >>] = ["getfield"]]
+						If[[[node]Type >>] = ["setfield"]]
 						{
-							type <- [[[node]Input Types >>]Index[0]]Index[0]
-							If[[[type]Name >>] = ["Any Type"]]
+							nextnode <- [node]Output Types <<[ [()]Append[ [[[node]Input Types >>]Index[0]]Index[0] ] ]
+						}{
+							If[[[node]Type >>] = ["getfield"]]
 							{
-								outtype <- Val[type]
-							}{
-								outtype <- [prog]Find Field[[node]Data >>, type] {}
+								type <- [[[node]Input Types >>]Index[0]]Index[0]
+								If[[[type]Name >>] = ["Any Type"]]
 								{
-									//TODO: Return errors rather than printing them
-									Print[
-										[[[[["Type "
-										]Append[[type]Name >>]
-										]Append[" does not have a field named "]
-										]Append[[node]Data >>]
-										]Append[" in worker "]
-										]Append[worker name]]
-								}
-							}
-							nextnode <- [node]Output Types <<[ [()]Append[outtype] ]
-						}{
-							worker name <- [[node]Data >>]Name >>
-							[prog]Is Method?[worker name]
-							{
-								first arg type <- [[[node]Input Types >>]Index[0]]Index[0]
-								If[[[first arg type]Name >>] = ["Any Type"]]
-								{
-									outtypes <- Fold[Append[?, Type Instance["Any Type"]], (), Range[0, [node]Inputs >>]]
+									outtype <- Val[type]
 								}{
-									worker def <- [prog]Find Method[worker name, first arg type] {}
+									outtype <- [prog]Find Field[[node]Data >>, type] {}
 									{
-										//TODO: Return errors instead of printing them
+										//TODO: Return errors rather than printing them
 										Print[
 											[[[[["Type "
-											]Append[[first arg type]Name >>]
-											]Append[" does not support method "]
-											]Append[worker name]
+											]Append[[type]Name >>]
+											]Append[" does not have a field named "]
+											]Append[[node]Data >>]
 											]Append[" in worker "]
-											]Append[ [worker]Name >> ]]
+											]Append[worker name]]
 									}
 								}
+								nextnode <- [node]Output Types <<[ [()]Append[outtype] ]
 							}{
-								worker def <- [prog]Find Worker Def[worker name]
+							
+								worker name <- [[node]Data >>]Name >>
+								[prog]Is Method?[worker name]
+								{
+									first arg type <- [[[node]Input Types >>]Index[0]]Index[0]
+									If[[[first arg type]Name >>] = ["Any Type"]]
+									{
+										outtypes <- Fold[Append[?, Type Instance["Any Type"]], (), Range[0, [node]Inputs >>]]
+									}{
+										worker def <- [prog]Find Method[worker name, first arg type] {}
+										{
+											//TODO: Return errors instead of printing them
+											Print[
+												[[[[["Type "
+												]Append[[first arg type]Name >>]
+												]Append[" does not support method "]
+												]Append[worker name]
+												]Append[" in worker "]
+												]Append[ [worker]Name >> ]]
+										}
+									}
+								}{
+									worker def <- [prog]Find Worker Def[worker name]
+								}
+								outtypes <- [worker def]Output Types >>
+								nextnode <- [node]Output Types <<[ outtypes ]
 							}
-							outtypes <- [worker def]Output Types >>
-							nextnode <- [node]Output Types <<[ outtypes ]
 						}
+					}{
+						out <- nodelist
 					}
-				}{
-					out <- nodelist
 				}
 			}
 		}
@@ -737,6 +743,16 @@
 				}{
 					out <- Constant[Const Name[[node]Data >>, [noderef]Index >>, [worker]Name >>]]
 				}
+			}{
+				If[[[node]Type >>]=["getglobal"]]
+				{
+					[conditions]Empty?
+					{
+						out <- AddRef[Result Var Name[[noderef]IO Num >>, [noderef]Index >>]]
+					}{
+						out <- AddRef[Global Get[[[node]Data >>]Index[0], [[node]Data >>]Index[1]]]
+					}
+				}
 			}
 		}
 	}
@@ -905,14 +921,40 @@
 					nfunc <- Val[withconst]
 				}
 			}{
-				[conditions]For Backend
+				If[[[node]Type >>]=["getglobal"]]
 				{
-					input name <- [[worker]Inputs >>]Index[ [node]Data >> ]
-					stream <- [[func]Instruction Stream
-						]Move[input name, Result Var Name[0, node index]]
-					nfunc <- [func]Do If[~, stream]
+					[conditions]For Backend
+					{
+						stream <- [[func]Instruction Stream
+							]Move[Global Get[[[node]Data >>]Index[0], [[node]Data >>]Index[1]], Result Var Name[0, node index]]
+						nfunc <- [func]Do If[~, stream]
+					}{
+						nfunc <- Val[func]
+					}
 				}{
-					nfunc <- Val[func]
+					If[[[node]Type >>]=["setglobal"]]
+					{
+						inputs <- [worker]Collect Inputs[node]
+						[conditions]For Backend
+						{
+							stream <- [func]Instruction Stream
+							nfunc <- [func]Do If[~, nstream]
+						}{
+							stream <- Val[func]
+							nfunc <- Val[nstream]
+						}
+						nstream <- [stream]Set Global[[[node]Data >>]Index[0], [[node]Data >>]Index[1], [inputs]Index[0]]
+					}{
+						[conditions]For Backend
+						{
+							input name <- [[worker]Inputs >>]Index[ [node]Data >> ]
+							stream <- [[func]Instruction Stream
+								]Move[input name, Result Var Name[0, node index]]
+							nfunc <- [func]Do If[~, stream]
+						}{
+							nfunc <- Val[func]
+						}
+					}
 				}
 			}
 			
@@ -1225,7 +1267,7 @@
 	}{
 		If[[[worker]Library >>] = [""]]
 		{	
-			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 >>]
+			ifunc <- Fold[Set Output Type[?], Fold[Set Input Type[?], [[program]Create Function[name,[worker]Inputs >>, [worker]Outputs >>, [worker]Convention >>]]Uses <<[[worker]Uses >>], [worker]Input Types >>], [worker]Output Types >>]
 			
 			groups <- [worker]Dependency Groups
 			
@@ -1450,15 +1492,17 @@
 	Workers
 	Worker Refs
 	Numtypes
+	Global Stores
 }
 
 NProgram[:out]
 {
-	out <- [[[[Build[NProgram()]
+	out <- [[[[[Build[NProgram()]
 		]Blueprints <<[Dictionary[]]
 		]Workers <<[Dictionary[]]
 		]Worker Refs <<[Dictionary[]]
 		]Numtypes << [("Int8","Int16","Int32","Int64","UInt8","UInt16","UInt32","UInt64")]
+		]Global Stores <<[Dictionary[]]
 }
 
 Supported Number Types@NProgram[program:out]
@@ -1507,7 +1551,7 @@
 
 Compile Program@NProgram[prog, backend:out]
 {
-	backend with bps <- Generate Boolean Methods[Generate Number Methods[Fold[_Compile Program BP Special[?], Fold[_Compile Program BP[?], backend, [prog]Blueprints >>], [prog]Blueprints >>]]]
+	backend with bps <- Generate Boolean Methods[Generate Number Methods[Fold[_Compile Program BP Special[?], Fold[_Compile Program BP[?], [backend]Global Stores <<[[prog]Global Stores >>], [prog]Blueprints >>], [prog]Blueprints >>]]]
 	workers with infer <- Map[[prog]Workers >>, Infer Types[?, prog]]
 	out <- Fold[_Compile Program[?], backend with bps,  workers with infer]
 }