Mercurial > repos > rhope
diff 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 |
line wrap: on
line diff
--- a/cbackend_c.rhope Thu Oct 14 22:37:20 2010 -0400 +++ b/cbackend_c.rhope Fri Oct 15 00:55:02 2010 -0400 @@ -321,14 +321,14 @@ ]Set["Boolean", "TYPE_BOOLEAN"] //9 ]Set["Float32", "TYPE_FLOAT32"] //10 ]Set["Float64", "TYPE_FLOAT64"] //11 - ]Set["Real Number", "TYPE_FLOAT64"] //12 - ]Set["Blueprint", "TYPE_BLUEPRINT"] //13 - ]Set["Array", "TYPE_ARRAY"] //14 - ]Set["Boxed Array", "TYPE_BOXEDARRAY"]//15 - ]Set["Worker", "TYPE_WORKER"] //16 - ]Set["Method Missing Exception", "TYPE_METHODMISSINGEXCEPTION"] //17 - ]Set["Field Missing Exception", "TYPE_FIELDMISSINGEXCEPTION"] //18 - ]Set["Wrong Type Exception", "TYPE_WRONGTYPEEXCEPTION"]] //19 + ]Set["Real Number", "TYPE_FLOAT64"] + ]Set["Blueprint", "TYPE_BLUEPRINT"] //12 + ]Set["Array", "TYPE_ARRAY"] //13 + ]Set["Boxed Array", "TYPE_BOXEDARRAY"]//14 + ]Set["Worker", "TYPE_WORKER"] //15 + ]Set["Method Missing Exception", "TYPE_METHODMISSINGEXCEPTION"] //16 + ]Set["Field Missing Exception", "TYPE_FIELDMISSINGEXCEPTION"] //17 + ]Set["Wrong Type Exception", "TYPE_WRONGTYPEEXCEPTION"]] //18 ]Definitions << [Dictionary[]] ]Next ID <<[0] ]Escape Pattern <<[p] @@ -632,6 +632,7 @@ result op <- Field Ref[var,field] } + Set Field Null@C Function[func,var,field:out] { out <- [func]Add Statement[ [[func]Field Result[var,field]]Append[" = NULL"] ] @@ -718,17 +719,24 @@ If[[[func]Last NumParams >>] = [-1]] { - freed <- Val[func] - }{ - freed <- [func]Add Raw Line["FreeCall"] - } - prepped <- [[freed]Add Raw Line[ + prepped <- [[func]Add Raw Line[ [[[["VCPrepCall(" ]Append[worker] ]Append[", "] ]Append[String[[rargs]Length]] ]Append[")"] ] ]Last NumParams <<[[rargs]Length] + }{ + prepped <- [[func]Add Raw Line[ + [[[[[["VCRePrepCall(" + ]Append[worker] + ]Append[", "] + ]Append[String[[rargs]Length]] + ]Append[", "] + ]Append[String[[func]Last NumParams >>]] + ]Append[")"] ] + ]Last NumParams <<[[rargs]Length] + } out <- [[[[Fold[_Val Function Arg C[?, ?, ?, worker], prepped, rargs] @@ -951,11 +959,7 @@ } _Var Defs C[string,type,varname,p:out] { - Print[["Variable: "]Append[varname]] - { out <- [[[string]Append[ ["\t"]Append[Rhope Type to C[type,p]] ]]Append[[" "]Append[Escape Rhope Name[varname,p]]]]Append[";\n"] - { Print["Produced Output"]} - } } @@ -1178,6 +1182,20 @@ out <- [text]Append[ [["object * _const_"]Append[Escape Rhope Name[name,p]]]Append[";\n"] ] } +_Consts C Release[text,value,name,p:out] +{ + out <- [text]Append[ [["\trelease_ref(_const_"]Append[Escape Rhope Name[name,p]]]Append[");\n"] ] +} + +_List Literal El[text,val,index,type reg:out] +{ + out <- [[[[text + ]Append[", "] + ]Append[index] + ]Append[", "] + ]Append[Const Construct C[val, type reg]] +} + Const Construct C[value,type reg:out] { valtype <- Blueprint Of[value] @@ -1200,6 +1218,7 @@ { //TODO: Support parametric types typeid <- [type reg]Type ID[[value]Name >>] + out <- [["make_Blueprint("]Append[typeid]]Append[")"] }{ If[[valtype] = [Boolean()]] @@ -1231,7 +1250,12 @@ ]Append[String[Fold[+[1,?], 0, [value]Args >>]]] ]Append[")"] }{ - out <- "UnhandledLiteralType" + [(List(), List Leaf())]Find[=[?,valtype]] + { + out <- [Fold[_List Literal El[?, ?, ?, type reg], ["make_List("]Append[String[[value]Length]], value]]Append[")"] + }{ + out <- "UnhandledLiteralType" + } } } } @@ -1447,8 +1471,9 @@ #include \"blueprint.h\" #include \"array.h\" #include \"worker.h\" -#include \"bool.h\"\n\n" - out <- [[[[[[[[[[[[[[[headers +#include \"bool.h\" +#include <sys/time.h>\n\n" + out <- [[[[[[[[[[[[[[[[[headers ]Append[[program]Dispatch[all methods]] ]Append[[[program]Type Registry >>]Type Defs] ]Append[Fold[_Consts C Program[?,?,?,p], @@ -1456,8 +1481,19 @@ constants]] ]Append[Fold[_Text C Program[?, ?, [program]Type Registry >>], "", Filter[[program]Functions >>, Not Native[?]]]] ]Append["\n +#ifdef ENABLE_PROFILING +uint64_t profile_counts[END]; +uint64_t profile_nestedcounts[END]; +uint64_t profile_totals[END]; +uint64_t profile_selftotals[END]; +uint64_t profile_activationlevel[END]; +#endif + int32_t rhope(uint32_t func, object ** params, uint16_t numparams, uint16_t callspace) { +#ifdef ENABLE_PROFILING + struct timeval time; +#endif uint16_t resume,idx, vcparam_offset, last_vcparam; context * ct; calldata * cdata, *temp_cdata, *my_cdata; @@ -1555,7 +1591,7 @@ blueprint * bp; int numret; int idx; - object * inout[2]; + object * inout[3]; register_builtin_types();\n\n"] ]Append[ [[program]Type Registry >>]Type Inits[[program]Method Registry >>, [program]Field Registry >>] ] ]Append[Fold[_Set Consts C Program[?, ?, ?, [program]Type Registry >>], "", constants]] @@ -1567,7 +1603,20 @@ inout[1] = make_String(argv[idx]); rhope(FUNC_Append, inout, 2, 2); } - numret = rhope(FUNC_Main, inout, 1, 1); + numret = rhope(FUNC_Main, inout, 1, 1);"] + ]Append[Fold[_Consts C Release[?, ?, ?, p], "", constants]] + ]Append[ + " + print_mem_info(manager); + print_live_object_types(manager); + +#ifdef ENABLE_PROFILING + for (idx = 0; idx < END; ++idx) + { + if(profile_counts[idx]) + 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]); + } +#endif if (!numret) return 0; if (numret < 0)