changeset 107:e5627038b7e7

Broken attempt at perf opt
author Mike Pavone <pavone@retrodev.com>
date Fri, 03 Sep 2010 08:11:51 -0400
parents 439db471f595
children
files cbackend.rhope cbackend_c.rhope runtime/func.h string.rhope
diffstat 4 files changed, 63 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/cbackend.rhope	Tue Aug 24 23:22:45 2010 -0400
+++ b/cbackend.rhope	Fri Sep 03 08:11:51 2010 -0400
@@ -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/cbackend_c.rhope	Tue Aug 24 23:22:45 2010 -0400
+++ b/cbackend_c.rhope	Fri Sep 03 08:11:51 2010 -0400
@@ -75,6 +75,7 @@
 Blueprint C Type
 {
 	Name
+	Escaped
 	Fields
 	Methods
 	Init
@@ -85,7 +86,7 @@
 
 C Type[name:out]
 {
-	out <- [[[[[[Build[C Type()]]Name <<[name]]Fields <<[()]]Methods <<[()]]Init <<["NULL"]]Copy <<["NULL"]]Cleanup <<["NULL"]
+	out <- [[[[[[[Build[C Type()]]Name <<[name]]Fields <<[()]]Methods <<[()]]Init <<["NULL"]]Copy <<["NULL"]]Cleanup <<["NULL"]]Escaped <<[Escape Rhope Name[name]]
 }
 
 Add Field@C Type[ctype,name,type:out]
@@ -223,12 +224,12 @@
 {
 	If[[[[ctype]Fields >>]Length] = [1]]
 	{
-		out <- [[[[_Type Def C Type["typedef struct {\n\tobject _SP_header;\n\t", [[ctype]Fields >>]Index[0]]]Append["\n} t_"]]Append[Escape Rhope Name[[ctype]Name >>]]]Append[";"]
+		out <- [[[[_Type Def C Type["typedef struct {\n\tobject _SP_header;\n\t", [[ctype]Fields >>]Index[0]]]Append["\n} t_"]]Append[[ctype]Escaped >>]]Append[";"]
 					]Append[ 
 						[[[["typedef "
 							]Append[Rhope Type to C[ [[[ctype]Fields >>]Index[0]]Index[1] ]]
 							]Append[" nt_"]
-							]Append[Escape Rhope Name[[ctype]Name >>]]
+							]Append[[ctype]Escaped >>]
 							]Append[";"] ]
 	}{
 		//HACK!!!
@@ -239,7 +240,7 @@
 			[("Array","Boxed Array","Worker")]Find[=[[ctype]Name >>,?]]
 			{ oend <- "\nMObject(" }
 			{ oend <- "\nObject(" } 
-			out <- [Fold[_Type Def C Type[?], "OBegin", [ctype]Fields >>]]Append[ [[oend]Append[Escape Rhope Name[[ctype]Name >>]]]Append[")"] ]
+			out <- [Fold[_Type Def C Type[?], "OBegin", [ctype]Fields >>]]Append[ [[oend]Append[[ctype]Escaped >>]]Append[")"] ]
 		}
 	}
 }
@@ -276,7 +277,7 @@
 				{ 
 					If[[[ctype]Name >>]=["Boolean"]]
 					{ typename <- "int32_t" }
-					{ typename <- ["nt_"]Append[Escape Rhope Name[[ctype]Name >>]] }
+					{ typename <- ["nt_"]Append[[ctype]Escaped >>] }
 				}
 			}
 		}
@@ -320,14 +321,14 @@
 			]Set["Boolean", "TYPE_BOOLEAN"]		//9
 			]Set["Float32", "TYPE_FLOAT32"]		//10
 			]Set["Float64", "TYPE_FLOAT64"]		//11
-			]Set["Real Number", "TYPE_FLOAT64"]	//12
-			]Set["Blueprint", "TYPE_BLUEPRINT"]	//13
-			]Set["Array", "TYPE_ARRAY"]			//14
-			]Set["Boxed Array", "TYPE_BOXEDARRAY"]//15
-			]Set["Worker", "TYPE_WORKER"]		//16
-			]Set["Method Missing Exception", "TYPE_METHODMISSINGEXCEPTION"]	//17
-			]Set["Field Missing Exception", "TYPE_FIELDMISSINGEXCEPTION"]	//18
-			]Set["Wrong Type Exception", "TYPE_WRONGTYPEEXCEPTION"]]		//19
+			]Set["Real Number", "TYPE_FLOAT64"]
+			]Set["Blueprint", "TYPE_BLUEPRINT"]	//12
+			]Set["Array", "TYPE_ARRAY"]			//13
+			]Set["Boxed Array", "TYPE_BOXEDARRAY"]//14
+			]Set["Worker", "TYPE_WORKER"]		//15
+			]Set["Method Missing Exception", "TYPE_METHODMISSINGEXCEPTION"]	//16
+			]Set["Field Missing Exception", "TYPE_FIELDMISSINGEXCEPTION"]	//17
+			]Set["Wrong Type Exception", "TYPE_WRONGTYPEEXCEPTION"]]		//18
 		]Definitions << [Dictionary[]]
 		]Next ID <<[0]
 }
