diff cbackend_c.rhope @ 142:7bbdc034e347

Fix some bugs. Get basic network code working (epoll listener + accept connections). Start porting webserver.
author Mike Pavone <pavone@retrodev.com>
date Sun, 21 Nov 2010 16:33:17 -0500
parents f2cb85c53ced
children f3686f60985d
line wrap: on
line diff
--- a/cbackend_c.rhope	Sat Nov 20 17:48:22 2010 -0500
+++ b/cbackend_c.rhope	Sun Nov 21 16:33:17 2010 -0500
@@ -154,11 +154,17 @@
 					[[type]Name >>]Slice[3] {}
 					{ typename <- [["int"]Append[~]]Append["_t"] }
 				}{
-					,regulartype <- [("UInt64","UInt32","UInt16","UInt8")]Find[=[[type]Name >>,?]]
+					[("UInt64","UInt32","UInt16","UInt8")]Find[=[[type]Name >>,?]]
 					{
 						primitive <- Yes
 						[[type]Name >>]Slice[4] {}
 						{ typename <- [["uint"]Append[~]]Append["_t"] }
+					}{
+						,regulartype <- If[[[type]Name >>]=["Context"]]
+						{
+							typename <- "context *"
+							primitive <- Yes
+						}
 					}
 				}
 			}
@@ -778,6 +784,15 @@
 {
 	worker <- Make Op[Strip Addref[to call], func]
 	rargs <- Map[args, Make Op[?, func]]
+	
+	If[[[[func]Variables >>]Length]+[[[func]Outputs >>]Length]]
+	{
+		valcall <- "ValCall("
+		postlude <- "ValCallPostlude("
+	}{
+		valcall <- "ValCallNoLocals("
+		postlude <- "ValCallNoLocalsPostlude("
+	}
 
 	If[[[func]Last NumParams >>] = [-1]]
 	{
@@ -803,7 +818,7 @@
 	
 	out <- [[[[Fold[_Val Function Arg C[?, ?, ?, worker], prepped, rargs]
 	]Add Raw Line[
-		[[[[[[[["ValCall("
+		[[[[[[[[valcall
 		]Append[worker]
 		]Append[", "]
 		]Append[String[[rargs]Length]]
@@ -814,7 +829,7 @@
 		]Append[")"]]
 	]Add Raw Line["DISPATCH"]
 	]Add Raw Line[
-		[[[["ValCallPostlude("
+		[[[[postlude
 		]Append[String[[func]Resume Index >>]]
 		]Append[", "]
 		]Append[Escape Rhope Name[[func]Name >>,[func]Escape Pattern >>]]
@@ -845,10 +860,14 @@
 	}
 }
 
-Func Base@C Function[func,tocall,args,type:out]
+Func Base@C Function[func,tocall,args,rtype:out]
 {
 	Print[ [[func]Name >>]Append[ [": Func Base("]Append[tocall] ] ]
 	rargs <- Map[args, Make Op[?, func]]
+	
+	If[[[[func]Variables >>]Length]+[[[func]Outputs >>]Length]]
+	{ type <- Val[rtype] }
+	{ type <- [rtype]Append["NoLocals"] }
 
 	If[[[rargs]Length] > [[func]Last NumParams >>]]
 	{	
@@ -1131,24 +1150,25 @@
 		}
 		fname <- Escape Rhope Name[[func]Name >>,[func]Escape Pattern >>]
 		param check <- Fold[Check Param Type C[?, ?, ?, func], "", [func]Input Types >>]
+		If[[[func]Last NumParams >>] = [-1]]
+		{
+			freecall <- ""
+		}{
+			freecall <- "\n\tFreeCall\n"
+		}
 		If[ [ [[[[func]Variables >>]Length]+[[[func]Outputs >>]Length]]+[[[func]Uses >>]Length] ] = [0] ]
 		{
-			out <- [[[[[[[[ [type]Append["NoLocals("]
+			out <- [[[[[[[[[ [type]Append["NoLocals("]
 				]Append[cname]
 				]Append[",\n\tNumParams "]
 				]Append[ String[[[func]Inputs >>]Length] ]
 				]Append[")\n\n"]
 				]Append[param check]
 				]Append[ [[func]Statements >>]Join[""] ]
+				]Append[freecall]
 				]Append["EndFuncNoLocals\n"]
 				]Append["DISPATCH"]
 		}{
-			If[[[func]Last NumParams >>] = [-1]]
-			{
-				freecall <- ""
-			}{
-				freecall <- "\n\tFreeCall\n"
-			}
 			If[[[func]Uses >>]Length]
 			{
 				begin trans <- [[[["\tbegin_transaction(ct, "]Append[ String[[[func]Uses >>]Length] ]]Append[", "]]Append[ [Map[Map[[func]Uses >>, Escape Rhope Name[?, [func]Escape Pattern >>]], ["gs_"]Append[?]]]Join[", "] ]]Append[");\n"]