changeset 114:25a205094f9b

More performance optimizations
author Mike Pavone <pavone@retrodev.com>
date Wed, 13 Oct 2010 01:15:04 +0000
parents 336da6ce8174
children 04148770c229
files cbackend.rhope compile compile_old.rhope compile_old_c.rhope file.rhope nworker_c.rhope parser_old.rhope parser_old_c.rhope
diffstat 8 files changed, 101 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/cbackend.rhope	Wed Oct 06 23:48:32 2010 +0000
+++ b/cbackend.rhope	Wed Oct 13 01:15:04 2010 +0000
@@ -1613,7 +1613,7 @@
 	for (idx = 0; idx < END; ++idx)
 	{
 		if(profile_counts[idx])
-			printf(\"Func: %d\tCount: %llu\tTime: %llu\tAvg: %f\tSelf: %llu\tAvg: %f\n\", idx, profile_counts[idx], profile_totals[idx], ((double)profile_totals[idx])/((double)profile_counts[idx]), profile_selftotals[idx], ((double)profile_selftotals[idx])/((double)profile_counts[idx]));
+			printf(\"Func: %d\tCount: %llu\tTime: %llu\tAvg: %f\tSelf: %llu\tAvg: %f\\n\", idx, profile_counts[idx], profile_totals[idx], ((double)profile_totals[idx])/((double)profile_counts[idx]), profile_selftotals[idx], ((double)profile_selftotals[idx])/((double)profile_counts[idx]));
 	}
 #endif
 	if (!numret)
--- a/compile	Wed Oct 06 23:48:32 2010 +0000
+++ b/compile	Wed Oct 13 01:15:04 2010 +0000
@@ -4,7 +4,7 @@
 	rm "$1.c"
 fi
 
-./rhope -t 1 parser_old.rhope $1
+./rhope -t 1 compile_old.rhope $1
 
 if test ! -f "$1.c"; then
 	echo "Compilation to C failed"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/compile_old.rhope	Wed Oct 13 01:15:04 2010 +0000
@@ -0,0 +1,29 @@
+Import parser_old.rhope
+
+Main[args]
+{
+	fname <- [args]Index[1]
+	{
+		file <- <String@File[~]
+		,text <- [file]Get FString[[file]Length]
+		params <- New@Parser[]
+		Print[["Parsing "]Append[fname]]
+		Null[text, params, New@Parse Program[], 0]
+		{
+			Print["Parsing imports"]
+			Process Imports[~, params]
+			{
+				tree <- [~]Workers << [ Map[[~]Workers >>, ["Check Worker Literals"]Set Input[1, ~]] ]
+				{ 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"] ]] }
+		}
+	}{
+		REPL[New@Parser[]]
+	}
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/compile_old_c.rhope	Wed Oct 13 01:15:04 2010 +0000
@@ -0,0 +1,30 @@
+
+Import parser_old_c.rhope
+
+Main[args]
+{
+        fname <- [args]Index[1]
+        {
+                file <- [File[~]]Open["r"]
+                text <- String[[file]Read[[file]Length]]
+                params <- Parser[]
+                Print[["Parsing "]Append[fname]]
+                Null[text, params, Parse Program[], 0]
+                {
+                        Print["Parsing imports"]
+                        Process Imports[~, params]
+                        {
+                                tree <- [~]Workers << [ Map[[~]Workers >>, Check Worker Literals[?, ~]] ]
+                                { Print["Compiling"] }
+                        }
+                        compiled <- [Tree to Program Native[tree]]Compile Program[C Program[]]
+                        { Print["Compiled program to backend"] }
+                        outfile <- [File[ [fname]Append[".c"] ]]Truncate
+                        [[compiled]Text]Write to File[outfile] 
+                        { Print[["Wrote output to "]Append[ [fname]Append[".c"] ]] }
+                }
+        }{
+                Print["You must provide a file name to compile"]
+        }
+}
+
--- a/file.rhope	Wed Oct 06 23:48:32 2010 +0000
+++ b/file.rhope	Wed Oct 13 01:15:04 2010 +0000
@@ -219,12 +219,28 @@
 
 Write@File Write[file,data(Array):out,err]
 {
-	err <- If[write[[file]Descriptor >>, data, Int64[[data]Length >>]]] {}
+	err <- If[[write[[file]Descriptor >>, data, Int64[[data]Length >>]]]<[0i32]] {}
 	{
 		out <- file
 	}
 }
 
+Write to File@String[str,file:out,err]
+{
+	out,err <- [file]Write[[str]Buffer >>]
+}
+
+Write to File@String Slice[str,file:out,err]
+{
+	out,err <- [[str]Flatten]Write to File[file]
+}
+
+Write to File@String Cat[str,file:out,err]
+{
+	,err <- [[str]Left >>]Write to File[file]
+	{ out,err <- [[str]Right >>]Write to File[~] }
+}
+
 Close@File Write[file:out]
 {
 	fsync[[file]Descriptor >>]
--- a/nworker_c.rhope	Wed Oct 06 23:48:32 2010 +0000
+++ b/nworker_c.rhope	Wed Oct 13 01:15:04 2010 +0000
@@ -32,7 +32,18 @@
 {
 	If[[Blueprint Of[cond]] = [Condition Set()]]
 	{
-		out <- [set]Subsets <<[ [[set]Subsets>>]Set[[cond]To String, cond] ]
+		If[[[set]Condition Type >>]=[[cond]Condition Type >>]]
+		{
+			out <- [[set]Variables <<[ Combine[[set]Variables >>, [cond]Variables >>] ]
+				]Subsets <<[ Combine[[set]Subsets >>, [cond]Subsets >>] ]
+		}{
+			[cond]Empty?
+			{
+				out <- [set]Subsets <<[ [[set]Subsets>>]Set[[cond]To String, cond] ]
+			}{
+				out <- set
+			}
+		}
 	}{
 		out <- [set]Variables <<[ [[set]Variables >>]Set[cond, Yes] ]
 	}
@@ -72,47 +83,17 @@
 
 Empty?@Condition Set[set:not empty,empty]
 {
-	Print["Empty?@Condition Set"]
 	[[set]Variables >>]First
 	{
 		not empty <- Yes
 	}{
-		,empty <- [[set]Subsets >>]First Non-empty Set
+		,empty <- [[set]Subsets >>]First
 		{
 			not empty <- Yes
 		}
 	}
 }
 
-_First Non-empty Set[setlist,index:out,none]
-{
-	current <- [setlist]Index[index]
-	[[current]Variables >>]First
-	{
-		out <- index
-	}{
-		,trynext <- [[current]Subsets >>]First Non-empty Set
-		{
-			out <- index
-		}
-	}
-	Val[trynext]
-	{
-		,none <- [setlist]Next[index]
-		{
-			out,none <- _First Non-empty Set[setlist, ~]
-		}
-	}
-}
-
-First Non-empty Set[setlist:index,none]
-{
-	,none <- [setlist]First
-	{
-		index,none <- _First Non-empty Set[setlist,~]
-	}
-}
-
 For Backend@Condition Set[set:out,none]
 {
 	firstvar <- [[set]Variables >>]First
@@ -125,7 +106,7 @@
 		}
 		out <- Fold[_For Backend Subset[?, ?, [set]Condition Type >>], vars, [set]Subsets >>]
 	}{
-		[[set]Subsets >>]First Non-empty Set
+		[[set]Subsets >>]First
 		{
 			firstsub <- [[[set]Subsets >>]Index[~]]For Backend
 			[[set]Subsets >>]Next[~]
@@ -714,7 +695,7 @@
 		If[[[node]Type >>] = ["input"]]
 		{
 			input name <- [[worker]Inputs >>]Index[ [node]Data >> ]
-			[conditions]For Backend
+			[conditions]Empty?
 			{
 				out <- AddRef[Result Var Name[[noderef]IO Num >>, [noderef]Index >>]]
 			}{
@@ -723,7 +704,7 @@
 		}{
 			If[[[node]Type >>] = ["const"]]
 			{
-				[conditions]For Backend
+				[conditions]Empty?
 				{
 					out <- AddRef[Result Var Name[[noderef]IO Num >>, [noderef]Index >>]]
 				}{
@@ -1031,7 +1012,7 @@
 {
 	[("const","input")]Find[=[[node]Type >>, ?]]
 	{
-		[[node]Conditions >>]For Backend
+		[[node]Conditions >>]Empty?
 		{
 			out <- Result Var[vars, 0, index]
 		}{	
--- a/parser_old.rhope	Wed Oct 06 23:48:32 2010 +0000
+++ b/parser_old.rhope	Wed Oct 13 01:15:04 2010 +0000
@@ -1652,6 +1652,7 @@
 }
 
 
+/*
 Main[args]
 {
 	fname <- [args]Index[1]
@@ -1678,3 +1679,5 @@
 		REPL[New@Parser[]]
 	}
 }
+*/
+
--- a/parser_old_c.rhope	Wed Oct 06 23:48:32 2010 +0000
+++ b/parser_old_c.rhope	Wed Oct 13 01:15:04 2010 +0000
@@ -1578,7 +1578,7 @@
 	out <- Fold[Add If Store[?, ?, params], stores, [node]Assignments >>]
 }
 
-
+/*
 Main[args]
 {
 	fname <- [args]Index[1]
@@ -1605,3 +1605,5 @@
 		Print["You must provide a file name to compile"]
 	}
 }
+*/
+