diff parser_old_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 7bbdc034e347
line wrap: on
line diff
--- a/parser_old_c.rhope	Tue Nov 16 21:53:18 2010 -0500
+++ b/parser_old_c.rhope	Fri Nov 19 04:04:14 2010 -0500
@@ -44,11 +44,12 @@
 	Hex Escape
 	Escape Map
 	Foreign
+	Globals
 }
 
 Parser[:out]
 {
-	out <- [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[Build[Parser()]
+	out <- [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[Build[Parser()]
 	]Arg Begin << ["["]
 	]Arg End <<["]"]
 	]Line Comment <<["//"]
@@ -79,6 +80,7 @@
 	]Uses <<["uses"]
 	]Escape Map <<[[[[Dictionary[]]Set["n","\n"]]Set["r","\r"]]Set["t","\t"]]
 	]Foreign <<["Foreign"]
+	]Globals <<["Globals"]
 }
 
 Blueprint Output Reference
@@ -124,23 +126,41 @@
 	]Name <<[library]
 }
 
+Blueprint Global Store
+{
+	Name
+	Vars
+}
+
+Global Store[name:out]
+{
+	out <- [[Build[Global Store()]]Name <<[name]]Vars <<[Dictionary[]]
+}
+
 Blueprint Parse Program
 {
 	Workers
 	Imports
 	Blueprints
+	Global Stores
 	Errors
 }
 
 Parse Program[:out]
 {
-	out <- [[[[Build[Parse Program()]
+	out <- [[[[[Build[Parse Program()]
 	]Workers <<[Dictionary[]]
 	]Imports <<[Dictionary[]]
 	]Blueprints <<[Dictionary[]]
+	]Global Stores <<[Dictionary[]]
 	]Errors <<[()]
 }
 
+Add Global Store@Parse Program[tree,store:out]
+{
+	out <- [tree]Global Stores <<[ [[tree]Global Stores >>]Set[[store]Name >>, store] ]
+}
+
 Blueprint Blueprint Definition
 {
 	Name
@@ -1397,6 +1417,57 @@
 	}
 }
 
+Parse Global Vars[string,params,store:out]
+{
+	trimmed <- Left Trim[string, "\r\n\t "]
+	If[trimmed]
+	{
+		,,after <- [trimmed]Partition[[params]Assign >>]
+		{
+			varname <- Right Trim[~, "\r\n\t "]
+		} {} {
+			valstring <- [~]Partition["\n"] {} {} 
+			{
+				out <- Parse Global Vars[~,params,next store]
+			}{
+				valstring <- Val[after]
+				out <- Val[next store]
+			}
+			Val[valstring]
+			{
+				value <- [Named Pipe or Literal[Trim[~, "\r\n\t "], params]]Value >>
+				next store <- [store]Vars <<[ [[store]Vars >>]Set[varname, value] ]
+			}
+		}
+	}{
+		out <- store
+	}
+}
+
+Parse Globals[string,params,tree,lines:out]
+{
+	,after globals <- [string]Slice[[[params]Globals >>]Length]
+	[after globals]Partition[[params]Block Begin >>]
+	{
+		store <- Global Store[Trim[~, "\r\n\t "]]
+	} {} {
+		
+		[~]Partition[[params]Block End >>]
+		{
+			next tree <- [tree]Add Global Store[Parse Global Vars[~, params, store]]
+		} {} {
+			out <- Null[~,params,next tree,lines]
+		}{
+			Print["Error: Globals declaration missing block close symbol"]
+			out <- tree
+		}
+	} {
+		Print["Error: Globals declaration without block"]
+		out <- tree
+	}
+}
+
+
 Null[string,params,tree,lines:out]
 {
 	trimmed <- Comment Left Trim[string, " \n\r\t", params]
@@ -1413,11 +1484,16 @@
 			{
 				out <- Parse Foreign[trimmed, params, tree, current line]
 			}{
-				If[trimmed]
+				If[[trimmed]Starts With[[params]Globals >>]]
 				{
-					out <- Worker Name[trimmed, params, tree, current line]
+					out <- Parse Globals[trimmed, params, tree, current line]
 				}{
-					out <- tree
+					If[trimmed]
+					{
+						out <- Worker Name[trimmed, params, tree, current line]
+					}{
+						out <- tree
+					}
 				}
 			}
 		}
@@ -1483,7 +1559,7 @@
 
 Tree to Program Native[parse tree,number types:out]
 {
-	registered <- Fold[Register Workers Compile[?], [Fold[Add Blueprint Compile[?], [NProgram[]]Numtypes <<[number types], [parse tree]Blueprints >>]]Register Builtins, [parse tree]Workers >>]
+	registered <- Fold[Register Workers Compile[?], [Fold[Add Blueprint Compile[?], [[NProgram[]]Numtypes <<[number types]]Global Stores <<[[parse tree]Global Stores >>], [parse tree]Blueprints >>]]Register Builtins, [parse tree]Workers >>]
 	out <- Fold[Add Workers Compile[?], registered, [parse tree]Workers >>]
 	{ Print["Transformed AST to dataflow graph "] }
 }