changeset 170:ac5c2d78663f

Inline calls to If@Boolean when static type info is present
author Mike Pavone <pavone@retrodev.com>
date Sun, 08 May 2011 18:21:19 -0700
parents fd06fb07762a
children a32afde77abb
files boolean.rhope cbackend_c.rhope file.rhope nworker_c.rhope
diffstat 4 files changed, 49 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/boolean.rhope	Sun May 08 01:37:44 2011 -0700
+++ b/boolean.rhope	Sun May 08 18:21:19 2011 -0700
@@ -21,3 +21,25 @@
 	out <- [backend]Store Function[ffunc]
 }
 
+Compile Boolean Inline Check[func,op,type,in,outyes,outno:out,no inline]
+{
+	,no inline <- If[[op]=["If"]]
+	{
+		,no inline <- If[[[type]Name >>]=["Boolean"]]
+		{
+			ifyes <- [[func]Instruction Stream
+			]Move[in, outyes]
+			
+			ifno <- [[func]Instruction Stream
+			]Move[in, outno]
+			
+			,inval <- [func]Read Field[Cast[in, type] "Val"]
+			{ 
+				out <- [[~]Do If[inval, ifyes]
+					]Do If[NotCond[inval], ifno]
+			}
+			
+		}
+	}
+}
+
--- a/cbackend_c.rhope	Sun May 08 01:37:44 2011 -0700
+++ b/cbackend_c.rhope	Sun May 08 18:21:19 2011 -0700
@@ -596,6 +596,7 @@
 	out <- [func]Add Statement[[[dest]Append[" = "]]Append[source]]
 }
 
+
 Do AddRef@C Function[func,psource,pdest:out]
 {
     source <- [psource]Make Op[func] 
@@ -880,8 +881,10 @@
 	{	
 		If[[[func]Last NumParams >>] = [-1]]
 		{
+			Print["No previous PrepCall"]
 			freed <- Val[func]
 		}{
+			Print[[["Last NumParams is "]Append[String[[func]Last NumParams >>]]]Append[" adding FreeCall"]]
 			freed <- [func]Add Raw Line["FreeCall"]
 		}
 		prepped <- [[freed]Add Raw Line[ [["PrepCall("]Append[String[[rargs]Length]]]Append[")"] ]
@@ -979,12 +982,19 @@
 Do If@C Function[func,condition,stream:out]
 {
 	cond <- [condition]Make Op[func]
-	out <- [[Fold[_If C[?], [[func
+	after statements <- Fold[_If C[?], [[func
 		]Add Raw Line[ [["if("]Append[cond]]Append[")"] ]
 		]Add Raw Line["{"], [stream]Statements >>]
-		]Add Raw Line["}"]
+		
+		
+	If[[[[func]Last NumParams >>]=[-1]]And[[[stream]Last NumParams >>]>[-1]]]
+	{
+		after free <- [after statements]Add Raw Line["FreeCall"]
+	}{
+		after free <- Val[after statements]
+	}
+	out <- [[after free]Add Raw Line["}"]
 		]Resume Index <<[[stream]Resume Index >>]
-
 }
 
 Discard Outputs@C Function[func,first to discard:out]
--- a/file.rhope	Sun May 08 01:37:44 2011 -0700
+++ b/file.rhope	Sun May 08 18:21:19 2011 -0700
@@ -88,8 +88,9 @@
 			imode <- 65i32
 			type <- File Write()
 			out <- Val[ofile]
-			If[[fd]!=[-1i32]]
-			{ lseek[fd, 0i64, 2i32] }
+			{ 
+				lseek[fd, 0i64, 2i32]
+			}
 		}{
 			,error <- If[[mode]=["rw"]]
 			{ 
--- a/nworker_c.rhope	Sun May 08 01:37:44 2011 -0700
+++ b/nworker_c.rhope	Sun May 08 18:21:19 2011 -0700
@@ -903,11 +903,19 @@
 			{
 				with call <- [func]Method Call[fname, inputs]
 			}{
-				,normal call <- If[[[fname]Contains["@"]]And[[[inputs]Length]=[2]]]
+				justfunc,,,normal call <- [fname]Partition["@"]
 				{
 					//Check for inline on static method calls
 					//TODO: Deal with unused output
-					out,normal call <- Compile Number Inline Check[func, [fname]Partition["@"], [[[node]Input Types >>]Index[0]]Index[0], [[[node]Input Types >>]Index[1]]Index[0], [inputs]Index[0], [inputs]Index[1], Result Var Name[0, node index]]
+					If[[[inputs]Length]=[2]]
+					{
+						out,normal call <- Compile Number Inline Check[func, justfunc, [[[node]Input Types >>]Index[0]]Index[0], [[[node]Input Types >>]Index[1]]Index[0], [inputs]Index[0], [inputs]Index[1], Result Var Name[0, node index]]
+					}{
+						,normal call <- If[[[inputs]Length]=[1]]
+						{
+							out,normal call <- Compile Boolean Inline Check[func, justfunc, [[[node]Input Types >>]Index[0]]Index[0], [inputs]Index[0], Result Var Name[0, node index], Result Var Name[1, node index]]
+						}
+					}
 				}
 				
 				Val[normal call]
@@ -933,6 +941,7 @@
 		}
 	}
 	after save <- Fold[Save Result[?, ?, node index], with call, Range[0, save outs]]
+	Print[["Last NumParams is now "]Append[String[[after save]Last NumParams >>]]]
 }
 
 Compile Node[worker,program,func,nodes,current:out,out worker]