changeset 54:243d013a49cb

Defer processing of string literals until after simpler ones to avoid a segfault
author Mike Pavone <pavone@retrodev.com>
date Thu, 29 Apr 2010 01:12:43 -0400
parents 70af7fa155d0
children 048046186d22
files cbackend.rhope
diffstat 1 files changed, 15 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/cbackend.rhope	Thu Apr 29 04:32:54 2010 +0000
+++ b/cbackend.rhope	Thu Apr 29 01:12:43 2010 -0400
@@ -1085,14 +1085,22 @@
 					make <- [[[" = make_"]Append[s]]Append["nt"]]Append[[value]Size >>]
 					out <- [text]Append[ [[[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[make]]Append["("]]Append[[value]Value >>]]Append[");\n"] ]
 				}{
-					If[[valtype] = ["String"]]
-					{
-						out <- [text]Append[ [[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[" = make_String(\""]]Append[ [[value]Replace["\n", "\\n"]]Replace["\\", "\\\\"]]]Append["\");\n"] ]
-					}
+					out <- text
 				}
 			}
 		}
 	}
+}
+
+_Set Late Consts C[text,value,name,type reg:out]
+{
+	valtype <- Type Of[value]
+	If[[valtype] = ["String"]]
+	{
+		out <- [text]Append[ [[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[" = make_String(\""]]Append[ [[value]Replace["\n", "\\n"]]Replace["\\", "\\\\"]]]Append["\");\n"] ]
+	}{
+		out <- text
+	}
 }
 
 Text@C Program[program:out]
@@ -1108,7 +1116,7 @@
 #include \"blueprint.h\"
 #include \"array.h\"
 #include \"bool.h\"\n\n"
-	out <- [[[[[[headers
+	out <- [[[[[[[headers
 		]Append[[[program]Type Registry >>]Type Defs]
 		]Append[Fold[["_Text C Program"]Set Input[2, [program]Type Registry >>], 
 				Fold["_Consts C Program", 
@@ -1123,7 +1131,8 @@
 	blueprint * bp;
 	register_builtin_types();\n\n"]
 		]Append[ [[program]Type Registry >>]Type Inits[[program]Method Registry >>, [program]Field Registry >>] ]
-		]Append[Fold[["_Set Consts C Program"]Set Input[3, [program]Type Registry >>], "", constants]]
+		]Append[Fold[["_Set Consts C Program"]Set Input[3, [program]Type Registry >>], "", constants]]
+		]Append[Fold[["_Set Late Consts C"]Set Input[3, [program]Type Registry >>], "", constants]]
 		]Append["
 	ct = new_context();
 	cdata = alloc_cdata(ct, 0);