# HG changeset patch # User Mike Pavone # Date 1287118502 14400 # Node ID b3f56e1d54a0443f950e43d9a082ff5ee05e45fb # Parent 4d089503fb51e41115c1bb9d926b9749826b731b Merged changes from interpreted version of compiler to compiled version diff -r 4d089503fb51 -r b3f56e1d54a0 cbackend_c.rhope --- 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 \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) diff -r 4d089503fb51 -r b3f56e1d54a0 nworker_c.rhope --- a/nworker_c.rhope Thu Oct 14 22:37:20 2010 -0400 +++ b/nworker_c.rhope Fri Oct 15 00:55:02 2010 -0400 @@ -482,9 +482,27 @@ out,node index <- [worker]Add Typed Input[name,number,Type Instance["Any Type"]] } +Add Anon Input@NWorker[worker,number:out] +{ + If[[number]>[Length[[worker]Inputs >>]]] + { + prepped <- [worker]Add Anon Input[[number]-[1]] + }{ + prepped <- Val[worker] + } + out <- out <- [[prepped]Inputs <<[[[prepped]Inputs >>]Set[number,[" unnamed"]Append[String[number]]]] + ]Input Types <<[[[prepped]Input Types >>]Set[number,Type Instance["Any Type"]]] +} + Add Typed Input@NWorker[worker,name,number,type:out,node index] { - ,node index <- [worker]Add Node["input",number,0,1] + If[[number]>[Length[[worker]Inputs >>]]] + { + prepped <- [worker]Add Anon Input[[number]-[1]] + }{ + prepped <- Val[worker] + } + ,node index <- [prepped]Add Node["input",number,0,1] { out <- [[~]Inputs <<[[[~]Inputs >>]Set[number,name]] ]Input Types <<[[[~]Input Types >>]Set[number,type]] @@ -882,7 +900,7 @@ [conditions]For Backend { stream <- [[withconst]Instruction Stream - ]Move[Constant[constname], Result Var Name[0, node index]] + ]Move[Strip Addref[Constant[constname]], Result Var Name[0, node index]] nfunc <- [withconst]Do If[~, stream] }{ nfunc <- Val[withconst] @@ -1082,6 +1100,27 @@ } } +Release Raw Inputs[func,input type,index,inputs,outputs:out] +{ + If[[[input type]Variant >>] = ["Raw Pointer"]] + { + name <- [inputs]Index[index] + If[[input type]Mutable? >>] + { + [outputs]Find[=[?,[inputs]Index[index]]] + { + out <- func + }{ + out <- [func]Release[name] + } + }{ + out <- [func]Release[name] + } + }{ + out <- func + } +} + FParams[input:out] { iname <- [input]Index[0] @@ -1164,8 +1203,9 @@ Fold[FInputs[?, ?, ?, [worker]Inputs >>], rfunc, [worker]Input Types >>] { [~]Call Foreign[name, [worker]Convention >>, Map[Zip[[worker]Inputs >>, [worker]Input Types >>], FParams[?]], rparam] + { Fold[Release Raw Inputs[?, ?, ?, [worker]Inputs >>, [worker]Outputs >>], ~, [worker]Input Types >>] { Fold[Save Foreign Result[?, ?, ?, [worker]Output Types >>, [worker]Inputs >>, [worker]Input Types >>], ~, [worker]Outputs >>] - { out <- [program]Store Function[~] }}} + { out <- [program]Store Function[~] }}}} } Compile Worker@NWorker[worker,program,name:out] @@ -1364,8 +1404,17 @@ { //Rhope identifiers can't start with spaces, so we can use identifiers that start with spaces for special functions init name <- [" init "]Append[name] - copy name <- [" copy "]Append[name] - cleanup name <- [" cleanup "]Append[name] + [("Array","Boxed Array","Worker")]Find[=[?,name]] + { + [("internalarraynaked","internalarrayboxed","internalworker")]Index[~] + { + copy name <- [~]Append["copy"] + cleanup name <- [~]Append["cleanup"] + } + }{ + copy name <- [" copy "]Append[name] + cleanup name <- [" cleanup "]Append[name] + } type <- [[[Fold[_Compile Blueprint Methods[?], Fold[_Compile Blueprint Fields[?], [backend]Create Type[name], [bp]Fields >>], [bp]Methods >>] ]Init <<[init name] ]Copy <<[copy name] @@ -1377,14 +1426,17 @@ Compile Special@NBlueprint[bp,backend,name:out] { init name <- [" init "]Append[name] - copy name <- [" copy "]Append[name] - cleanup name <- [" cleanup "]Append[name] - got specials <- [bp]Make Special[ - [bp]Make Special[ - [bp]Make Special[backend, init name, name, Make Init[?]], - copy name, name, Make Copy[?]], - cleanup name, name, Make Cleanup[?]] - out <- Fold[Getters Setters[?, ?, name], got specials, [bp]Fields >>] + [("Array","Boxed Array","Worker")]Find[=[?,name]] + { + after copyclean <- Val[backend] + }{ + copy name <- [" copy "]Append[name] + cleanup name <- [" cleanup "]Append[name] + after copyclean <- [bp]Make Special[ + [bp]Make Special[backend, copy name, name, Make Copy[?]], + cleanup name, name, Make Cleanup[?]] + } + out <- Fold[Getters Setters[?, ?, name], [bp]Make Special[after copyclean, init name, name, Make Init[?]], [bp]Fields >>] } Blueprint NProgram