comparison cbackend.rhope @ 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 079200bc3e75
children e1fd6d244f14
comparison
equal deleted inserted replaced
53:70af7fa155d0 54:243d013a49cb
1083 { s <- "UI" } 1083 { s <- "UI" }
1084 1084
1085 make <- [[[" = make_"]Append[s]]Append["nt"]]Append[[value]Size >>] 1085 make <- [[[" = make_"]Append[s]]Append["nt"]]Append[[value]Size >>]
1086 out <- [text]Append[ [[[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[make]]Append["("]]Append[[value]Value >>]]Append[");\n"] ] 1086 out <- [text]Append[ [[[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[make]]Append["("]]Append[[value]Value >>]]Append[");\n"] ]
1087 }{ 1087 }{
1088 If[[valtype] = ["String"]] 1088 out <- text
1089 {
1090 out <- [text]Append[ [[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[" = make_String(\""]]Append[ [[value]Replace["\n", "\\n"]]Replace["\\", "\\\\"]]]Append["\");\n"] ]
1091 }
1092 } 1089 }
1093 } 1090 }
1094 } 1091 }
1092 }
1093 }
1094
1095 _Set Late Consts C[text,value,name,type reg:out]
1096 {
1097 valtype <- Type Of[value]
1098 If[[valtype] = ["String"]]
1099 {
1100 out <- [text]Append[ [[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[" = make_String(\""]]Append[ [[value]Replace["\n", "\\n"]]Replace["\\", "\\\\"]]]Append["\");\n"] ]
1101 }{
1102 out <- text
1095 } 1103 }
1096 } 1104 }
1097 1105
1098 Text@C Program[program:out] 1106 Text@C Program[program:out]
1099 { 1107 {
1106 #include \"func.h\" 1114 #include \"func.h\"
1107 #include \"integer.h\" 1115 #include \"integer.h\"
1108 #include \"blueprint.h\" 1116 #include \"blueprint.h\"
1109 #include \"array.h\" 1117 #include \"array.h\"
1110 #include \"bool.h\"\n\n" 1118 #include \"bool.h\"\n\n"
1111 out <- [[[[[[headers 1119 out <- [[[[[[[headers
1112 ]Append[[[program]Type Registry >>]Type Defs] 1120 ]Append[[[program]Type Registry >>]Type Defs]
1113 ]Append[Fold[["_Text C Program"]Set Input[2, [program]Type Registry >>], 1121 ]Append[Fold[["_Text C Program"]Set Input[2, [program]Type Registry >>],
1114 Fold["_Consts C Program", 1122 Fold["_Consts C Program",
1115 Fold["_Defs C Program", "", [program]Functions >>], 1123 Fold["_Defs C Program", "", [program]Functions >>],
1116 constants 1124 constants
1122 context * ct; 1130 context * ct;
1123 blueprint * bp; 1131 blueprint * bp;
1124 register_builtin_types();\n\n"] 1132 register_builtin_types();\n\n"]
1125 ]Append[ [[program]Type Registry >>]Type Inits[[program]Method Registry >>, [program]Field Registry >>] ] 1133 ]Append[ [[program]Type Registry >>]Type Inits[[program]Method Registry >>, [program]Field Registry >>] ]
1126 ]Append[Fold[["_Set Consts C Program"]Set Input[3, [program]Type Registry >>], "", constants]] 1134 ]Append[Fold[["_Set Consts C Program"]Set Input[3, [program]Type Registry >>], "", constants]]
1135 ]Append[Fold[["_Set Late Consts C"]Set Input[3, [program]Type Registry >>], "", constants]]
1127 ]Append[" 1136 ]Append["
1128 ct = new_context(); 1137 ct = new_context();
1129 cdata = alloc_cdata(ct, 0); 1138 cdata = alloc_cdata(ct, 0);
1130 cdata->num_params = 0; 1139 cdata->num_params = 0;
1131 cdata->resume = 0; 1140 cdata->resume = 0;