# HG changeset patch # User Mike Pavone # Date 1280468939 14400 # Node ID 3c4325e6298f6fa3b6b6aaf88da79c6598f17c7b # Parent 27bb051d631c469845de74894ed7e135d6757ae7 Add First@Dictionary (need to find mem man bug) diff -r 27bb051d631c -r 3c4325e6298f cbackend.rhope --- a/cbackend.rhope Tue Jul 27 23:33:31 2010 -0400 +++ b/cbackend.rhope Fri Jul 30 01:48:59 2010 -0400 @@ -1343,12 +1343,12 @@ { out <- [[[[["typedef enum {\n" ]Append[Fold["_Dispatch Enum", - [Fold["_Dispatch Enum Methods", "", all methods]]Append["\tFUNC_Build,\n\tFUNC_BlueprintSP_Of,\n\tFUNC_ID,\n"], + [Fold["_Dispatch Enum Methods", "", all methods]]Append["\tFUNC_Build,\n\tFUNC_BlueprintSP_Of,\n\tFUNC_ID,\n\tFUNC_BlueprintSP_FromSP_ID,\n"], [program]Functions >>]] ]Append["\tEND\n} funcids;\n\n"] ]Append["#define DISPATCH switch(func) { \\\n"] ]Append[Fold["_Dispatch Switch", - [Fold["_Dispatch Switch Methods", "", all methods]]Append["\tcase FUNC_Build: goto f_Build;\\\n\tcase FUNC_BlueprintSP_Of: goto f_BlueprintSP_Of;\\\n\tcase FUNC_ID: goto f_ID;\\\n"], + [Fold["_Dispatch Switch Methods", "", all methods]]Append["\tcase FUNC_Build: goto f_Build;\\\n\tcase FUNC_BlueprintSP_Of: goto f_BlueprintSP_Of;\\\n\tcase FUNC_ID: goto f_ID;\\\n\tcase FUNC_BlueprintSP_FromSP_ID: goto f_BlueprintSP_FromSP_ID;\\\n"], [program]Functions >>]] ]Append["\tcase END: goto DO_END;\\\n}\n\n"] } @@ -1442,7 +1442,7 @@ { uint16_t resume,idx, vcparam_offset, last_vcparam; context * ct; - calldata * cdata, *temp_cdata, *my_cdata;\n\nFuncDef(Build)\nFuncDef(BlueprintSP_Of)\nFuncDef(ID)\n"] + calldata * cdata, *temp_cdata, *my_cdata;\n\nFuncDef(Build)\nFuncDef(BlueprintSP_Of)\nFuncDef(ID)\nFuncDef(BlueprintSP_FromSP_ID)\n"] ]Append[Fold["Local Pointers", "", [program]Functions >>]] ]Append[" ct = new_context(); @@ -1486,6 +1486,24 @@ 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\n"] ]Append[Fold[["_Text C Program"]Set Input[2, [program]Type Registry >>], "", Filter[[program]Functions >>, "Native"]]] ]Append[" diff -r 27bb051d631c -r 3c4325e6298f dict.rhope --- a/dict.rhope Tue Jul 27 23:33:31 2010 -0400 +++ b/dict.rhope Fri Jul 30 01:48:59 2010 -0400 @@ -86,10 +86,9 @@ }{ If[[bits]<[[dict]Bits >>]] { + go <- Left >>[dict] + }{ go <- Right >>[dict] - - }{ - go <- Left >>[dict] } out,not found <- [go]_Index[index,bits,bitindex] } @@ -116,14 +115,56 @@ }{ If[[bits]<[[dict]Bits >>]] { + go <- Left >>[dict] + out <- [dict]Left <<[new] + }{ go <- Right >>[dict] out <- [dict]Right <<[new] - - }{ - go <- Left >>[dict] - out <- [dict]Left <<[new] } new <- [go]_Set[index,val,bits,bitindex] } } +_First Type ID@Empty Dictionary[dict:typeid,node,none] +{ + none <- dict +} + +_First Type ID@Dictionary[dict:typeid,node] +{ + typeid,node <- [[dict]Left >>]_First Type ID {} {} + { + typeid <- [dict]Bits >> + node <- dict + } +} + +_First@Empty Dictionary[dict,keylist:keyout,none] +{ + none <- dict +} + +_First@Dictionary[dict,keylist:keyout] +{ + keyout <- [[dict]Left >>]_First[keylist] {} + { + If[[[dict]Bits >>] = [4294967295u32]] + { + keyout <- keylist + }{ + keyout <- [[dict]Straight >>]_First[[keylist]Append[[dict]Bits >>]] + } + } +} + +First@Dictionary[dict:out,none] +{ + typeid, node <- [dict]_First Type ID + l <- List[] + rawkey <- [[node]Left >>]_First[l] {} + { + rawkey <- [[node]Straight >>]_First[l] + } + out <- [Build[Blueprint From ID[typeid]]]From Dict Key[rawkey] +} + diff -r 27bb051d631c -r 3c4325e6298f nworker.rhope --- a/nworker.rhope Tue Jul 27 23:33:31 2010 -0400 +++ b/nworker.rhope Fri Jul 30 01:48:59 2010 -0400 @@ -1451,15 +1451,16 @@ Register Builtins@NProgram[prog:out] { - registered <- [[[[[[[prog]Register Worker["Print", "rhope", 1, 1] + registered <- [[[[[[[[prog]Register Worker["Print", "rhope", 1, 1] ]Register Worker["If@Boolean", "rhope", 1, 2] ]Register Worker["Build", "rhope", 1, 1] ]Register Worker["Blueprint Of", "rhope", 1, 1] ]Register Worker["Call@Worker", "rhope", 1, 2] //We're using 2 because we need to assume that the outputs are conditional ]Register Worker["ID", "rhope", 1, 1] + ]Register Worker["Blueprint From ID", "rhope", 1, 2] ]Register Number Methods - out <- [[[[[[registered]Bind Worker["If@Boolean", + out <- [[[[[[[registered]Bind Worker["If@Boolean", [[[[[NWorker["rhope"] ]Inputs <<[("condition")] ]Input Types <<[ [()]Append[Type Instance["Boolean"]] ] @@ -1501,6 +1502,13 @@ ]Outputs <<[("id")] ]Output Types <<[ [()]Append[Type Instance["UInt32"]]] ]Builtin? << [Yes]] + ]Bind Worker["Blueprint From ID", + [[[[[NWorker["rhope"] + ]Inputs <<[("id")] + ]Input Types <<[ [()]Append[Type Instance["UInt32"]]] + ]Outputs <<[("bp","none")] + ]Output Types <<[ [[()]Append[Type Instance["Blueprint"]]]Append[Type Instance["Any Type"]]] + ]Builtin? << [Yes]] } Find Worker@NProgram[prog, name:out,notfound] diff -r 27bb051d631c -r 3c4325e6298f runtime/blueprint.h --- a/runtime/blueprint.h Tue Jul 27 23:33:31 2010 -0400 +++ b/runtime/blueprint.h Fri Jul 30 01:48:59 2010 -0400 @@ -22,4 +22,8 @@ object * id; } lt_ID; +typedef struct { + uint32_t type; +} lt_BlueprintSP_FromSP_ID; + #endif //BLUEPRINT_H_ diff -r 27bb051d631c -r 3c4325e6298f runtime/object.h --- a/runtime/object.h Tue Jul 27 23:33:31 2010 -0400 +++ b/runtime/object.h Fri Jul 30 01:48:59 2010 -0400 @@ -83,6 +83,9 @@ returntype coerce_value(uint32_t type, calldata * params); blueprint * get_blueprint_byid(uint32_t type); +extern blueprint ** registered_types; +extern uint32_t max_registered_type; + #define INITIAL_TYPE_STORAGE 32 #define INITIAL_METHOD_LOOKUP 8 #define BELOW_INITIAL_METHOD 3 diff -r 27bb051d631c -r 3c4325e6298f string.rhope --- a/string.rhope Tue Jul 27 23:33:31 2010 -0400 +++ b/string.rhope Fri Jul 30 01:48:59 2010 -0400 @@ -559,3 +559,13 @@ { out <- UInt32[~] } } +_From Dict String[arr,el:out] +{ + out <- [arr]Append[Trunc UInt8[el]] +} + +From Dict Key@String[string,data:out] +{ + out <- String[Fold[_From Dict String[?], Array[], data]] +} + diff -r 27bb051d631c -r 3c4325e6298f testdictfirstnext.rhope --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testdictfirstnext.rhope Fri Jul 30 01:48:59 2010 -0400 @@ -0,0 +1,13 @@ + + +Main[] +{ + dict <- [[[[Dictionary[] + ]Set["foo", "bar"] + ]Set["bovine","moo"] + ]Set["food", "fight"] + ]Set["fool", "wise"] + + Print[First[dict]] +} +