diff cbackend.rhope @ 42:aabda74c7a88

Fields can now be defined to have naked primitive types
author Mike Pavone <pavone@retrodev.com>
date Tue, 13 Oct 2009 00:07:34 -0400
parents 789a146a48e1
children a24eb366195c
line wrap: on
line diff
--- a/cbackend.rhope	Sat Oct 10 16:40:50 2009 -0400
+++ b/cbackend.rhope	Tue Oct 13 00:07:34 2009 -0400
@@ -230,7 +230,12 @@
 
 Type Def@C Type[ctype:out]
 {
-	out <- [Fold["_Type Def C Type", "OBegin", [ctype]Fields >>]]Append[ [["\nObject("]Append[Escape Rhope Name[[ctype]Name >>]]]Append[")"] ]
+	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[[ctype]Name >>]]Append[";"]
+	}{
+		out <- [Fold["_Type Def C Type", "OBegin", [ctype]Fields >>]]Append[ [["\nObject("]Append[Escape Rhope Name[[ctype]Name >>]]]Append[")"] ]
+	}
 }
 
 _Type Init C[type name,method reg,text,method:out]
@@ -334,6 +339,16 @@
 	out,notfound <- [[reg]Lookup >>]Index[name]
 }
 
+Simple Type?@C Type Registry[reg,name:yep,nope,notfound]
+{
+	Print[["Symple Type?: "]Append[name]]
+	,notfound <- [[reg]Definitions >>]Index[name]
+	{
+		Print["found type"]
+		yep,nope <- If[[[[~]Fields >>]Length] = [1]]
+	}
+}
+
 Blueprint C Function
 {
 	Name
@@ -352,10 +367,10 @@
 
 C Function[name,inputs,outputs,convention:out]
 {
-	out <- C Function With Registry[name,inputs,outputs,convention, C Method Registry[], C Field Registry[]]
+	out <- C Function With Registry[name,inputs,outputs,convention, C Method Registry[], C Field Registry[], C Type Registry[]]
 }
 
-C Function With Registry[name,inputs,outputs,convention,registry,field reg:out]
+C Function With Registry[name,inputs,outputs,convention,registry,field reg,type reg:out]
 {
 	out <- [[[[[[[[[[[[Build["C Function"]
 		]Name <<[name]
@@ -366,7 +381,7 @@
 		]Statements <<[()]
 		]Method Registry <<[registry]
 		]Field Registry <<[field reg]
-		]Type Registry <<[C Type Registry[]]
+		]Type Registry <<[type reg]
 		]Constants <<[New@Dictionary[]]
 		]Input Types <<[ Fold[["Append"]Set Input[1, "Any Type"], (), inputs] ]
 		]Output Types <<[ Fold[["Append"]Set Input[1, "Any Type"], (), outputs] ]
@@ -475,24 +490,37 @@
 Field Result@C Function[func,var,field:out]
 {
 	as op <- [var]Make Op[func]
-	If[[[Type Of[var]] = ["String"]] And[ [[func]Convention >>] = ["rhope"]] ]
+	If[[Type Of[var]] = ["String"]]
 	{
 		[[func]Inputs >>]Find[var]
 		{
 			type <- [[func]Input Types >>]Index[~]
-			If[[type] = ["Any Type"]]
-			{
-				rvar <- Val[as op]
-			}{
-				rvar <- [[[["(("]Append[ Rhope Type to C[type] ]]Append[")("]]Append[as op]]Append["))"]
+		}{
+			type <- [[func]Variables >>]Index[var] {}
+			{ 
+				//Does it make sense for us to do this?
+				type <- Type Instance["Any Type"] 
 			}
+		}
+	}{
+		type <- Type Instance["Any Type"] 
+	}
+	If[[[func]Convention >>] = ["rhope"]]
+	{
+		If[[type] = ["Any Type"]]
+		{
+			rvar <- Val[as op]
 		}{
-			rvar <- Val[as op]
+			rvar <- [[[["(("]Append[ Rhope Type to C[type] ]]Append[")("]]Append[as op]]Append["))"]
 		}
 	}{
 		rvar <- Val[as op]
 	}
-	out <- [[rvar]Append["->"]]Append[Escape Rhope Name[field]]
+
+	[[func]Type Registry >>]Simple Type?[[type]Name >>]
+	{ access <- "->" }
+	{ access <- "->payload." }
+	out <- [[rvar]Append[access]]Append[Escape Rhope Name[field]]
 }
 
 Read Field@C Function[func,var,field:out,result op]
@@ -509,6 +537,7 @@
 
 Set Field Null@C Function[func,var,field:out]
 {
+	Print["Set Field Null"]
 	out <- [func]Add Statement[ [[func]Field Result[var,field]]Append[" = NULL"] ]
 }
 
@@ -518,7 +547,7 @@
 	out <- [func]Add Statement[ [dest]Append[[[" = copy_object("]Append[dest]]Append[")"]] ]
 }
 
-Box@C Function[func,pdest,psource,type:out]
+Box@C Function[func,psource,pdest,type:out]
 {
 	dest <- [pdest]Make Op[func]
 	source <- [psource]Make Op[func]
@@ -531,7 +560,7 @@
 		]Append[")"] ]
 }
 
-Unbox@C Function[func,pdest,psource:out]
+Unbox@C Function[func,psource,pdest:out]
 {
 	dest <- [pdest]Make Op[func]
 	source <- [psource]Make Op[func]
@@ -669,11 +698,11 @@
 }
 _Output Defs C[string,varname,index,func:out]
 {
-	out <- [[[string]Append[ ["\t"]Append[Rhope Type to C[[[func]Output Types >>]Index[index]]] ]]Append[Escape Rhope Name[varname]]]Append[";\n"]
+	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]
 {
-	out <- [[[string]Append[ ["\t"]Append[Rhope Type to C[type]] ]]Append[Escape Rhope Name[varname]]]Append[";\n"]
+	out <- [[[string]Append[ ["\t"]Append[Rhope Type to C[type]] ]]Append[[" "]Append[Escape Rhope Name[varname]]]]Append[";\n"]
 }
 
 
@@ -707,10 +736,7 @@
 
 _Proto Input[list,input,index,types:out]
 {
-	Print[["_Proto Input: "]Append[input]]
-	{ Print[[types]Index[index]] }
 	out <- [list]Append[ [[Rhope Type to C[[types]Index[index]]]Append[" "]]Append[Escape Rhope Name[input]] ]
-	{ Pretty Print[~, ""] }
 }
 
 Naked Proto@C Function[func:out]
@@ -823,7 +849,7 @@
 
 Create Function@C Program[program,name,inputs,outputs,convention:out]
 {
-	out <- C Function With Registry[name,inputs,outputs,convention, [program]Method Registry >>, [program]Field Registry >>]
+	out <- C Function With Registry[name,inputs,outputs,convention, [program]Method Registry >>, [program]Field Registry >>, [program]Type Registry >>]
 }
 
 Store Function@C Program[program,func:out]