changeset 38:7f05bbe82f24

Started work on adding Array support
author Mike Pavone <pavone@retrodev.com>
date Tue, 06 Oct 2009 23:13:47 -0400
parents 640f541e9116
children 3d92bc1352c2 d2f9b0a9403d
files backendutils.rhope cbackend.rhope
diffstat 2 files changed, 36 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/backendutils.rhope	Mon Oct 05 23:12:43 2009 -0400
+++ b/backendutils.rhope	Tue Oct 06 23:13:47 2009 -0400
@@ -1,7 +1,7 @@
 
 Escape Rhope Name NU[name:escaped]
 {
-	escaped <- [[[[[[[[[[name]Replace["@","_AT_"]
+	escaped <- [[[[[[[[[[[[name]Replace["@","_AT_"]
 		]Replace[" ","_SP_"]
 		]Replace[":","_CN_"]
 		]Replace["?","_QN_"]
@@ -11,6 +11,8 @@
 		]Replace["/","_DV_"]
 		]Replace["<","_LT_"]
 		]Replace[">","_GT_"]
+		]Replace["(","_LP_"]
+		]Replace[")","_RP_"]
 }
 
 Escape Rhope Name[name:escaped]
--- a/cbackend.rhope	Mon Oct 05 23:12:43 2009 -0400
+++ b/cbackend.rhope	Tue Oct 06 23:13:47 2009 -0400
@@ -128,16 +128,42 @@
 	out <- Fold["_Register Field C", field reg, [ctype]Fields >>]
 }
 
-Rhope Type to C[type:out]
+Rhope Type to C[type:out,array]
 {
 	If[[Type Of[type]]=["Type Instance"]]
 	{
-		typename <- [type]Name >>
 		variant <- [type]Variant >>
+		If[[[type]Name >>] = ["Array"]]
+		{
+			[("Naked","Raw Pointer")]Find[variant]
+			{
+				pre param <- [[type]Params >>]Index[0] {}
+				{ pre param <- Type Instance["Any Type"] }
+				[[type]Params >>]Index[1]
+				{ param,param <- [pre param]Set Variant[~] }
+				{ param <- Val[pre param] }
+				child type <- Rhope Type to C[param]
+				If[[variant] = ["Naked"]]
+				{
+					out <- Val[child type]
+					array <- "[1]"
+				}{
+					out <- [child type]Append[" *"]
+					array <- ""
+				}
+			}{
+				typename <- "Array"
+			}
+		}{
+			typename <- [type]Name >>
+		}
 	}{
 		typename <- type
+		param <- "Any Type"
 		variant <- "boxed"
 	}
+	Val[typename]
+	{ array <- "" }
 	If[[typename] = ["Any Type"]]
 	{
 		out <- "struct object *"
@@ -155,16 +181,17 @@
 		}{
 			postfix <- " *"
 		}
-		
-		out <- [[prefix]Append[Escape Rhope Name[typename]]]Append[postfix]
 	}
+	out <- [[prefix]Append[Escape Rhope Name[typename]]]Append[postfix]
 }
 
 _Type Def C Type[text,field:out]
 {
 	name <- [field]Index[0]
-	type <- ["\n\t"]Append[Rhope Type to C[[field]Index[1]]]
-	out <- [[[[text]Append[type]]Append[" "]]Append[Escape Rhope Name[name]]]Append[";"]
+	,postfix <- Rhope Type to C[[field]Index[1]]
+	{ type <- ["\n\t"]Append[~] }
+	
+	out <- [[[[text]Append[type]]Append[" "]]Append[[Escape Rhope Name[name]]Append[postfix]]]Append[";"]
 }
 
 Type Def@C Type[ctype:out]