diff parser_old.rhope @ 69:d0ce696786cc

Clean up debug print statements a bit. Fix bug that prevented workers that took no inputs from working. Remove workaround in Array for said bug.
author Mike Pavone <pavone@retrodev.com>
date Wed, 16 Jun 2010 04:36:08 +0000
parents 079200bc3e75
children 6a1a7d5cc2d9
line wrap: on
line diff
--- a/parser_old.rhope	Mon Jun 07 15:36:04 2010 -0400
+++ b/parser_old.rhope	Wed Jun 16 04:36:08 2010 +0000
@@ -215,8 +215,6 @@
 
 Add Blocks to Worker[blocks,worker,program,parse worker,refs:out blocks,out worker,out refs]
 {
-	Print["Add Blocks to Worker"]
-	{
 	[blocks]First
 	{
 		out blocks, out worker, out refs <- _Add Blocks to Worker[blocks, worker, program, parse worker, ~, refs]
@@ -225,7 +223,6 @@
 		out worker <- worker
 		out refs <- refs
 	}
-	}
 }
 
 Add to Worker@Worker Node[node,worker,program,parse worker,refs:out node,out worker,out refs]
@@ -250,87 +247,37 @@
 
 Add Multi Wire[worker,ref,junk,end index,input num:out]
 {
-	Print[
-		[[[[[[["Wire: "
-			]Append[ [ref]Index >> ]
-			]Append[","]
-			]Append[ [ref]Output Number >>]
-			]Append[" to "]
-			]Append[end index]
-			]Append[","]
-			]Append[input num]
-		]
 	out <- [worker]Add Wire[[ref]Index >>, [ref]Output Number >>, end index, input num]
-	{ Print["Wire added"] }
 }
 
 Add Param Wire[worker,param,input num,end index,blocks,parse worker,assignments:out]
 {
-	Print[[[["param type: "
-		]Append[Type Of[param]]
-		]Append[", dest index:"]
-		]Append[end index]]
-	{
 	param worker, start index, output num <- [param]Add Wires[worker, blocks, parse worker, assignments] {}
 	{
-		Print[
-		[[[[[[["Wire: "
-			]Append[start index ]
-			]Append[","]
-			]Append[output num]
-			]Append[" to "]
-			]Append[end index]
-			]Append[","]
-			]Append[input num]
-		] {
 		out <- [param worker]Add Wire[start index, output num, end index, input num]
-		{ Print["wire done, Add Param Wire"] }
-		}
 	}{}{
 		out <- Fold[[["Add Multi Wire"]Set Input[3, end index]]Set Input[4, input num], param worker, ~]
 	}
-	}
 }
 
 _Add Block Wire[worker,node,junk,blocks,parse worker,assignments:out]
 {
-	Print[["_Add Block Wire "]Append[Type Of[node]]]
-	{
-		out <- [node]Add Wires[worker, blocks, parse worker, assignments]
-		{ Print[["_Add Block Wire done "]Append[Type Of[node]]] }
-	}
+	out <- [node]Add Wires[worker, blocks, parse worker, assignments]
 }
 
 Add Block Wire[worker,block nodes,output num,parent index,existing blocks,parse worker,assignments:out]
 {
-	Print["Add Block Wire"]
-	{
 	blocks <- [existing blocks]Append[New@Output Reference[parent index, output num]]
 	out <- Fold[[[["_Add Block Wire"]Set Input[3, blocks]]Set Input[4, parse worker]]Set Input[5, assignments], worker, block nodes]
-	{ Print["done: Add Block Wire"] }
-	}
 }
 
 Assignments Add Wires[worker,assignment,output num,parse worker,start index:out worker]
 {
-	Print[["Assignments Add Wires: "]Append[assignment]]
-	{
 	[[parse worker]Outputs >>]Find[assignment]
 	{
 		,output index <- [worker]Add Typed Output[assignment, ~, [[parse worker]Output Types >>]Index[~]]
 		{
-			Print[
-				[[[[[[["Wire: "
-					]Append[ start index ]
-					]Append[","]
-					]Append[ output num]
-					]Append[" to "]
-					]Append[output index]
-					]Append[","]
-					]Append[ 0 ]
-				]
 			out worker <- [~]Add Wire[start index, output num, output index, 0]
-			{ Print["wire done, Assignments Add Wires 1"] }
 		}
 	}{
 		//Ugly hack alert!
@@ -340,15 +287,12 @@
 			,global index <- [worker]Add Global Set[[parts]Index[0], [parts]Index[1]]
 			{
 				out worker <- [~]Add Wire[start index, output num, global index, 0]
-				{ Print["wire done, Assignments Add Wires 2"] }
 			}
 		}{
-			Print["Pipe assignment, do nothing"]
-			{ out worker <- worker }
+			out worker <- worker
 		}
 	}
 }
