# HG changeset patch # User Mike Pavone # Date 1299730598 0 # Node ID 1bfc19076f1bfb54e5ff68cfdf033d709c47f50c # Parent 47ab97730865a3b1fa99f8accfeda9bcbe60f097# Parent 429afd920a23dd29c50cb42bd268a6e82b537fa7 Merge diff -r 47ab97730865 -r 1bfc19076f1b cbackend_c.rhope --- a/cbackend_c.rhope Thu Mar 10 04:15:37 2011 +0000 +++ b/cbackend_c.rhope Thu Mar 10 04:16:38 2011 +0000 @@ -1641,178 +1641,16 @@ 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 proftime; -#endif - uint16_t resume,idx, vcparam_offset, last_vcparam; - context *ct,*temp_ct; - void *tmp; - calldata * cdata, *temp_cdata, *my_cdata; - DispatchVar - FuncDef(Build) - FuncDef(BlueprintSP_Of) - FuncDef(ID) - FuncDef(BlueprintSP_FromSP_ID)\n"] +#include \"rhopefuncs_prolog.c\"\n"] ]Append[Fold[Local Pointers[?], "", [program]Functions >>]] ]Append[" - ct = new_context(); - cdata = alloc_cdata(ct, NULL, callspace); - cdata->num_params = numparams; - for(idx = 0; idx < numparams; ++idx) - cdata->params[idx] = params[idx]; - cdata->func = END; -DISPATCH\n"] +#include \"localpointers_fragment.c\"\n"] ]Append[Fold[Method Dispatch[?, ?, ?, [program]Type Registry >>], "", all methods]] ]Append[" -Func(Build, - NumParams 1) - - Param(0, TYPE_BLUEPRINT) - - lv_Build->bp = ((t_Blueprint *)(cdata->params[0]))->bp; - release_ref(cdata->params[0]); - - Ret(0, new_object_bp(lv_Build->bp)) -EndFunc(Build) -DISPATCH - -Func(BlueprintSP_Of, - NumParams 1) - - lv_BlueprintSP_Of->bp = get_blueprint(cdata->params[0]); - release_ref(cdata->params[0]); - - Ret(0, new_object(TYPE_BLUEPRINT)) - ((t_Blueprint *)cdata->params[0])->bp = lv_BlueprintSP_Of->bp; -EndFunc(BlueprintSP_Of) -DISPATCH - -Func(ID, NumParams 1) - - Param(0, TYPE_BLUEPRINT) - - lv_ID->id = new_object(TYPE_UINT32); - ((t_UInt32 *)lv_ID->id)->Num = ((t_Blueprint *)cdata->params[0])->bp->type_id; - release_ref(cdata->params[0]); - Ret(0, lv_ID->id) -EndFunc(ID) -DISPATCH - -Func(BlueprintSP_FromSP_ID, NumParams 1) - - Param(0, TYPE_UINT32) - - lv_BlueprintSP_FromSP_ID->type = ((t_UInt32 *)cdata->params[0])->Num; - if (lv_BlueprintSP_FromSP_ID->type >= max_registered_type || !registered_types[lv_BlueprintSP_FromSP_ID->type]) { - Ret(1, cdata->params[0]) - Ret(0, NULL) - } else { - release_ref(cdata->params[0]); - Ret(0, new_object(TYPE_BLUEPRINT)) - ((t_Blueprint *)cdata->params[0])->bp = registered_types[lv_BlueprintSP_FromSP_ID->type]; - Ret(1, NULL) - } - -EndFunc(BlueprintSP_FromSP_ID) -DISPATCH - -FuncNoLocals(Pause, NumParams 1) - Param(0, TYPE_WORKER) - - ct->resume_cdata = my_cdata; - ct->resumeable = 1; - temp_ct = ct; - ct = new_context(); - VCPrepCall(my_cdata->params[0], 1) - VCSetParam(my_cdata->params[0], 0, make_Context(temp_ct)) - ValCallNoLocals(my_cdata->params[0], 1, 1, Pause) - release_ref(my_cdata->params[0]); - DISPATCH - ValCallNoLocalsPostlude(1, Pause) - for(idx = 0; idx < cdata->num_params; ++idx) - if(cdata->params[idx]) - { release_ref(cdata->params[idx]); } - free_context(ct); - ct = get_cqueue(); - if (!ct) goto NOTHING_TO_DO; - cdata = ct->resume_cdata; - ct->resume_cdata = NULL; -EndFuncNoLocals -DISPATCH - -FuncNoLocals(Resume, NumParams 2) - Param(0, TYPE_CONTEXT) - - temp_ct = ((t_Context *)my_cdata->params[0])->ct; - release_ref(my_cdata->params[0]); - if(temp_ct->resumeable && temp_ct->resume_cdata) - { - temp_ct->resumeable = 0; - temp_ct->resume_cdata->params[0] = add_ref(my_cdata->params[1]); - my_cdata->params[0] = my_cdata->params[1]; - my_cdata->params[1] = NULL; - if(!put_cqueue(temp_ct)) - { - ct->resume_cdata = my_cdata; - temp_ct->runafter = ct; - ct = temp_ct; - cdata = ct->resume_cdata; - ct->resume_cdata = NULL; - } - } else { - my_cdata->params[0] = NULL; - } -EndFuncNoLocals -DISPATCH\n"] +#include \"builtinworkers.c\"\n"] ]Append[Fold[_Text C Program[?, ?, [program]Type Registry >>], "", Filter[[program]Functions >>, Native[?]]]] ]Append[" -DO_END: - for(idx = 0; idx < cdata->num_params; ++idx) - params[idx] = cdata->params[idx]; - free_context(ct); - return cdata->num_params; - -DO_END_THREAD: - for(idx = 0; idx < cdata->num_params; ++idx) - { release_ref(cdata->params[idx]); } - if(ct->runafter) - { - temp_ct = ct; - ct = ct->runafter; - free_context(temp_ct); - cdata = ct->resume_cdata; - func = cdata->func; - DISPATCH - } - free_context(ct); - if(ct = get_cqueue()) - { - cdata = ct->resume_cdata; - func = cdata->func; - DISPATCH - } -NOTHING_TO_DO: - return 0; - -_exception: - puts(\"Exception! Trace follows:\"); - while(cdata && cdata->func < END) - { - printf(\"%d\\n\", cdata->func); - cdata = cdata->lastframe; - } - return -1; -} +#include \"rhopefuncs_epilog.c\" #include \"builtin.c\" #include \"array.c\" diff -r 47ab97730865 -r 1bfc19076f1b kernel.rhope --- a/kernel.rhope Thu Mar 10 04:15:37 2011 +0000 +++ b/kernel.rhope Thu Mar 10 04:16:38 2011 +0000 @@ -183,6 +183,7 @@ Foreign C:runtime { _internal_blueprint_eq[left(Blueprint),right(Blueprint):out(Int32,Naked)] + _internal_blueprint_rawsize[bp(Blueprint):out(Int32,Naked)] _internal_worker_alloc[size(Int16,Naked):out(Worker)] _internal_worker_setinput[worker(Worker,Boxed,Mutable),num(Int16,Naked),val:worker] _internal_worker_getinput[worker(Worker),num(Int16,Naked):out] @@ -248,6 +249,11 @@ out <- [_internal_blueprint_eq[left,right]]!=[0] } +Raw Size@Blueprint[bp:out] +{ + out <- _internal_blueprint_rawsize[bp] +} + _Keys[list,val,key:out] { out <- [list]Append[key] diff -r 47ab97730865 -r 1bfc19076f1b net.rhope --- a/net.rhope Thu Mar 10 04:15:37 2011 +0000 +++ b/net.rhope Thu Mar 10 04:16:38 2011 +0000 @@ -309,7 +309,15 @@ { If[[buffer]Length] { - out,err <- [con]_Write[buffer,0] + If[[Raw Size[[buffer]Eltype >>]] > [1]] + { + bytelen <- [[buffer]Length]*[Raw Size[[buffer]Eltype >>]] + //Copy to a byte buffer until we have a better way of writing from an arbitrary byte offset + bbuffer <- [_internal_array_copychunk[buffer, 0, _internal_array_allocnaked[bytelen, UInt8()], 0, [buffer]Length]]Length <<[bytelen] + }{ + bbuffer <- Val[buffer] + } + out,err <- [con]_Write[bbuffer,0] }{ out <- con } @@ -395,6 +403,15 @@ } } +Read Type@TCP Connection[con,toread(Int32),type(Blueprint):data,out con,err] +{ + toreadbytes <- [toread]*[Raw Size[type]] + ,out con,err <- [con]Read[toreadbytes] + { + data <- [_internal_array_copychunk[~, 0, _internal_array_allocnaked[toread, type], 0, toreadbytes]]Length <<[toread] + } +} + _Check Partial[buffer,delim,offset:partial,none] { none <- If[[offset]=[[buffer]Length]] {} diff -r 47ab97730865 -r 1bfc19076f1b runtime/blueprint.c --- a/runtime/blueprint.c Thu Mar 10 04:15:37 2011 +0000 +++ b/runtime/blueprint.c Thu Mar 10 04:16:38 2011 +0000 @@ -26,4 +26,12 @@ return l->bp == r->bp; } +int32_t _internal_blueprint_rawsize(object * bp) +{ + int32_t ret; + t_Blueprint * bprint = (t_Blueprint *)bp; + ret = bprint->bp->size; + release_ref(bp); + return ret; +} diff -r 47ab97730865 -r 1bfc19076f1b runtime/blueprint.h --- a/runtime/blueprint.h Thu Mar 10 04:15:37 2011 +0000 +++ b/runtime/blueprint.h Thu Mar 10 04:16:38 2011 +0000 @@ -9,6 +9,7 @@ object * make_Blueprint(int32_t type_id); int32_t _internal_blueprint_eq(object * left, object * right); +int32_t _internal_blueprint_rawsize(object * bp); typedef struct { blueprint * bp; diff -r 47ab97730865 -r 1bfc19076f1b runtime/builtinworkers.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/runtime/builtinworkers.c Thu Mar 10 04:16:38 2011 +0000 @@ -0,0 +1,101 @@ +Func(Build, + NumParams 1) + + Param(0, TYPE_BLUEPRINT) + + lv_Build->bp = ((t_Blueprint *)(cdata->params[0]))->bp; + release_ref(cdata->params[0]); + + Ret(0, new_object_bp(lv_Build->bp)) +EndFunc(Build) +DISPATCH + +Func(BlueprintSP_Of, + NumParams 1) + + lv_BlueprintSP_Of->bp = get_blueprint(cdata->params[0]); + release_ref(cdata->params[0]); + + Ret(0, new_object(TYPE_BLUEPRINT)) + ((t_Blueprint *)cdata->params[0])->bp = lv_BlueprintSP_Of->bp; +EndFunc(BlueprintSP_Of) +DISPATCH + +Func(ID, NumParams 1) + + Param(0, TYPE_BLUEPRINT) + + lv_ID->id = new_object(TYPE_UINT32); + ((t_UInt32 *)lv_ID->id)->Num = ((t_Blueprint *)cdata->params[0])->bp->type_id; + release_ref(cdata->params[0]); + Ret(0, lv_ID->id) +EndFunc(ID) +DISPATCH + +Func(BlueprintSP_FromSP_ID, NumParams 1) + + Param(0, TYPE_UINT32) + + lv_BlueprintSP_FromSP_ID->type = ((t_UInt32 *)cdata->params[0])->Num; + if (lv_BlueprintSP_FromSP_ID->type >= max_registered_type || !registered_types[lv_BlueprintSP_FromSP_ID->type]) { + Ret(1, cdata->params[0]) + Ret(0, NULL) + } else { + release_ref(cdata->params[0]); + Ret(0, new_object(TYPE_BLUEPRINT)) + ((t_Blueprint *)cdata->params[0])->bp = registered_types[lv_BlueprintSP_FromSP_ID->type]; + Ret(1, NULL) + } + +EndFunc(BlueprintSP_FromSP_ID) +DISPATCH + +FuncNoLocals(Pause, NumParams 1) + Param(0, TYPE_WORKER) + + ct->resume_cdata = my_cdata; + ct->resumeable = 1; + temp_ct = ct; + ct = new_context(); + VCPrepCall(my_cdata->params[0], 1) + VCSetParam(my_cdata->params[0], 0, make_Context(temp_ct)) + ValCallNoLocals(my_cdata->params[0], 1, 1, Pause) + release_ref(my_cdata->params[0]); + DISPATCH + ValCallNoLocalsPostlude(1, Pause) + for(idx = 0; idx < cdata->num_params; ++idx) + if(cdata->params[idx]) + { release_ref(cdata->params[idx]); } + free_context(ct); + ct = get_cqueue(); + if (!ct) goto NOTHING_TO_DO; + cdata = ct->resume_cdata; + ct->resume_cdata = NULL; +EndFuncNoLocals +DISPATCH + +FuncNoLocals(Resume, NumParams 2) + Param(0, TYPE_CONTEXT) + + temp_ct = ((t_Context *)my_cdata->params[0])->ct; + release_ref(my_cdata->params[0]); + if(temp_ct->resumeable && temp_ct->resume_cdata) + { + temp_ct->resumeable = 0; + temp_ct->resume_cdata->params[0] = add_ref(my_cdata->params[1]); + my_cdata->params[0] = my_cdata->params[1]; + my_cdata->params[1] = NULL; + if(!put_cqueue(temp_ct)) + { + ct->resume_cdata = my_cdata; + temp_ct->runafter = ct; + ct = temp_ct; + cdata = ct->resume_cdata; + ct->resume_cdata = NULL; + } + } else { + my_cdata->params[0] = NULL; + } +EndFuncNoLocals +DISPATCH + diff -r 47ab97730865 -r 1bfc19076f1b runtime/localpointers_fragment.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/runtime/localpointers_fragment.c Thu Mar 10 04:16:38 2011 +0000 @@ -0,0 +1,8 @@ + ct = new_context(); + cdata = alloc_cdata(ct, NULL, callspace); + cdata->num_params = numparams; + for(idx = 0; idx < numparams; ++idx) + cdata->params[idx] = params[idx]; + cdata->func = END; +DISPATCH + diff -r 47ab97730865 -r 1bfc19076f1b runtime/object.h --- a/runtime/object.h Thu Mar 10 04:15:37 2011 +0000 +++ b/runtime/object.h Thu Mar 10 04:16:38 2011 +0000 @@ -27,8 +27,8 @@ uint32_t last_convertto; uint32_t first_convertfrom; uint32_t last_convertfrom; - int32_t size; - int32_t boxed_size; + int32_t size; + int32_t boxed_size; } blueprint; struct object { diff -r 47ab97730865 -r 1bfc19076f1b runtime/rhopefuncs_epilog.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/runtime/rhopefuncs_epilog.c Thu Mar 10 04:16:38 2011 +0000 @@ -0,0 +1,39 @@ + +DO_END: + for(idx = 0; idx < cdata->num_params; ++idx) + params[idx] = cdata->params[idx]; + free_context(ct); + return cdata->num_params; + +DO_END_THREAD: + for(idx = 0; idx < cdata->num_params; ++idx) + { release_ref(cdata->params[idx]); } + if(ct->runafter) + { + temp_ct = ct; + ct = ct->runafter; + free_context(temp_ct); + cdata = ct->resume_cdata; + func = cdata->func; + DISPATCH + } + free_context(ct); + if(ct = get_cqueue()) + { + cdata = ct->resume_cdata; + func = cdata->func; + DISPATCH + } +NOTHING_TO_DO: + return 0; + +_exception: + puts("Exception! Trace follows:"); + while(cdata && cdata->func < END) + { + printf("%d\n", cdata->func); + cdata = cdata->lastframe; + } + return -1; +} + diff -r 47ab97730865 -r 1bfc19076f1b runtime/rhopefuncs_prolog.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/runtime/rhopefuncs_prolog.c Thu Mar 10 04:16:38 2011 +0000 @@ -0,0 +1,23 @@ +#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 proftime; +#endif + uint16_t resume,idx, vcparam_offset, last_vcparam; + context *ct,*temp_ct; + void *tmp; + calldata * cdata, *temp_cdata, *my_cdata; + DispatchVar + FuncDef(Build) + FuncDef(BlueprintSP_Of) + FuncDef(ID) + FuncDef(BlueprintSP_FromSP_ID) +