comparison cbackend.rhope @ 74:a844c623c7df

Add support for Worker type
author Mike Pavone <pavone@retrodev.com>
date Thu, 01 Jul 2010 21:32:08 -0400
parents f7bcf3db1342
children 0083b2f7b3c7
comparison
equal deleted inserted replaced
73:6a1a7d5cc2d9 74:a844c623c7df
241 //HACK!!! 241 //HACK!!!
242 If[[[ctype]Name >>]=["Blueprint"]] 242 If[[[ctype]Name >>]=["Blueprint"]]
243 { 243 {
244 out <- "" 244 out <- ""
245 }{ 245 }{
246 If[[[ctype]Name >>]=["Array"]] 246 [("Array","Worker")]Find[[ctype]Name >>]
247 { oend <- "\nMObject(" } 247 { oend <- "\nMObject(" }
248 { oend <- "\nObject(" } 248 { oend <- "\nObject(" }
249 out <- [Fold["_Type Def C Type", "OBegin", [ctype]Fields >>]]Append[ [[oend]Append[Escape Rhope Name[[ctype]Name >>]]]Append[")"] ] 249 out <- [Fold["_Type Def C Type", "OBegin", [ctype]Fields >>]]Append[ [[oend]Append[Escape Rhope Name[[ctype]Name >>]]]Append[")"] ]
250 } 250 }
251 } 251 }
263 ]Append[[["\n\tadd_setter(bp, "]Append[ [field reg]Field ID[fname] ]]Append[ [[", MethodName("]Append[Escape Rhope Name[[fname]Append[" <<"]]]]Append[[","]Append[Escape Rhope Name[type name]]]]]]Append["));"] 263 ]Append[[["\n\tadd_setter(bp, "]Append[ [field reg]Field ID[fname] ]]Append[ [[", MethodName("]Append[Escape Rhope Name[[fname]Append[" <<"]]]]Append[[","]Append[Escape Rhope Name[type name]]]]]]Append["));"]
264 } 264 }
265 265
266 Type Init@C Type[ctype,id,method reg,field reg:out] 266 Type Init@C Type[ctype,id,method reg,field reg:out]
267 { 267 {
268 If[[[ctype]Name >>]=["Array"]] 268 [("Array","Worker")]Find[[ctype]Name >>]
269 { size <- "-1" } 269 { size <- "-1" }
270 { 270 {
271 [("Int64","Int32","Int16","Int8")]Find[[ctype]Name >>] 271 [("Int64","Int32","Int16","Int8")]Find[[ctype]Name >>]
272 { 272 {
273 [[ctype]Name >>]Slice[3] {} 273 [[ctype]Name >>]Slice[3] {}
313 } 313 }
314 314
315 C Type Registry[:out] 315 C Type Registry[:out]
316 { 316 {
317 out <- [[[Build["C Type Registry"]]Lookup << [ 317 out <- [[[Build["C Type Registry"]]Lookup << [
318 [[[[[[[[[[[[[[[[[Dictionary[] 318 [[[[[[[[[[[[[[[[[[Dictionary[]
319 ]Set["UInt8", "TYPE_UINT8"] 319 ]Set["UInt8", "TYPE_UINT8"]
320 ]Set["UInt16", "TYPE_UINT16"] 320 ]Set["UInt16", "TYPE_UINT16"]
321 ]Set["UInt32", "TYPE_UINT32"] 321 ]Set["UInt32", "TYPE_UINT32"]
322 ]Set["UInt64", "TYPE_UINT64"] 322 ]Set["UInt64", "TYPE_UINT64"]
323 ]Set["Int8", "TYPE_INT8"] 323 ]Set["Int8", "TYPE_INT8"]
328 ]Set["Float32", "TYPE_FLOAT32"] 328 ]Set["Float32", "TYPE_FLOAT32"]
329 ]Set["Float64", "TYPE_FLOAT64"] 329 ]Set["Float64", "TYPE_FLOAT64"]
330 ]Set["Real Number", "TYPE_FLOAT64"] 330 ]Set["Real Number", "TYPE_FLOAT64"]
331 ]Set["Blueprint", "TYPE_BLUEPRINT"] 331 ]Set["Blueprint", "TYPE_BLUEPRINT"]
332 ]Set["Array", "TYPE_ARRAY"] 332 ]Set["Array", "TYPE_ARRAY"]
333 ]Set["Worker", "TYPE_WORKER"]
333 ]Set["Method Missing Exception", "TYPE_METHODMISSINGEXCEPTION"] 334 ]Set["Method Missing Exception", "TYPE_METHODMISSINGEXCEPTION"]
334 ]Set["Field Missing Exception", "TYPE_FIELDMISSINGEXCEPTION"] 335 ]Set["Field Missing Exception", "TYPE_FIELDMISSINGEXCEPTION"]
335 ]Set["Wrong Type Exception", "TYPE_WRONGTYPEEXCEPTION"]] 336 ]Set["Wrong Type Exception", "TYPE_WRONGTYPEEXCEPTION"]]
336 ]Definitions << [Dictionary[]] 337 ]Definitions << [Dictionary[]]
337 ]Next ID <<[0] 338 ]Next ID <<[0]
562 { 563 {
563 dest <- [pdest]Make Op[func] 564 dest <- [pdest]Make Op[func]
564 out <- [func]Add Statement[[dest]Append[" = NULL"]] 565 out <- [func]Add Statement[[dest]Append[" = NULL"]]
565 } 566 }
566 567
567 Lookup Constant@C Function[func,const:out] 568 Lookup Constant@C Function[func,const,doaddref:out]
568 { 569 {
569 out <- [["add_ref(_const_"]Append[Escape Rhope Name[const]]]Append[")"] 570 var <- ["_const_"]Append[Escape Rhope Name[const]]
571 If[doaddref]
572 {
573 out <- [["add_ref("]Append[var]]Append[")"]
574 }{
575 out <- Val[var]
576 }
570 } 577 }
571 578
572 Field Result@C Function[func,var,field:out] 579 Field Result@C Function[func,var,field:out]
573 { 580 {
574 as op <- [var]Make Op[func] 581 as op <- [var]Make Op[func]
681 ]Append[val] 688 ]Append[val]
682 ]Append[")"] 689 ]Append[")"]
683 ] 690 ]
684 } 691 }
685 692
693 _Val Function Arg C[func,val,inputnum,worker:out]
694 {
695 out <- [func]Add Raw Line[
696 [[[[[["VCSetParam("
697 ]Append[worker]
698 ]Append[", "]
699 ]Append[inputnum]
700 ]Append[", "]
701 ]Append[val]
702 ]Append[")"]
703 ]
704 }
705
686 Method Call@C Function[func,method,args:out] 706 Method Call@C Function[func,method,args:out]
687 { 707 {
688 out <- [func]Call[method,args] 708 out <- [func]Call[method,args]
689 } 709 }
690 710
711 Val Call@C Function[func,to call,args:out]
712 {
713 worker <- Make Op[Strip Addref[to call], func]
714 rargs <- Map[args, ["Make Op"]Set Input[1, func]]
715
716 If[[[func]Last NumParams >>] = [-1]]
717 {
718 freed <- Val[func]
719 }{
720 freed <- [func]Add Raw Line["FreeCall"]
721 }
722 prepped <- [[freed]Add Raw Line[
723 [[[["VCPrepCall("
724 ]Append[worker]
725 ]Append[", "]
726 ]Append[[rargs]Length]
727 ]Append[")"] ]
728 ]Last NumParams <<[[rargs]Length]
729
730
731 out <- [[[[Fold[["_Val Function Arg C"]Set Input[3, worker], prepped, rargs]
732 ]Add Raw Line[
733 [[[[[[[["ValCall("
734 ]Append[worker]
735 ]Append[", "]
736 ]Append[[rargs]Length]
737 ]Append[", "]
738 ]Append[[func]Resume Index >>]
739 ]Append[", "]
740 ]Append[Escape Rhope Name[[func]Name >>]]
741 ]Append[")"]]
742 ]Add Raw Line["DISPATCH"]
743 ]Add Raw Line[
744 [[[["ValCallPostlude("
745 ]Append[[func]Resume Index >>]
746 ]Append[", "]
747 ]Append[Escape Rhope Name[[func]Name >>]]
748 ]Append[")"]]
749 ]Resume Index <<[ [[func]Resume Index >>]+[1] ]
750 }
751
691 Call@C Function[func,name,args:out] 752 Call@C Function[func,name,args:out]
692 { 753 {
693 out <- [func]Func Base[Escape Rhope Name[name],args, "Call"] 754 If[[name]=["Call@Worker"]]
755 {
756 //TODO: Handle case when user explicitly calls the fully qualified version, but the type of the first arg isn't Worker
757 out <- [func]Val Call[[args]Index[0], Tail[args,1]]
758 }{
759 If[[name]=["Call"]]
760 {
761 to call <- [args]Index[0]
762 out <- [[[[[func]Add Raw Line[[["if (get_blueprint("]Append[Make Op[Strip Addref[to call], func]]]Append[")->type_id == TYPE_WORKER) {"]]
763 ]Val Call[to call, Tail[args,1]]
764 ]Add Raw Line["} else {"]
765 ]Func Base["Call",args, "Call"]
766 ]Add Raw Line["}"]
767 }{
768 out <- [func]Func Base[Escape Rhope Name[name],args, "Call"]
769 }
770 }
694 } 771 }
695 772
696 Func Base@C Function[func,tocall,args,type:out] 773 Func Base@C Function[func,tocall,args,type:out]
697 { 774 {
698 rargs <- Map[args, ["Make Op"]Set Input[1, func]] 775 rargs <- Map[args, ["Make Op"]Set Input[1, func]]
827 ]Append[")"] 904 ]Append[")"]
828 } 905 }
829 906
830 _Set Outputs C[string,inputname,inputnum,func:out] 907 _Set Outputs C[string,inputname,inputnum,func:out]
831 { 908 {
832 out <- [string]Append[[[ [ ["\tRet("]Append[inputnum] ]Append[ [[", lv_"]Append[Escape Rhope Name[[func]Name >>]]]Append["->"]]]Append[inputname]]Append[")\n"]] 909 out <- [string]Append[[[ [ ["\tRet("]Append[inputnum] ]Append[ [[", lv_"]Append[Escape Rhope Name[[func]Name >>]]]Append["->"]]]Append[Escape Rhope Name[inputname]]]Append[")\n"]]
833 } 910 }
834 911
835 Set Outputs@C Function[func:out] 912 Set Outputs@C Function[func:out]
836 { 913 {
837 If[[[func]Convention >>] = ["rhope"]] 914 If[[[func]Convention >>] = ["rhope"]]
1070 _Consts C Program[text,value,name:out] 1147 _Consts C Program[text,value,name:out]
1071 { 1148 {
1072 out <- [text]Append[ [["object * _const_"]Append[Escape Rhope Name[name]]]Append[";\n"] ] 1149 out <- [text]Append[ [["object * _const_"]Append[Escape Rhope Name[name]]]Append[";\n"] ]
1073 } 1150 }
1074 1151
1075 _Set Consts C Program[text,value,name,type reg:out] 1152 Const Construct C[value,type reg:out]
1076 { 1153 {
1077 //TODO: Support more constant types
1078 valtype <- Type Of[value] 1154 valtype <- Type Of[value]
1079 [("Int32","Whole Number")]Find[valtype] 1155 [("Int32","Whole Number")]Find[valtype]
1080 { 1156 {
1081 out <- [text]Append[[[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[" = make_Int32("]]Append[value]]Append[");\n"]] 1157 out <- [["make_Int32("]Append[value]]Append[")"]
1082 }{ 1158 }{
1083 If[[valtype] = ["Type Instance"]] 1159 If[[valtype] = ["Type Instance"]]
1084 { 1160 {
1085 //TODO: Support parametric types 1161 //TODO: Support parametric types
1086 typeid <- [type reg]Type ID[[value]Name >>] 1162 typeid <- [type reg]Type ID[[value]Name >>]
1087 out <- [text]Append[[[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[" = make_Blueprint("]]Append[typeid]]Append[");\n"]] 1163 out <- [["make_Blueprint("]Append[typeid]]Append[")"]
1088 }{ 1164 }{
1089 If[[valtype] = ["Yes No"]] 1165 If[[valtype] = ["Yes No"]]
1090 { 1166 {
1091 If[value] 1167 If[value]
1092 { 1168 {
1093 out <- [text]Append[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[" = make_Bool(1);\n"]] 1169 out <- "make_Bool(1)"
1094 }{ 1170 }{
1095 out <- [text]Append[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[" = make_Bool(0);\n"]] 1171 out <- "make_Bool(0)"
1096 } 1172 }
1097 }{ 1173 }{
1098 If[[valtype] = ["Machine Integer"]] 1174 If[[valtype] = ["Machine Integer"]]
1099 { 1175 {
1100 If[[value]Signed? >>] 1176 If[[value]Signed? >>]
1101 { s <- "I" } 1177 { s <- "I" }
1102 { s <- "UI" } 1178 { s <- "UI" }
1103 1179
1104 make <- [[[" = make_"]Append[s]]Append["nt"]]Append[[value]Size >>] 1180 out <- [[[[[["make_"
1105 out <- [text]Append[ [[[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[make]]Append["("]]Append[[value]Value >>]]Append[");\n"] ] 1181 ]Append[s]
1182 ]Append["nt"]
1183 ]Append[[value]Size >>]
1184 ]Append["("]
1185 ]Append[[value]Value >>]
1186 ]Append[")"]
1106 }{ 1187 }{
1107 out <- text 1188 If[[valtype] = ["String"]]
1189 {
1190 out <- [["make_String(\""]Append[ [[value]Replace["\\", "\\\\"]]Replace["\n", "\\n"]]]Append["\")"]
1191 }{
1192 If[[valtype]=["Worker Literal"]]
1193 {
1194 //TODO: Figure out how to fully support these in nested cases
1195 //or workaround the problem higher up in the food chain
1196 [[value]Args >>]Last
1197 { size <- [~]+[1] }
1198 { size <- "0" }
1199 out <- [[[[[["make_Worker(FUNC_"
1200 ]Append[Escape Rhope Name[[value]Name >>]]
1201 ]Append[", "]
1202 ]Append[size]
1203 ]Append[", "]
1204 ]Append[[[value]Args >>]Length]
1205 ]Append[")"]
1206 }{
1207 out <- "UnhandledLiteralType"
1208 }
1209 }
1108 } 1210 }
1109 } 1211 }
1110 } 1212 }
1213
1214 }
1215 }
1216
1217 _Set Worker Params C[text,param,num,type reg,name:out]
1218 {
1219 out <- [text]Append[
1220 [[[[[["\t((object **)(((t_Worker *)_const_"
1221 ]Append[name]
1222 ]Append[")+1))["]
1223 ]Append[num]
1224 ]Append["] = "]
1225 ]Append[Const Construct C[param, type reg]]
1226 ]Append[";\n"] ]
1227 }
1228
1229 _Set Consts C Program[text,value,name,type reg:out]
1230 {
1231 valtype <- Type Of[value]
1232 [("String","Worker Literal")]Find[valtype]
1233 {
1234 out <- text
1235 }{
1236 Const Construct C[value,type reg]
1237 { out <- [text]Append[ [[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[" = "]]Append[~]]Append[";\n"] ] }
1111 } 1238 }
1112 } 1239 }
1113 1240
1114 _Set Late Consts C[text,value,name,type reg:out] 1241 _Set Late Consts C[text,value,name,type reg:out]
1115 { 1242 {
1116 valtype <- Type Of[value] 1243 valtype <- Type Of[value]
1117 If[[valtype] = ["String"]] 1244 [("String","Worker Literal")]Find[valtype]
1118 { 1245 {
1119 out <- [text]Append[ [[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[" = make_String(\""]]Append[ [[value]Replace["\n", "\\n"]]Replace["\\", "\\\\"]]]Append["\");\n"] ] 1246 Const Construct C[value,type reg]
1247 { init <- [text]Append[ [[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[" = "]]Append[~]]Append[";\n"] ] }
1248
1249 If[[valtype]=["Worker Literal"]]
1250 {
1251 out <- Fold[[["_Set Worker Params C"]Set Input[3, type reg]]Set Input[4, Escape Rhope Name[name]], init, [value]Args >>]
1252 }{
1253 out <- Val[init]
1254 }
1120 }{ 1255 }{
1121 out <- text 1256 out <- text
1122 } 1257 }
1123 } 1258 }
1124 1259
1268 #include \"context.h\" 1403 #include \"context.h\"
1269 #include \"func.h\" 1404 #include \"func.h\"
1270 #include \"integer.h\" 1405 #include \"integer.h\"
1271 #include \"blueprint.h\" 1406 #include \"blueprint.h\"
1272 #include \"array.h\" 1407 #include \"array.h\"
1408 #include \"worker.h\"
1273 #include \"bool.h\"\n\n" 1409 #include \"bool.h\"\n\n"
1274 out <- [[[[[[[[[[[[[[[headers 1410 out <- [[[[[[[[[[[[[[[headers
1275 ]Append[[program]Dispatch[all methods]] 1411 ]Append[[program]Dispatch[all methods]]
1276 ]Append[[[program]Type Registry >>]Type Defs] 1412 ]Append[[[program]Type Registry >>]Type Defs]
1277 ]Append[Fold["_Consts C Program", 1413 ]Append[Fold["_Consts C Program",
1279 constants]] 1415 constants]]
1280 ]Append[Fold[["_Text C Program"]Set Input[2, [program]Type Registry >>], "", Filter[[program]Functions >>, "Not Native"]]] 1416 ]Append[Fold[["_Text C Program"]Set Input[2, [program]Type Registry >>], "", Filter[[program]Functions >>, "Not Native"]]]
1281 ]Append["\n 1417 ]Append["\n
1282 uint16_t rhope(uint32_t func, object ** params, uint16_t numparams, uint16_t callspace) 1418 uint16_t rhope(uint32_t func, object ** params, uint16_t numparams, uint16_t callspace)
1283 { 1419 {
1284 uint16_t resume,idx; 1420 uint16_t resume,idx, vcparam_offset, last_vcparam;
1285 context * ct; 1421 context * ct;
1286 calldata * cdata, *temp_cdata, *my_cdata;\n\nFuncDef(Build)\nFuncDef(BlueprintSP_Of)\n"] 1422 calldata * cdata, *temp_cdata, *my_cdata;\n\nFuncDef(Build)\nFuncDef(BlueprintSP_Of)\n"]
1287 ]Append[Fold["Local Pointers", "", [program]Functions >>]] 1423 ]Append[Fold["Local Pointers", "", [program]Functions >>]]
1288 ]Append[" 1424 ]Append["
1289 ct = new_context(); 1425 ct = new_context();
1335 return 0; 1471 return 0;
1336 } 1472 }
1337 1473
1338 #include \"builtin.c\" 1474 #include \"builtin.c\"
1339 #include \"array.c\" 1475 #include \"array.c\"
1476 #include \"worker.c\"
1340 1477
1341 int main(int argc, char **argv) 1478 int main(int argc, char **argv)
1342 { 1479 {
1343 blueprint * bp; 1480 blueprint * bp;
1344 register_builtin_types();\n\n"] 1481 register_builtin_types();\n\n"]