Mercurial > repos > rhope
comparison cbackend_c.rhope @ 118:b3f56e1d54a0
Merged changes from interpreted version of compiler to compiled version
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 15 Oct 2010 00:55:02 -0400 |
parents | b7df624895b2 |
children | cd25171e1bb2 |
comparison
equal
deleted
inserted
replaced
117:4d089503fb51 | 118:b3f56e1d54a0 |
---|---|
319 ]Set["Int32", "TYPE_INT32"] //7 | 319 ]Set["Int32", "TYPE_INT32"] //7 |
320 ]Set["Int64", "TYPE_INT64"] //8 | 320 ]Set["Int64", "TYPE_INT64"] //8 |
321 ]Set["Boolean", "TYPE_BOOLEAN"] //9 | 321 ]Set["Boolean", "TYPE_BOOLEAN"] //9 |
322 ]Set["Float32", "TYPE_FLOAT32"] //10 | 322 ]Set["Float32", "TYPE_FLOAT32"] //10 |
323 ]Set["Float64", "TYPE_FLOAT64"] //11 | 323 ]Set["Float64", "TYPE_FLOAT64"] //11 |
324 ]Set["Real Number", "TYPE_FLOAT64"] //12 | 324 ]Set["Real Number", "TYPE_FLOAT64"] |
325 ]Set["Blueprint", "TYPE_BLUEPRINT"] //13 | 325 ]Set["Blueprint", "TYPE_BLUEPRINT"] //12 |
326 ]Set["Array", "TYPE_ARRAY"] //14 | 326 ]Set["Array", "TYPE_ARRAY"] //13 |
327 ]Set["Boxed Array", "TYPE_BOXEDARRAY"]//15 | 327 ]Set["Boxed Array", "TYPE_BOXEDARRAY"]//14 |
328 ]Set["Worker", "TYPE_WORKER"] //16 | 328 ]Set["Worker", "TYPE_WORKER"] //15 |
329 ]Set["Method Missing Exception", "TYPE_METHODMISSINGEXCEPTION"] //17 | 329 ]Set["Method Missing Exception", "TYPE_METHODMISSINGEXCEPTION"] //16 |
330 ]Set["Field Missing Exception", "TYPE_FIELDMISSINGEXCEPTION"] //18 | 330 ]Set["Field Missing Exception", "TYPE_FIELDMISSINGEXCEPTION"] //17 |
331 ]Set["Wrong Type Exception", "TYPE_WRONGTYPEEXCEPTION"]] //19 | 331 ]Set["Wrong Type Exception", "TYPE_WRONGTYPEEXCEPTION"]] //18 |
332 ]Definitions << [Dictionary[]] | 332 ]Definitions << [Dictionary[]] |
333 ]Next ID <<[0] | 333 ]Next ID <<[0] |
334 ]Escape Pattern <<[p] | 334 ]Escape Pattern <<[p] |
335 } | 335 } |
336 | 336 |
630 { | 630 { |
631 out <- func | 631 out <- func |
632 result op <- Field Ref[var,field] | 632 result op <- Field Ref[var,field] |
633 } | 633 } |
634 | 634 |
635 | |
635 Set Field Null@C Function[func,var,field:out] | 636 Set Field Null@C Function[func,var,field:out] |
636 { | 637 { |
637 out <- [func]Add Statement[ [[func]Field Result[var,field]]Append[" = NULL"] ] | 638 out <- [func]Add Statement[ [[func]Field Result[var,field]]Append[" = NULL"] ] |
638 } | 639 } |
639 | 640 |
716 worker <- Make Op[Strip Addref[to call], func] | 717 worker <- Make Op[Strip Addref[to call], func] |
717 rargs <- Map[args, Make Op[?, func]] | 718 rargs <- Map[args, Make Op[?, func]] |
718 | 719 |
719 If[[[func]Last NumParams >>] = [-1]] | 720 If[[[func]Last NumParams >>] = [-1]] |
720 { | 721 { |
721 freed <- Val[func] | 722 prepped <- [[func]Add Raw Line[ |
722 }{ | |
723 freed <- [func]Add Raw Line["FreeCall"] | |
724 } | |
725 prepped <- [[freed]Add Raw Line[ | |
726 [[[["VCPrepCall(" | 723 [[[["VCPrepCall(" |
727 ]Append[worker] | 724 ]Append[worker] |
728 ]Append[", "] | 725 ]Append[", "] |
729 ]Append[String[[rargs]Length]] | 726 ]Append[String[[rargs]Length]] |
730 ]Append[")"] ] | 727 ]Append[")"] ] |
731 ]Last NumParams <<[[rargs]Length] | 728 ]Last NumParams <<[[rargs]Length] |
729 }{ | |
730 prepped <- [[func]Add Raw Line[ | |
731 [[[[[["VCRePrepCall(" | |
732 ]Append[worker] | |
733 ]Append[", "] | |
734 ]Append[String[[rargs]Length]] | |
735 ]Append[", "] | |
736 ]Append[String[[func]Last NumParams >>]] | |
737 ]Append[")"] ] | |
738 ]Last NumParams <<[[rargs]Length] | |
739 } | |
732 | 740 |
733 | 741 |
734 out <- [[[[Fold[_Val Function Arg C[?, ?, ?, worker], prepped, rargs] | 742 out <- [[[[Fold[_Val Function Arg C[?, ?, ?, worker], prepped, rargs] |
735 ]Add Raw Line[ | 743 ]Add Raw Line[ |
736 [[[[[[[["ValCall(" | 744 [[[[[[[["ValCall(" |
949 { | 957 { |
950 out <- [[[string]Append[ ["\t"]Append[Rhope Type to C[[[func]Output Types >>]Index[index],[func]Escape Pattern >>]] ]]Append[[" "]Append[Escape Rhope Name[varname,[func]Escape Pattern >>]]]]Append[";\n"] | 958 out <- [[[string]Append[ ["\t"]Append[Rhope Type to C[[[func]Output Types >>]Index[index],[func]Escape Pattern >>]] ]]Append[[" "]Append[Escape Rhope Name[varname,[func]Escape Pattern >>]]]]Append[";\n"] |
951 } | 959 } |
952 _Var Defs C[string,type,varname,p:out] | 960 _Var Defs C[string,type,varname,p:out] |
953 { | 961 { |
954 Print[["Variable: "]Append[varname]] | |
955 { | |
956 out <- [[[string]Append[ ["\t"]Append[Rhope Type to C[type,p]] ]]Append[[" "]Append[Escape Rhope Name[varname,p]]]]Append[";\n"] | 962 out <- [[[string]Append[ ["\t"]Append[Rhope Type to C[type,p]] ]]Append[[" "]Append[Escape Rhope Name[varname,p]]]]Append[";\n"] |
957 { Print["Produced Output"]} | |
958 } | |
959 } | 963 } |
960 | 964 |
961 | 965 |
962 Definitions@C Function[func:out] | 966 Definitions@C Function[func:out] |
963 { | 967 { |
1176 _Consts C Program[text,value,name,p:out] | 1180 _Consts C Program[text,value,name,p:out] |
1177 { | 1181 { |
1178 out <- [text]Append[ [["object * _const_"]Append[Escape Rhope Name[name,p]]]Append[";\n"] ] | 1182 out <- [text]Append[ [["object * _const_"]Append[Escape Rhope Name[name,p]]]Append[";\n"] ] |
1179 } | 1183 } |
1180 | 1184 |
1185 _Consts C Release[text,value,name,p:out] | |
1186 { | |
1187 out <- [text]Append[ [["\trelease_ref(_const_"]Append[Escape Rhope Name[name,p]]]Append[");\n"] ] | |
1188 } | |
1189 | |
1190 _List Literal El[text,val,index,type reg:out] | |
1191 { | |
1192 out <- [[[[text | |
1193 ]Append[", "] | |
1194 ]Append[index] | |
1195 ]Append[", "] | |
1196 ]Append[Const Construct C[val, type reg]] | |
1197 } | |
1198 | |
1181 Const Construct C[value,type reg:out] | 1199 Const Construct C[value,type reg:out] |
1182 { | 1200 { |
1183 valtype <- Blueprint Of[value] | 1201 valtype <- Blueprint Of[value] |
1184 [(Int8(),UInt8(),Int16(),UInt16(),Int32(),UInt32(),Int64(),UInt64())]Find[=[valtype,?]] | 1202 [(Int8(),UInt8(),Int16(),UInt16(),Int32(),UInt32(),Int64(),UInt64())]Find[=[valtype,?]] |
1185 { | 1203 { |
1198 }{ | 1216 }{ |
1199 If[[valtype] = [Type Instance()]] | 1217 If[[valtype] = [Type Instance()]] |
1200 { | 1218 { |
1201 //TODO: Support parametric types | 1219 //TODO: Support parametric types |
1202 typeid <- [type reg]Type ID[[value]Name >>] | 1220 typeid <- [type reg]Type ID[[value]Name >>] |
1221 | |
1203 out <- [["make_Blueprint("]Append[typeid]]Append[")"] | 1222 out <- [["make_Blueprint("]Append[typeid]]Append[")"] |
1204 }{ | 1223 }{ |
1205 If[[valtype] = [Boolean()]] | 1224 If[[valtype] = [Boolean()]] |
1206 { | 1225 { |
1207 If[value] | 1226 If[value] |
1229 ]Append[size] | 1248 ]Append[size] |
1230 ]Append[", "] | 1249 ]Append[", "] |
1231 ]Append[String[Fold[+[1,?], 0, [value]Args >>]]] | 1250 ]Append[String[Fold[+[1,?], 0, [value]Args >>]]] |
1232 ]Append[")"] | 1251 ]Append[")"] |
1233 }{ | 1252 }{ |
1234 out <- "UnhandledLiteralType" | 1253 [(List(), List Leaf())]Find[=[?,valtype]] |
1254 { | |
1255 out <- [Fold[_List Literal El[?, ?, ?, type reg], ["make_List("]Append[String[[value]Length]], value]]Append[")"] | |
1256 }{ | |
1257 out <- "UnhandledLiteralType" | |
1258 } | |
1235 } | 1259 } |
1236 } | 1260 } |
1237 } | 1261 } |
1238 } | 1262 } |
1239 | 1263 |
1445 #include \"func.h\" | 1469 #include \"func.h\" |
1446 #include \"integer.h\" | 1470 #include \"integer.h\" |
1447 #include \"blueprint.h\" | 1471 #include \"blueprint.h\" |
1448 #include \"array.h\" | 1472 #include \"array.h\" |
1449 #include \"worker.h\" | 1473 #include \"worker.h\" |
1450 #include \"bool.h\"\n\n" | 1474 #include \"bool.h\" |
1451 out <- [[[[[[[[[[[[[[[headers | 1475 #include <sys/time.h>\n\n" |
1476 out <- [[[[[[[[[[[[[[[[[headers | |
1452 ]Append[[program]Dispatch[all methods]] | 1477 ]Append[[program]Dispatch[all methods]] |
1453 ]Append[[[program]Type Registry >>]Type Defs] | 1478 ]Append[[[program]Type Registry >>]Type Defs] |
1454 ]Append[Fold[_Consts C Program[?,?,?,p], | 1479 ]Append[Fold[_Consts C Program[?,?,?,p], |
1455 Fold[_Defs C Program[?], "", [program]Functions >>], | 1480 Fold[_Defs C Program[?], "", [program]Functions >>], |
1456 constants]] | 1481 constants]] |
1457 ]Append[Fold[_Text C Program[?, ?, [program]Type Registry >>], "", Filter[[program]Functions >>, Not Native[?]]]] | 1482 ]Append[Fold[_Text C Program[?, ?, [program]Type Registry >>], "", Filter[[program]Functions >>, Not Native[?]]]] |
1458 ]Append["\n | 1483 ]Append["\n |
1484 #ifdef ENABLE_PROFILING | |
1485 uint64_t profile_counts[END]; | |
1486 uint64_t profile_nestedcounts[END]; | |
1487 uint64_t profile_totals[END]; | |
1488 uint64_t profile_selftotals[END]; | |
1489 uint64_t profile_activationlevel[END]; | |
1490 #endif | |
1491 | |
1459 int32_t rhope(uint32_t func, object ** params, uint16_t numparams, uint16_t callspace) | 1492 int32_t rhope(uint32_t func, object ** params, uint16_t numparams, uint16_t callspace) |
1460 { | 1493 { |
1494 #ifdef ENABLE_PROFILING | |
1495 struct timeval time; | |
1496 #endif | |
1461 uint16_t resume,idx, vcparam_offset, last_vcparam; | 1497 uint16_t resume,idx, vcparam_offset, last_vcparam; |
1462 context * ct; | 1498 context * ct; |
1463 calldata * cdata, *temp_cdata, *my_cdata; | 1499 calldata * cdata, *temp_cdata, *my_cdata; |
1464 DispatchVar | 1500 DispatchVar |
1465 FuncDef(Build) | 1501 FuncDef(Build) |
1553 int main(int argc, char **argv) | 1589 int main(int argc, char **argv) |
1554 { | 1590 { |
1555 blueprint * bp; | 1591 blueprint * bp; |
1556 int numret; | 1592 int numret; |
1557 int idx; | 1593 int idx; |
1558 object * inout[2]; | 1594 object * inout[3]; |
1559 register_builtin_types();\n\n"] | 1595 register_builtin_types();\n\n"] |
1560 ]Append[ [[program]Type Registry >>]Type Inits[[program]Method Registry >>, [program]Field Registry >>] ] | 1596 ]Append[ [[program]Type Registry >>]Type Inits[[program]Method Registry >>, [program]Field Registry >>] ] |
1561 ]Append[Fold[_Set Consts C Program[?, ?, ?, [program]Type Registry >>], "", constants]] | 1597 ]Append[Fold[_Set Consts C Program[?, ?, ?, [program]Type Registry >>], "", constants]] |
1562 ]Append[Fold[_Set Late Consts C[?, ?, ?, [program]Type Registry >>], "", constants]] | 1598 ]Append[Fold[_Set Late Consts C[?, ?, ?, [program]Type Registry >>], "", constants]] |
1563 ]Append[" | 1599 ]Append[" |
1565 for (idx = 0; idx < argc; ++idx) | 1601 for (idx = 0; idx < argc; ++idx) |
1566 { | 1602 { |
1567 inout[1] = make_String(argv[idx]); | 1603 inout[1] = make_String(argv[idx]); |
1568 rhope(FUNC_Append, inout, 2, 2); | 1604 rhope(FUNC_Append, inout, 2, 2); |
1569 } | 1605 } |
1570 numret = rhope(FUNC_Main, inout, 1, 1); | 1606 numret = rhope(FUNC_Main, inout, 1, 1);"] |
1607 ]Append[Fold[_Consts C Release[?, ?, ?, p], "", constants]] | |
1608 ]Append[ | |
1609 " | |
1610 print_mem_info(manager); | |
1611 print_live_object_types(manager); | |
1612 | |
1613 #ifdef ENABLE_PROFILING | |
1614 for (idx = 0; idx < END; ++idx) | |
1615 { | |
1616 if(profile_counts[idx]) | |
1617 printf(\"Func: %d\tCount: %llu\tTime: %llu\tAvg: %f\tSelf: %llu\tAvg: %f\tNested Count: %llu\\n\", idx, profile_counts[idx], profile_totals[idx], ((double)profile_totals[idx])/((double)profile_counts[idx]), profile_selftotals[idx], ((double)profile_selftotals[idx])/((double)profile_counts[idx]), profile_nestedcounts[idx]); | |
1618 } | |
1619 #endif | |
1571 if (!numret) | 1620 if (!numret) |
1572 return 0; | 1621 return 0; |
1573 if (numret < 0) | 1622 if (numret < 0) |
1574 return numret; | 1623 return numret; |
1575 if (get_blueprint(inout[0])->type_id == TYPE_INT32) | 1624 if (get_blueprint(inout[0])->type_id == TYPE_INT32) |