-}
 
 Has Block@Worker Node[junk:out,unused]
 {
@@ -382,22 +326,15 @@
 
 Add Wires@Worker Node[node,worker,blocks,parse worker,assignments:worker,index,num,unused]
 {
-	Print["Add Wires@Worker Node"]
-	{
 	worker,index,num <- Add Wires Worker or Field[node, worker, blocks, parse worker, assignments]
-	}
 }
 
 Add Wires Worker or Field[node,worker,blocks,parse worker,assignments:worker,index,num,unused]
 {
-	Print["Add Wires Worker or Field"]
-	{
 	Fold[[["Assignments Add Wires"]Set Input[3, parse worker]]Set Input[4, [node]Index >>], worker, [node]Assignments >>]
 	{ 
-		Print["Assignments Add Wires done"]
 		Fold[[[[["Add Block Wire"]Set Input[3, [node]Index >>]]Set Input[4, blocks]]Set Input[5, parse worker]]Set Input[6, assignments], ~, [node]Blocks >>]
 		{ 
-			Print["Add Block Wire fold done"]
 			params worker <- Fold[[[[["Add Param Wire"]Set Input[3, [node]Index >>]]Set Input[4, blocks]]Set Input[5, parse worker]]Set Input[6, assignments], ~, [node]Params >>] }}
 	If[Has Block Params[[node]Params >>]]
 	{
@@ -412,7 +349,6 @@
 	}
 	index <- [node]Index >>
 	num <- 0
-	}
 }
 
 Blueprint Field Node
@@ -457,10 +393,7 @@
 
 Add Wires@Field Node[node,worker,blocks,parse worker,assignments:worker,index,num]
 {
-	Print["Add Wires@Field Node"]
-	{
 	worker,index,num <- Add Wires Worker or Field[node, worker, blocks, parse worker, assignments]
-	}
 }
 
 Blueprint Named Pipe Node
@@ -498,7 +431,6 @@
 	{
 		after add <- [worker]Add Typed Input[[node]Name >>, ~, [[parse worker]Input Types>>]Index[~]] {}
 		{
-			Print[["Added input, node:"]Append[~]]
 			assign refs <- Fold[[["Assignment Save Reference"]Set Input[3, parse worker]]Set Input[4, ~], refs, [node]Assignments >>]
 			index node <- [node]Index <<[~]
 		}
@@ -514,8 +446,6 @@
 
 Add Wires@Named Pipe Node[node,worker,blocks,parse worker,assignments:worker,index,num,reflist]
 {
-	Print["Add Wires@Named Pipe Node"]
-	{
 	reflist <- [assignments]Index[[node]Name >>]
 	{ 
 		//TODO: Fix support for a named pipe with a block
@@ -549,7 +479,6 @@
 			}
 		}
 	}
-	}
 	index <- Val[my index]
 	
 	worker <- Fold[[[[["Add Block Wire"]Set Input[3, my index]]Set Input[4, blocks]]Set Input[5, parse worker]]Set Input[6, assignments], wires worker, [node]Blocks >>]
@@ -618,29 +547,20 @@
 
 Add Wires@Literal Node[node,worker,blocks,parse worker,assignments:worker,index,num,unused]
 {
-	Print["Add Wires@Literal Node"]
-	{
 	worker,index,num <- Add Wires Literal or Global[node, worker, blocks, parse worker, assignments]
-	}
 }
 
 Add Wires Literal or Global[node,worker,blocks,parse worker,junk:worker,index,num,unused]
 {
-	Print["Add Wires Literal or Global"]
-	{
 	assignments worker <- Fold[[["Assignments Add Wires"]Set Input[3, parse worker]]Set Input[4, [node]Index >>], worker, [node]Assignments >>]
-	{ Print["Done fold Assignments Add Wires"] }
 	[blocks]Peek
 	{
-		Print["Add wire"]
 		worker <- [assignments worker]Add Wire[[~]Index >>, [~]Output Number>>, [node]Index >>, [0]-[1]]
-		{ Print["Add wire done"] }
 	}{
 		worker <- Val[assignments worker]
 	}
 	index <- [node]Index >>
 	num <- 0
-	}
 }
 
 Blueprint Block Node
@@ -1210,8 +1130,15 @@
 	delims <- [[()]Append[[params]List Begin >>]]Append[[params]List Delim >>]
 	after,param name <-[text]Get DString[delims] {}
 	{
-		nextlist <- [paramlist]Append[Trim[~, "\r\n\t "]]
-		next types <-  [typelist]Append[paramtype]
+		tname <- Trim[~, "\r\n\t "]
+		If[[tname] = [""]]
+		{
+			nextlist <- Val[paramlist]
+			next types <- Val[typelist]
+		}{
+			nextlist <- [paramlist]Append[tname]
+			next types <-  [typelist]Append[paramtype]
+		}
 	}{
 		If[[~] = [[params]List Begin >>]]
 		{
@@ -1271,7 +1198,6 @@
 	,whitespace name <- [string]Get Comment DString[[params]Arg Begin >>, params]
 	{
 		worker name <- Trim[whitespace name, "\n\r\t "]
-		Print[["Parsing worker: "]Append[worker name]]
 		in out <- [params]In Out Delim >>
 		arg end <- [params]Arg End >>
 		delims <- [[()]Append[in out]]Append[arg end]
@@ -1286,8 +1212,6 @@
 				rest <- [after]Get Comment DString[arg end, params] {}
 				{
 					outputs,output types <- Parse Param List[~, (), (), params]
-					{ Print["got outputs"] }
-					{ Print["got output types"] }
 				}
 			}{
 				rest <- Val[after]
@@ -1295,8 +1219,6 @@
 				output types <- ()
 			}
 			inputs,input types <- Parse Param List[arglist, (), (), params]
-			{ Print["got inputs"] }
-			{ Print["got input types"] }
 			worker <- New@Parse Worker[worker name, inputs, outputs, input types, output types, 0]
 		}
 	}{}{}{
@@ -1308,7 +1230,6 @@
 {
 	,after arglist <- Worker Declaration[string, params]
 	{
-		Print["Got parse worker"]
 		worker name <- [~]Name >>
 		body text, modifiers <- [after arglist]Get Comment DString[[params]Block Begin >>, params]
 		modified <- Process Modifiers[~, params, modifiers]
@@ -1335,9 +1256,7 @@
 
 Parse Foreign[string,params,tree,lines:out]
 {	
-	Print["Foreign block"]
 	,after foreign <- [string]Slice[[[params]Foreign >>]Length]
-	Print[[after foreign]Slice[20]]
 	[after foreign]Get Comment DString[[params]Blueprint Type Delim >>, params]
 	{
 		[~]Get Comment DString[[params]Block Begin >>, params]
@@ -1347,13 +1266,10 @@
 		{ lib <- Trim[~, "\r\n\t "] }
 	}
 	{ language <- Trim[~, "\r\n\t "] }
-	Print[[[["Language: "]Append[language]]Append[" Library: "]]Append[lib]]
-	{
 	Parse Foreign Worker[tree, body, New Foreign Lib[language, lib], params]
 	{ 
 		out <- Null[rest, params, ~, 0]
 	}
-	}
 }
 
 Null[string,params,tree,lines:out]
@@ -1392,7 +1308,6 @@
 
 Register Workers Compile[prog, worker, name:out]
 {
-	Print[["Registering "]Append[name]]
 	If[[ Type Of[[worker]Trees >>] ] = ["Foreign Lib"]]
 	{ convention <- Val[[[worker]Trees >>]Language >>] }
 	{ convention <- "rhope" }
@@ -1401,8 +1316,6 @@
 
 Add Workers Compile[prog, worker, name:out]
 {
-	Print[["Add Workers Compile: "]Append[name]]
-	{
 		If[[Type Of[[worker]Trees >>]] = ["Foreign Lib"]]
 		{
 			//TODO: Handle foreign func
@@ -1418,21 +1331,15 @@
 			final nworker <- Fold[[["Add Wires Helper"]Set Input[3, worker]]Set Input[4, refs], nworker, trees]
 		}
 		out <- [prog]Bind Worker[name, final nworker]
-	}
 }
 
 Add Wires Helper[worker,node,unused,parse worker,assignments:out]
 {
-	Print["Add Wires Helper"]
-	{
 	out <- [node]Add Wires[worker, (), parse worker, assignments]
-	{ Print["Add Wires Helper Done"] }
-	}
 }
 
 Add Contents[parse worker,name,program:out,key]
 {
-	Print[["Add Contents: "]Append[name]]
 	worker <- [[program]Find Worker[name]]Uses[[parse worker]Uses Stores >>]
 	trees, contents worker, refs <- Add List to Worker[[parse worker]Trees >>, worker, program, parse worker, Dictionary[]]
 	Fold[[["Add Wires Helper"]Set Input[3, parse worker]]Set Input[4, refs], contents worker, trees]
@@ -1463,22 +1370,17 @@
 	after blueprint <- Fold["Add Blueprint", program, [parse tree]Blueprints >>]
 	[[parse tree]Workers >>]First
 	{
-		Print["Adding workers"]
 		prog <- Add Workers[[parse tree]Workers >>, ~, after blueprint]
-		{ Print["Add Workers done"] }
 	}{
 		Print["No workers!"]
 	}
 	Key Value Map[[parse tree]Workers >>, ["Add Contents"]Set Input[2, prog]]
-	{ Print["Done Add Contents"] }
 	out <- Val[prog]
 }
 
 Tree to Program[parse tree:out]
 {
-	Print["Tree to Program"]
 	out <- _Tree to Program[parse tree, [Program[]]Add Builtins]
-	{ Print["done"] }
 }
 
 Tree to Program Native[parse tree:out]
@@ -1572,29 +1474,18 @@
 				{ _REPL[params, _Tree to Program[import tree, prog], ~] }
 			}
 		}{
-			Print["Expression"]
 			trees <- Worker Body[[line]Append["}"], params, ()]
-			{ Print["Parse done"] }
 			tree <- [New@Worker Node["Val", [()]Append[[trees]Index[0]]]]Assignments <<[("__out")]
-			{ Print["Constructed new tree"] }
 			this stores <- [[tree]Gather Stores[params, Dictionary[]]]Keys
-			{ Print["Got stores"] }
 			next stores <- Fold["_Init Used Store", stores, this stores]
 			{
-				Print["Initialized stores"]
 				pworker <- [[New@Parse Worker["__Eval", (), ("__out"), 0]]Trees <<[[()]Append[tree]]]Uses Stores <<[this stores]
-				{ Print["Constructed parse worker"] }
 			}
 			[[prog]Find Worker["__Eval"]]Clear
 			{ 
-				Print["Cleared worker"]
 				Add Contents[pworker, "__Eval", prog]
 				{ 
-					Print["Added Contents"]
-					Pretty Print[[[[prog]Find Worker["__Eval"]]Do[()]]Index[0], ""]
-					{ 
-						Print["Finished executeion"]
-						_REPL[params, prog, next stores] } } }
+						_REPL[params, prog, next stores] } }
 		}
 	}
 }
@@ -1654,7 +1545,6 @@
 
 Main[args]
 {
-	Print["start"]
 	fname <- [args]Index[1]
 	{
 		file <- <String@File[~]
@@ -1667,6 +1557,7 @@
 			tree <- Process Imports[~, params]
 			{ Print["Compiling"] }
 			compiled <- [Tree to Program Native[tree]]Compile Program[C Program[]]
+			{ Print["Compiled program to backend"] }
 			outfile <- <String@File[ [fname]Append[".c"] ]
 			[outfile]Put String[ [compiled]Text ]
 			{ Print[["Wrote output to "]Append[ [fname]Append[".c"] ]] }