comparison cbackend.rhope @ 75:0083b2f7b3c7

Partially working implementation of List. Modified build scripts to allow use of other compilers. Fixed some bugs involving method implementations on different types returning different numbers of outputs. Added Fold to the 'builtins' in the comipler.
author Mike Pavone <pavone@retrodev.com>
date Tue, 06 Jul 2010 07:52:59 -0400
parents a844c623c7df
children dbe95bfec970
comparison
equal deleted inserted replaced
74:a844c623c7df 75:0083b2f7b3c7
234 234
235 Type Def@C Type[ctype:out] 235 Type Def@C Type[ctype:out]
236 { 236 {
237 If[[[[ctype]Fields >>]Length] = [1]] 237 If[[[[ctype]Fields >>]Length] = [1]]
238 { 238 {
239 out <- [[[_Type Def C Type["typedef struct {\n\tobject _SP_header;\n\t", [[ctype]Fields >>]Index[0]]]Append["\n} t_"]]Append[[ctype]Name >>]]Append[";"] 239 out <- [[[[_Type Def C Type["typedef struct {\n\tobject _SP_header;\n\t", [[ctype]Fields >>]Index[0]]]Append["\n} t_"]]Append[Escape Rhope Name[[ctype]Name >>]]]Append[";"]
240 ]Append[
241 [[[["typedef "
242 ]Append[Rhope Type to C[ [[[ctype]Fields >>]Index[0]]Index[1] ]]
243 ]Append[" nt_"]
244 ]Append[Escape Rhope Name[[ctype]Name >>]]
245 ]Append[";"] ]
240 }{ 246 }{
241 //HACK!!! 247 //HACK!!!
242 If[[[ctype]Name >>]=["Blueprint"]] 248 If[[[ctype]Name >>]=["Blueprint"]]
243 { 249 {
244 out <- "" 250 out <- ""
314 320
315 C Type Registry[:out] 321 C Type Registry[:out]
316 { 322 {
317 out <- [[[Build["C Type Registry"]]Lookup << [ 323 out <- [[[Build["C Type Registry"]]Lookup << [
318 [[[[[[[[[[[[[[[[[[Dictionary[] 324 [[[[[[[[[[[[[[[[[[Dictionary[]
319 ]Set["UInt8", "TYPE_UINT8"] 325 ]Set["UInt8", "TYPE_UINT8"] //1
320 ]Set["UInt16", "TYPE_UINT16"] 326 ]Set["UInt16", "TYPE_UINT16"] //2
321 ]Set["UInt32", "TYPE_UINT32"] 327 ]Set["UInt32", "TYPE_UINT32"] //3
322 ]Set["UInt64", "TYPE_UINT64"] 328 ]Set["UInt64", "TYPE_UINT64"] //4
323 ]Set["Int8", "TYPE_INT8"] 329 ]Set["Int8", "TYPE_INT8"] //5
324 ]Set["Int16", "TYPE_INT16"] 330 ]Set["Int16", "TYPE_INT16"] //6
325 ]Set["Int32", "TYPE_INT32"] 331 ]Set["Int32", "TYPE_INT32"] //7
326 ]Set["Int64", "TYPE_INT64"] 332 ]Set["Int64", "TYPE_INT64"] //8
327 ]Set["Boolean", "TYPE_BOOLEAN"] 333 ]Set["Boolean", "TYPE_BOOLEAN"] //9
328 ]Set["Float32", "TYPE_FLOAT32"] 334 ]Set["Float32", "TYPE_FLOAT32"] //10
329 ]Set["Float64", "TYPE_FLOAT64"] 335 ]Set["Float64", "TYPE_FLOAT64"] //11
330 ]Set["Real Number", "TYPE_FLOAT64"] 336 ]Set["Real Number", "TYPE_FLOAT64"] //12
331 ]Set["Blueprint", "TYPE_BLUEPRINT"] 337 ]Set["Blueprint", "TYPE_BLUEPRINT"] //13
332 ]Set["Array", "TYPE_ARRAY"] 338 ]Set["Array", "TYPE_ARRAY"] //14
333 ]Set["Worker", "TYPE_WORKER"] 339 ]Set["Worker", "TYPE_WORKER"] //15
334 ]Set["Method Missing Exception", "TYPE_METHODMISSINGEXCEPTION"] 340 ]Set["Method Missing Exception", "TYPE_METHODMISSINGEXCEPTION"] //16
335 ]Set["Field Missing Exception", "TYPE_FIELDMISSINGEXCEPTION"] 341 ]Set["Field Missing Exception", "TYPE_FIELDMISSINGEXCEPTION"] //17
336 ]Set["Wrong Type Exception", "TYPE_WRONGTYPEEXCEPTION"]] 342 ]Set["Wrong Type Exception", "TYPE_WRONGTYPEEXCEPTION"]] //18
337 ]Definitions << [Dictionary[]] 343 ]Definitions << [Dictionary[]]
338 ]Next ID <<[0] 344 ]Next ID <<[0]
339 } 345 }
340 346
341 _Type Defs C[text,def:out] 347 _Type Defs C[text,def:out]
883 ]Add Raw Line["}"] 889 ]Add Raw Line["}"]
884 ]Resume Index <<[[stream]Resume Index >>] 890 ]Resume Index <<[[stream]Resume Index >>]
885 891
886 } 892 }
887 893
894 Discard Outputs@C Function[func,first to discard:out]
895 {
896 out <- [[[[[func
897 ]Add Raw Line[[["for(idx = "]Append[first to discard]]Append["; idx < cdata->num_params; ++idx)"]]
898 ]Add Raw Line["{"]
899 ]Add Raw Line[" if (cdata->params[idx])"]
900 ]Add Raw Line[" release_ref(cdata->params[idx]);"]
901 ]Add Raw Line["}"]
902 }
903
888 Result Reference@C Function[func,output:out] 904 Result Reference@C Function[func,output:out]
889 { 905 {
890 out <- [["cdata->params["]Append[output]]Append["]"] 906 out <- [["cdata->params["]Append[output]]Append["]"]
891 } 907 }
908
909 Checked Result Reference@C Function[func,output:out]
910 {
911 out <- [[[["("]Append[output]]Append[" < cdata->num_params ? cdata->params["]]Append[output]]Append["] : NULL)"]
912 }
913
892 914
893 If Null Else@C Function[func,left,right:out] 915 If Null Else@C Function[func,left,right:out]
894 { 916 {
895 check <- [[Make Condition[left]]Strip Addref]Make Op[func] 917 check <- [[Make Condition[left]]Strip Addref]Make Op[func]
896 l <- [left]Make Op[func] 918 l <- [left]Make Op[func]
1185 ]Append[[value]Value >>] 1207 ]Append[[value]Value >>]
1186 ]Append[")"] 1208 ]Append[")"]
1187 }{ 1209 }{
1188 If[[valtype] = ["String"]] 1210 If[[valtype] = ["String"]]
1189 { 1211 {
1190 out <- [["make_String(\""]Append[ [[value]Replace["\\", "\\\\"]]Replace["\n", "\\n"]]]Append["\")"] 1212 out <- [["make_String(\""]Append[ [[[value]Replace["\\", "\\\\"]]Replace["\n", "\\n"]]Replace["\"", "\\\""] ]]Append["\")"]
1191 }{ 1213 }{
1192 If[[valtype]=["Worker Literal"]] 1214 If[[valtype]=["Worker Literal"]]
1193 { 1215 {
1194 //TODO: Figure out how to fully support these in nested cases 1216 //TODO: Figure out how to fully support these in nested cases
1195 //or workaround the problem higher up in the food chain 1217 //or workaround the problem higher up in the food chain
1413 ]Append[Fold["_Consts C Program", 1435 ]Append[Fold["_Consts C Program",
1414 Fold["_Defs C Program", "", [program]Functions >>], 1436 Fold["_Defs C Program", "", [program]Functions >>],
1415 constants]] 1437 constants]]
1416 ]Append[Fold[["_Text C Program"]Set Input[2, [program]Type Registry >>], "", Filter[[program]Functions >>, "Not Native"]]] 1438 ]Append[Fold[["_Text C Program"]Set Input[2, [program]Type Registry >>], "", Filter[[program]Functions >>, "Not Native"]]]
1417 ]Append["\n 1439 ]Append["\n
1418 uint16_t rhope(uint32_t func, object ** params, uint16_t numparams, uint16_t callspace) 1440 int32_t rhope(uint32_t func, object ** params, uint16_t numparams, uint16_t callspace)
1419 { 1441 {
1420 uint16_t resume,idx, vcparam_offset, last_vcparam; 1442 uint16_t resume,idx, vcparam_offset, last_vcparam;
1421 context * ct; 1443 context * ct;
1422 calldata * cdata, *temp_cdata, *my_cdata;\n\nFuncDef(Build)\nFuncDef(BlueprintSP_Of)\n"] 1444 calldata * cdata, *temp_cdata, *my_cdata;\n\nFuncDef(Build)\nFuncDef(BlueprintSP_Of)\n"]
1423 ]Append[Fold["Local Pointers", "", [program]Functions >>]] 1445 ]Append[Fold["Local Pointers", "", [program]Functions >>]]
1424 ]Append[" 1446 ]Append["
1425 ct = new_context(); 1447 ct = new_context();
1426 cdata = alloc_cdata(ct, NULL, callspace); 1448 cdata = alloc_cdata(ct, NULL, callspace);
1427 cdata->num_params = numparams; 1449 cdata->num_params = numparams;
1428 for(idx = 0; idx < numparams; ++idx) 1450 for(idx = 0; idx < numparams; ++idx)
1429 cdata->params[0-idx] = params[idx]; 1451 cdata->params[idx] = params[idx];
1430 cdata->func = END; 1452 cdata->func = END;
1431 DISPATCH\n"] 1453 DISPATCH\n"]
1432 ]Append[Fold[["Method Dispatch"]Set Input[3, [program]Type Registry >>], "", all methods]] 1454 ]Append[Fold[["Method Dispatch"]Set Input[3, [program]Type Registry >>], "", all methods]]
1433 ]Append[" 1455 ]Append["
1434 Func(Build, 1456 Func(Build,
1455 DISPATCH\n"] 1477 DISPATCH\n"]
1456 ]Append[Fold[["_Text C Program"]Set Input[2, [program]Type Registry >>], "", Filter[[program]Functions >>, "Native"]]] 1478 ]Append[Fold[["_Text C Program"]Set Input[2, [program]Type Registry >>], "", Filter[[program]Functions >>, "Native"]]]
1457 ]Append[" 1479 ]Append["
1458 DO_END: 1480 DO_END:
1459 for(idx = 0; idx < cdata->num_params; ++idx) 1481 for(idx = 0; idx < cdata->num_params; ++idx)
1460 params[idx] = cdata->params[0-idx]; 1482 params[idx] = cdata->params[idx];
1461 free_context(ct); 1483 free_context(ct);
1462 return cdata->num_params; 1484 return cdata->num_params;
1463 1485
1464 _exception: 1486 _exception:
1465 puts(\"Exception! Trace follows:\"); 1487 puts(\"Exception! Trace follows:\");
1466 while(cdata && cdata->func != END) 1488 while(cdata && cdata->func != END)
1467 { 1489 {
1468 printf(\"%d\\n\", cdata->func); 1490 printf(\"%d\\n\", cdata->func);
1469 cdata = cdata->lastframe; 1491 cdata = cdata->lastframe;
1470 } 1492 }
1471 return 0; 1493 return -1;
1472 } 1494 }
1473 1495
1474 #include \"builtin.c\" 1496 #include \"builtin.c\"
1475 #include \"array.c\" 1497 #include \"array.c\"
1476 #include \"worker.c\" 1498 #include \"worker.c\"
1477 1499
1478 int main(int argc, char **argv) 1500 int main(int argc, char **argv)
1479 { 1501 {
1480 blueprint * bp; 1502 blueprint * bp;
1503 int numret;
1504 int idx;
1505 object * inout[2];
1481 register_builtin_types();\n\n"] 1506 register_builtin_types();\n\n"]
1482 ]Append[ [[program]Type Registry >>]Type Inits[[program]Method Registry >>, [program]Field Registry >>] ] 1507 ]Append[ [[program]Type Registry >>]Type Inits[[program]Method Registry >>, [program]Field Registry >>] ]
1483 ]Append[Fold[["_Set Consts C Program"]Set Input[3, [program]Type Registry >>], "", constants]] 1508 ]Append[Fold[["_Set Consts C Program"]Set Input[3, [program]Type Registry >>], "", constants]]
1484 ]Append[Fold[["_Set Late Consts C"]Set Input[3, [program]Type Registry >>], "", constants]] 1509 ]Append[Fold[["_Set Late Consts C"]Set Input[3, [program]Type Registry >>], "", constants]]
1485 ]Append[" 1510 ]Append["
1486 rhope(FUNC_Main, NULL, 0, 0); 1511 rhope(FUNC_List, inout, 0, 1);
1487 return 0; 1512 for (idx = 0; idx < argc; ++idx)
1513 {
1514 inout[1] = make_String(argv[idx]);
1515 rhope(FUNC_Append, inout, 2, 2);
1516 }
1517 numret = rhope(FUNC_Main, inout, 1, 1);
1518 if (!numret)
1519 return 0;
1520 if (numret < 0)
1521 return numret;
1522 if (get_blueprint(inout[0])->type_id == TYPE_INT32)
1523 return ((t_Int32 *)inout[0])->Num;
1524
1525 rhope(FUNC_If, inout, 1, 2);
1526 if (inout[0])
1527 return 0;
1528 return 1;
1488 }\n\n"] 1529 }\n\n"]
1489 1530
1490 } 1531 }
1491 1532
1492 1533