@@ -390,6 +391,7 @@
 Blueprint C Function
 {
 	Name
+	Escaped
 	Inputs
 	Outputs
 	Convention
@@ -412,7 +414,7 @@
 
 C Function With Registry[name,inputs,outputs,convention,registry,field reg,type reg:out]
 {
-	out <- [[[[[[[[[[[[[[Build[C Function()]
+	out <- [[[[[[[[[[[[[[[Build[C Function()]
 		]Name <<[name]
 		]Inputs <<[inputs]
 		]Outputs <<[outputs]
@@ -427,6 +429,7 @@
 		]Output Types <<[ Fold[Append[?, "Any Type"], (), outputs] ]
 		]Resume Index <<[1]
 		]Last NumParams <<[-1]
+		]Escaped <<[Escape Rhope Name[name]]
 }
 
 Set Input Type@C Function[func,type,input num:out]
@@ -446,7 +449,7 @@
 
 Allocate Var@C Function[func,name,type:out]
 {
-	out <- [func]Variables <<[ [[func]Variables >>]Set[name,type] ]
+	out <- [func]Variables <<[ [[func]Variables >>]Set[name,[[()]Append[type]]Append[Escape Rhope Name[name]]] ]
 }
 
 Add Statement@C Function[func,statement:out]
@@ -580,8 +583,10 @@
 			type <- [[func]Input Types >>]Index[~]
 			
 		}{
-			type <- [[func]Variables >>]Index[var] { Print["op refers to a var"] }
+			[[func]Variables >>]Index[var]
 			{
+				type <- [~]Index[0]
+			}{
 				[[func]Outputs >>]Find[=[var,?]]
 				{
 					type <- [[func]Output Types >>]Index[~]
@@ -736,14 +741,14 @@
 		]Append[", "]
 		]Append[String[[func]Resume Index >>]]
 		]Append[", "]
-		]Append[Escape Rhope Name[[func]Name >>]]
+		]Append[[func]Escaped >>]
 		]Append[")"]]
 	]Add Raw Line["DISPATCH"]
 	]Add Raw Line[
 		[[[["ValCallPostlude("
 		]Append[String[[func]Resume Index >>]]
 		]Append[", "]
-		]Append[Escape Rhope Name[[func]Name >>]]
+		]Append[[func]Escaped >>]
 		]Append[")"]]
 	]Resume Index <<[ [[func]Resume Index >>]+[1] ]
 }
@@ -800,7 +805,7 @@
 		]Append[", "]
 		]Append[String[[func]Resume Index >>]]
 		]Append[", "]
-		]Append[Escape Rhope Name[[func]Name >>]]
+		]Append[[func]Escaped >>]
 		]Append[")"]]
 	]Resume Index <<[ [[func]Resume Index >>]+[1] ]
 }
@@ -849,10 +854,15 @@
 		{
 			out <- [["my_cdata->params["]Append[String[~]]]Append["	]"]
 		}{
-			out <- [[["lv_"]Append[Escape Rhope Name[[func]Name >>]]]Append["->"]]Append[Escape Rhope Name[op]]
+			[[func]Variables >>]Index[op]
+			{ eop <- [~]Index[1] }
+			{ eop <- Escape Rhope Name[op] }
+			out <- [[["lv_"]Append[[func]Escaped >>]]Append["->"]]Append[eop]
 		}
 	}{
-		out <- Escape Rhope Name[op]
+		[[func]Variables >>]Index[op]
+		{ out <- [~]Index[1] }
+		{ out <- Escape Rhope Name[op] }
 	}
 }
 
@@ -860,7 +870,7 @@
 {
 	If[[[func]Convention >>] = ["rhope"]]
 	{
-		out <- [[["lv_"]Append[Escape Rhope Name[[func]Name >>]]]Append["->"]]Append[Escape Rhope Name[name]]
+		out <- [[["lv_"]Append[[func]Escaped >>]]Append["->"]]Append[Escape Rhope Name[name]]
 	}{
 		out <- Escape Rhope Name[name]
 	} 
@@ -924,7 +934,7 @@
 
 _Set Outputs C[string,inputname,inputnum,func:out]
 {
-	out <- [string]Append[[[ [ ["\tRet("]Append[String[inputnum]] ]Append[ [[", lv_"]Append[Escape Rhope Name[[func]Name >>]]]Append["->"]]]Append[Escape Rhope Name[inputname]]]Append[")\n"]]
+	out <- [string]Append[[[ [ ["\tRet("]Append[String[inputnum]] ]Append[ [[", lv_"]Append[[func]Escaped >>]]Append["->"]]]Append[Escape Rhope Name[inputname]]]Append[")\n"]]
 }
 
 Set Outputs@C Function[func:out]
@@ -945,8 +955,9 @@
 {
 	out <- [[[string]Append[ ["\t"]Append[Rhope Type to C[[[func]Output Types >>]Index[index]]] ]]Append[[" "]Append[Escape Rhope Name[varname]]]]Append[";\n"]
 }
-_Var Defs C[string,type,varname:out]
+_Var Defs C[string,info,varname:out]
 {
+	type <- [info]Index[0]
 	Print[["Variable: "]Append[varname]]
 	{
 	out <- [[[string]Append[ ["\t"]Append[Rhope Type to C[type]] ]]Append[[" "]Append[Escape Rhope Name[varname]]]]Append[";\n"]
@@ -961,7 +972,7 @@
 	{
 	If[ [[[func]Convention >>] = ["rhope"]] And [[ [[[func]Variables >>]Length]+[[[func]Outputs >>]Length] ] > [0]] ]
 	{
-		localtype <- [[[Fold[_Output Defs C[?, ?, ?, func], Fold[_Var Defs C[?],"typedef struct {\n", [func]Variables >>], [func]Outputs >>]]Append["} lt_"]]Append[Escape Rhope Name[[func]Name >>]]]Append[";\n"]
+		localtype <- [[[Fold[_Output Defs C[?, ?, ?, func], Fold[_Var Defs C[?],"typedef struct {\n", [func]Variables >>], [func]Outputs >>]]Append["} lt_"]]Append[[func]Escaped >>]]Append[";\n"]
 	}{
 		localtype <- ""
 	}
@@ -1000,7 +1011,7 @@
 		outtype <- "void "
 	}
 	out <- [[[[outtype
-			]Append[ Escape Rhope Name[[func]Name >>]]
+			]Append[ [func]Escaped >>]
 			]Append["("]
 			]Append[ [Fold[_Proto Input[?, ?, ?, [func]Input Types >>], (), [func]Inputs >>]]Join[", "] ]
 			]Append[")"]
@@ -1037,20 +1048,24 @@
 	Print[["Text@C Function: "]Append[[func]Name >>]]
 	If[ [[func]Convention >>] = ["rhope"] ]
 	{
-		before <- [[func]Name >>]Partition["@"] {} {}
+		before <- [[func]Escaped >>]Partition["AT_"] {} {}
 		{
+			Print[[[["Method "]Append[before]]Append["@"]]Append[~]]
 			type <- "MethodImpl"
-			cname <- [[[[Escape Rhope Name[before]
+			cname <- [[[[before
 				]Append[", "]
-				]Append[Escape Rhope Name[~]]
+				]Append[~]
 				]Append[", "]
 				]Append[ [[func]Type Registry >>]Type ID[~] ]
 		}{
 			type <- "Func"
 			cname <- Val[fname]
+			
 		}
-		fname <- Escape Rhope Name[[func]Name >>]
+		Print[fname]
+		fname <- Val[[func]Escaped >>]
 		param check <- Fold[Check Param Type C[?, ?, ?, func], "", [func]Input Types >>]
+		Print[param check]
 		If[ [ [[[func]Variables >>]Length]+[[[func]Outputs >>]Length] ] = [0] ]
 		{
 			out <- [[[[[[[[ [type]Append["NoLocals("]
@@ -1069,6 +1084,7 @@
 			}{
 				freecall <- "\n\tFreeCall\n"
 			}
+			Print[freecall]
 			out <- [[[[[[[[[[ [type]Append["("]
 				]Append[cname]
 				]Append[",\n\tNumParams "]
@@ -1080,6 +1096,7 @@
 				]Append[[func]Set Outputs]
 				]Append[[["EndFunc("]Append[fname]]Append[")\n"]]
 				]Append["DISPATCH"]
+			{ Print[~] }
 		}
 	}{
 		
@@ -1381,7 +1398,7 @@
 	{
 		out <- text
 	}{
-		out <- [text]Append[[["\tFuncDef("]Append[Escape Rhope Name[[func]Name >>]]]Append[")\n"]]
+		out <- [text]Append[[["\tFuncDef("]Append[[func]Escaped >>]]Append[")\n"]]
 	}
 }
 
--- a/runtime/func.h	Tue Aug 24 23:22:45 2010 -0400
+++ b/runtime/func.h	Fri Sep 03 08:11:51 2010 -0400
@@ -233,7 +233,7 @@
 			if(FUNC_ ## tocall == FUNC_ ## myname) {\
 				PAUSE_SELF\
 				AND_TOTAL\
-			} else if (FUNC_ ## tocall != FUNC_PL_ && FUNC_ ## tocall != FUNC_MN_ && FUNC_ ## tocall != FUNC_TM_ && FUNC_ ## tocall != FUNC_DV_ && FUNC_ ## tocall != FUNC_If) {\
+			} else if (FUNC_ ## tocall != FUNC_PL_ && FUNC_ ## tocall != FUNC_MN_ && FUNC_ ## tocall != FUNC_TM_ && FUNC_ ## tocall != FUNC_DV_ && FUNC_ ## tocall != FUNC_If && FUNC_ ## tocall != FUNC_LT_ && FUNC_ ## tocall != FUNC_GT_ && FUNC_ ## tocall != FUNC_EQ_) {\
 				PAUSE_SELF\
 			}\
 			goto sf_ ## tocall;\
@@ -242,7 +242,7 @@
 			if(FUNC_ ## tocall == FUNC_ ## myname) {\
 				RESUME_SELF\
 				AND_RESUME_TOTAL\
-			} else if (FUNC_ ## tocall != FUNC_PL_ && FUNC_ ## tocall != FUNC_MN_ && FUNC_ ## tocall != FUNC_TM_ && FUNC_ ## tocall != FUNC_DV_ && FUNC_ ## tocall != FUNC_If) {\
+			} else if (FUNC_ ## tocall != FUNC_PL_ && FUNC_ ## tocall != FUNC_MN_ && FUNC_ ## tocall != FUNC_TM_ && FUNC_ ## tocall != FUNC_DV_ && FUNC_ ## tocall != FUNC_If && FUNC_ ## tocall != FUNC_LT_ && FUNC_ ## tocall != FUNC_GT_ && FUNC_ ## tocall != FUNC_EQ_) {\
 				RESUME_SELF\
 			}\
 			lv_ ## myname = cdata->vars;
--- a/string.rhope	Tue Aug 24 23:22:45 2010 -0400
+++ b/string.rhope	Fri Sep 03 08:11:51 2010 -0400
@@ -439,7 +439,12 @@
 			left <- ""
 			right <- string
 		}{
-			sliceoffset <- CPOff to BOff[[string]Buffer >>, 0i32, 0i32, slicepoint]
+			If[[[string]Length >>]=[[string]Byte Length]]
+			{
+				sliceoffset <- Val[slicepoint]
+			}{
+				sliceoffset <- CPOff to BOff[[string]Buffer >>, 0i32, 0i32, slicepoint]
+			}
 			left <- String Slice[string, 0i32, slicepoint, sliceoffset]
 			right <- String Slice[string, sliceoffset, [[string]Length >>]-[slicepoint], [[[string]Buffer >>]Length]-[sliceoffset]]
 		}
@@ -643,7 +648,12 @@
 			left <- ""
 			right <- string
 		}{
-			sliceoffset <- CPOff to BOff[[[string]Source >>]Buffer >>, 0i32, [string]Offset >>, slicepoint]
+			If[[[string]Length >>]=[[string]ByteLen >>]]
+			{
+				sliceoffset <- [[string]Offset >>]+[slicepoint]
+			}{
+				sliceoffset <- CPOff to BOff[[[string]Source >>]Buffer >>, 0i32, [string]Offset >>, slicepoint]
+			}
 			left <- String Slice[[string]Source >>, [string]Offset >>, slicepoint, [sliceoffset]-[[string]Offset >>]]
 			right <- String Slice[[string]Source >>, sliceoffset, [[string]Length >>]-[slicepoint], [[string]Byte Length]-[[sliceoffset]-[[string]Offset >>]]]
 		}