diff cbackend.rhope @ 37:640f541e9116

Added support for type declarations on user defined workers and added a few more methods to Int32 in the runtime for the C backend
author Mike Pavone <pavone@retrodev.com>
date Mon, 05 Oct 2009 23:12:43 -0400
parents 495dddadd058
children 7f05bbe82f24
line wrap: on
line diff
--- a/cbackend.rhope	Sat Oct 03 03:18:15 2009 -0400
+++ b/cbackend.rhope	Mon Oct 05 23:12:43 2009 -0400
@@ -128,13 +128,35 @@
 	out <- Fold["_Register Field C", field reg, [ctype]Fields >>]
 }
 
-Rhope Type to C[typename:out]
+Rhope Type to C[type:out]
 {
+	If[[Type Of[type]]=["Type Instance"]]
+	{
+		typename <- [type]Name >>
+		variant <- [type]Variant >>
+	}{
+		typename <- type
+		variant <- "boxed"
+	}
 	If[[typename] = ["Any Type"]]
 	{
 		out <- "struct object *"
 	}{
-		out <- [["t_"]Append[Escape Rhope Name[typename]]]Append[" *"]
+		[("Naked","Raw Pointer")]Find[variant]
+		{
+			prefix <- "nt_"
+		}{
+			prefix <- "t_"
+		}
+		
+		If[[variant]=["Naked"]]
+		{
+			postfix <- ""
+		}{
+			postfix <- " *"
+		}
+		
+		out <- [[prefix]Append[Escape Rhope Name[typename]]]Append[postfix]
 	}
 }
 
@@ -289,12 +311,12 @@
 		]Output Types <<[ Fold[["Append"]Set Input[1, "Any Type"], (), outputs] ]
 }
 
-Set Input Type@C Function[func,input num,type:out]
+Set Input Type@C Function[func,type,input num:out]
 {
 	out <- [func]Input Types <<[ [[func]Input Types >>]Set[input num, type] ]
 }
 
-Set Output Type@C Function[func,output num,type:out]
+Set Output Type@C Function[func,type,output num:out]
 {
 	out <- [func]Output Types <<[ [[func]Output Types >>]Set[output num, type] ]
 }
@@ -426,7 +448,7 @@
 
 Set Field Null@C Function[func,var,field:out]
 {
-	out <- [func]Add Statement[ [[[var]Append["->"]]Append[field]]Append[" = NULL"] ]
+	out <- [func]Add Statement[ [[func]Field Result[var,field]]Append[" = NULL"] ]
 }
 
 Copy@C Function[func,pdest:out]
@@ -632,28 +654,47 @@
 	}
 }
 
+Check Param Type C[text,type,input num,func:out]
+{
+	If[[Type Of[type]] = ["String"]]
+	{
+		typename <- type
+	}{
+		typename <- [type]Name >>
+	}
+	If[[typename] = ["Any Type"]]
+	{
+		out <- text
+	}{
+		out <- [text]Append[[[["\tParam("]Append[input num]]Append[ [","]Append[ [[func]Type Registry >>]Type ID[typename] ] ]]Append[")\n"]]
+	}
+}
+
 Text@C Function[func:out]
 {	
 	If[ [[func]Convention >>] = ["rhope"] ]
 	{
 		cname <- Escape Rhope Name[[func]Name >>]
+		param check <- Fold[["Check Param Type C"]Set Input[3, func], "", [func]Input Types >>]
 		If[ [ [[[func]Variables >>]Length]+[[[func]Outputs >>]Length] ] = [0] ]
 		{
-			out <- [[[[[["FuncNoLocals("
+			out <- [[[[[[["FuncNoLocals("
 				]Append[cname]
 				]Append[",\n\tNumParams "]
 				]Append[ [[func]Inputs >>]Length ]
 				]Append[",\n\tCallSpace 32)\n\n"]//TODO: Fill in with calculated callspace value
+				]Append[param check]
 				]Append[ [[func]Statements >>]Join[""] ]
 				]Append["EndFunc"]
 		}{
-			out <- [[[[[[[[["Func("
+			out <- [[[[[[[[[["Func("
 				]Append[cname]
 				]Append[",\n\tNumParams "]
 				]Append[ [[func]Inputs >>]Length ]
 				]Append[",\n\tCallSpace 32,\n\t"]//TODO: Fill in with calculated callspace value
 				]Append[["l_"]Append[cname]]
 				]Append[")\n\n"]
+				]Append[param check]
 				]Append[ [[func]Statements >>]Join[""] ]
 				]Append[[func]Set Outputs]
 				]Append["EndFunc"]
@@ -743,11 +784,21 @@
 	{
 		out <- [text]Append[[[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[" = make_Int32("]]Append[value]]Append[");\n"]]
 	}{
-		If[[valtype] = ["Type Literal"]]
+		If[[valtype] = ["Type Instance"]]
 		{
 			//TODO: Support parametric types
 			typeid <- [type reg]Type ID[[value]Name >>]
 			out <- [text]Append[[[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[" = make_Blueprint("]]Append[typeid]]Append[");\n"]]
+		}{
+			If[[valtype] = ["Yes No"]]
+			{
+				If[value]
+				{
+					out <- [text]Append[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[" = (object *)val_yes;\n"]]
+				}{
+					out <- [text]Append[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[" = (object *)val_no;\n"]]
+				}
+			}
 		}
 	}
 }
@@ -762,7 +813,8 @@
 #include \"context.h\"
 #include \"func.h\"
 #include \"integer.h\"
-#include \"blueprint.h\"\n\n"
+#include \"blueprint.h\"
+#include \"bool.h\"\n\n"
 	out <- [[[[[[headers
 		]Append[[[program]Type Registry >>]Type Defs]
 		]Append[Fold[["_Text C Program"]Set Input[2, [program]Type Registry >>],