# HG changeset patch # User Mike Pavone # Date 1280603295 14400 # Node ID c25d75c2440b1343756d315e0cf7417c7feb6244 # Parent 5a195ee08eac7848140dd2e4e38f02684b3406f1 Implemented Next@Dictionary and Print@Dictionary diff -r 5a195ee08eac -r c25d75c2440b backendutils.rhope --- a/backendutils.rhope Sat Jul 31 00:19:15 2010 -0400 +++ b/backendutils.rhope Sat Jul 31 15:08:15 2010 -0400 @@ -1,7 +1,7 @@ Escape Rhope Name NU[name:escaped] { - escaped <- [[[[[[[[[[[[[[[[[[[[name]Replace["_","UN_"] + escaped <- [[[[[[[[[[[[[[[[[[[[[[[name]Replace["_","UN_"] ]Replace["@","AT_"] ]Replace[" ","SP_"] ]Replace[":","CN_"] @@ -13,14 +13,17 @@ ]Replace["<","LT_"] ]Replace[">","GT_"] ]Replace["(","LP_"] - ]Replace[")","RP_"] - ]Replace["!","NT_"] - ]Replace["=","EQ_"] - ]Replace["'","PR_"] - ]Replace["\"","DP_"] - ]Replace["\t","TB_"] - ]Replace[",", "CM_"] + ]Replace[")","RP_"] + ]Replace["!","NT_"] + ]Replace["=","EQ_"] + ]Replace["'","PR_"] + ]Replace["\"","DP_"] + ]Replace["\t","TB_"] + ]Replace[",", "CM_"] ]Replace[".", "PD_"] + ]Replace["\n", "NL_"] + ]Replace["{", "LC_"] + ]Replace["}", "RC_"] } Escape Rhope Name[name:escaped] @@ -42,66 +45,66 @@ { //TODO: Make me work with other backends out <- [["add_ref((object *)"]Append[ [[addref]Value >>]Make Op[func] ]]Append[")"] -} - -Strip Addref@AddRef[op:out] -{ - out <- [[op]Value >>]Strip Addref +} + +Strip Addref@AddRef[op:out] +{ + out <- [[op]Value >>]Strip Addref } Make Op@String[string,func:out] { out <- [func]Resolve[string] -} - -Strip Addref@String[op:out] -{ - out <- op +} + +Strip Addref@String[op:out] +{ + out <- op } Make Op@Whole Number[num,func:out] { out <- num -} - -Strip Addref@Whole Number[op:out] -{ - out <- op +} + +Strip Addref@Whole Number[op:out] +{ + out <- op } Make Op@Real Number[num,func:out] { out <- num -} - -Strip Addref@Real Number[op:out] -{ - out <- op -} - -Blueprint Output -{ - Name -} - -Output[name:out] -{ - out <- [Build["Output"]]Name <<[name] -} - -Make Op@Output[op,func:out] -{ - out <- [func]Resolve Output[[op]Name >>] -} - -Strip Addref@Output[op:out] -{ - out <- op +} + +Strip Addref@Real Number[op:out] +{ + out <- op +} + +Blueprint Output +{ + Name +} + +Output[name:out] +{ + out <- [Build["Output"]]Name <<[name] +} + +Make Op@Output[op,func:out] +{ + out <- [func]Resolve Output[[op]Name >>] +} + +Strip Addref@Output[op:out] +{ + out <- op } Blueprint Constant { - Value + Value Need Addref } @@ -113,11 +116,11 @@ Make Op@Constant[const,func:out] { out <- [func]Lookup Constant[[const]Value >>, [const]Need Addref >>] -} - -Strip Addref@Constant[op:out] -{ - out <- [op]Need Addref <<[No] +} + +Strip Addref@Constant[op:out] +{ + out <- [op]Need Addref <<[No] } Blueprint Result @@ -133,13 +136,13 @@ Make Op@Result[result,func:out] { out <- [func]Result Reference[[result]Output Num>>] -} - -Strip Addref@Result[op:out] -{ - out <- op -} - +} + +Strip Addref@Result[op:out] +{ + out <- op +} + Blueprint Check Result { Output Num @@ -153,21 +156,21 @@ Make Op@Check Result[result,func:out] { out <- [func]Checked Result Reference[[result]Output Num>>] -} - -Strip Addref@Check Result[op:out] -{ - out <- op -} - -Make Condition[op:out] -{ - If[[Type Of[op]]=["OrValue"]] - { - out <- OrCond[Make Condition[[op]Left >>], Make Condition[[op]Right >>]] - }{ - out <- op - } +} + +Strip Addref@Check Result[op:out] +{ + out <- op +} + +Make Condition[op:out] +{ + If[[Type Of[op]]=["OrValue"]] + { + out <- OrCond[Make Condition[[op]Left >>], Make Condition[[op]Right >>]] + }{ + out <- op + } } Blueprint OrValue @@ -184,11 +187,11 @@ Make Op@OrValue[orval,func:out] { out <- [func]If Null Else[[orval]Left >>, [orval]Right >>] -} - -Strip Addref@OrValue[op:out] -{ - out <- [[op]Left <<[ [[op]Left >>]Strip Addref ]]Right <<[ [[op]Right >>]Strip Addref ] +} + +Strip Addref@OrValue[op:out] +{ + out <- [[op]Left <<[ [[op]Left >>]Strip Addref ]]Right <<[ [[op]Right >>]Strip Addref ] } Blueprint NotCond @@ -204,11 +207,11 @@ Make Op@NotCond[cond,func:out] { out <- ["!"]Append[[[cond]Condition >>]Make Op[func]] -} - -Strip Addref@NotCond[op:out] -{ - out <- op +} + +Strip Addref@NotCond[op:out] +{ + out <- op } Blueprint OrCond @@ -225,11 +228,11 @@ Make Op@OrCond[cond,func:out] { out <- ["("]Append[[[ [[cond]Condition1 >>]Make Op[func] ]Append[" || "]]Append[[ [[cond]Condition2 >>]Make Op[func] ]Append[")"]]] -} - -Strip Addref@OrCond[op:out] -{ - out <- op +} + +Strip Addref@OrCond[op:out] +{ + out <- op } Blueprint AndCond @@ -246,11 +249,11 @@ Make Op@AndCond[cond,func:out] { out <- ["("]Append[[[ [[cond]Condition1 >>]Make Op[func] ]Append[" && "]]Append[[ [[cond]Condition2 >>]Make Op[func] ]Append[")"]]] -} - -Strip Addref@AndCond[op:out] -{ - out <- op +} + +Strip Addref@AndCond[op:out] +{ + out <- op } Blueprint Field Ref @@ -267,18 +270,18 @@ Make Op@Field Ref[ref,func:out] { out <- [func]Field Result[[ref]Variable >>,[ref]Field >>] -} - -Strip Addref@Field Ref[op:out] -{ - out <- op +} + +Strip Addref@Field Ref[op:out] +{ + out <- op } Blueprint Type Instance { Name Params - Variant + Variant Mutable? } @@ -313,20 +316,21 @@ ,out <- If[[[type]Name >>] = [[compare]Name >>]] { out <- [[type]Variant >>] = [[compare]Variant >>] } } -} - -Blueprint Worker Literal -{ - Name - Args -} - Worker Literal[name:out] -{ - out <- [[Build["Worker Literal"]]Name <<[name]]Args <<[()] -} - -Set Input@Worker Literal[worker,argnum,val:out] -{ - out <- [worker]Args <<[ [[worker]Args >>]Set[argnum, val] ] -} - +} + +Blueprint Worker Literal +{ + Name + Args +} + +Worker Literal[name:out] +{ + out <- [[Build["Worker Literal"]]Name <<[name]]Args <<[()] +} + +Set Input@Worker Literal[worker,argnum,val:out] +{ + out <- [worker]Args <<[ [[worker]Args >>]Set[argnum, val] ] +} + diff -r 5a195ee08eac -r c25d75c2440b dict.rhope --- a/dict.rhope Sat Jul 31 00:19:15 2010 -0400 +++ b/dict.rhope Sat Jul 31 15:08:15 2010 -0400 @@ -32,14 +32,14 @@ ]Left <<[Dictionary[]] ]Right <<[Dictionary[]] ]Straight <<[val] - ]Bits <<[4294967295u32] //Maximum 32-bit unsigned int value + ]Bits <<[0u32] } _Set New[index,val,bits,bitindex:out] { nbitindex <- [bitindex]+[1] [index]Dict Bits[nbitindex] - { straight <- _Set New[index,val,~,nbitindex] } + { straight <- _Set New[index,val,[~]+[1u32],nbitindex] } { straight <- _Terminal Node[val] } out <- [[[[Build[Dictionary()]]Left <<[Dictionary[]]]Right <<[Dictionary[]]]Straight <<[straight]]Bits <<[bits] } @@ -51,7 +51,7 @@ Set@Empty Dictionary[dict,index,val:out] { - out <- _Set New[index,val, Dict Type ID[index], -1] + out <- _Set New[index,val, [Dict Type ID[index]]+[1u32], -1] } First@Empty Dictionary[dict:first,not found] @@ -67,20 +67,21 @@ Index@Dictionary[dict,index:out,not found] { - out,not found <- [dict]_Index[index,Dict Type ID[index], -1] + out,not found <- [dict]_Index[index,[Dict Type ID[index]]+[1u32], -1] } _Index@Dictionary[dict,index,bits,bitindex:out,not found] { If[[bits]=[[dict]Bits >>]] { - If[[bits]=[4294967295u32]] + If[[bits]=[0u32]] { out <- Straight >>[dict] }{ nbitindex <- [bitindex]+[1] - nbits <- [index]Dict Bits[nbitindex] {} - { nbits <- 4294967295u32 } + [index]Dict Bits[nbitindex] + { nbits <- [~]+[1u32] } + { nbits <- 0u32 } out,not found <- [[dict]Straight >>]_Index[index,nbits,nbitindex] } }{ @@ -96,20 +97,21 @@ Set@Dictionary[dict,index,val:out] { - out <- [dict]_Set[index,val,Dict Type ID[index], -1] + out <- [dict]_Set[index,val,[Dict Type ID[index]]+[1u32], -1] } _Set@Dictionary[dict,index,val,bits,bitindex:out] { If[[bits]=[[dict]Bits >>]] { - If[[bits]=[4294967295u32]] + If[[bits]=[0u32]] { out <- [dict]Straight <<[val] }{ nbitindex <- [bitindex]+[1] - nbits <- [index]Dict Bits[nbitindex] {} - { nbits <- 4294967295u32 } + [index]Dict Bits[nbitindex] + { nbits <- [~]+[1u32] } + { nbits <- 0u32 } out <- [dict]Straight <<[[[dict]Straight >>]_Set[index,val,nbits,nbitindex]] } }{ @@ -134,8 +136,8 @@ { typeid,node <- [[dict]Left >>]_First Type ID {} {} { - typeid <- [dict]Bits >> - node <- dict + typeid <- [[dict]Bits >>]-[1u32] + node <- Straight >>[dict] } } @@ -148,11 +150,11 @@ { keyout <- [[dict]Left >>]_First[keylist] {} { - If[[[dict]Bits >>] = [4294967295u32]] + If[[[dict]Bits >>] = [0u32]] { keyout <- keylist }{ - keyout <- [[dict]Straight >>]_First[[keylist]Append[[dict]Bits >>]] + keyout <- [[dict]Straight >>]_First[[keylist]Append[[[dict]Bits >>]-[1u32]]] } } } @@ -160,11 +162,102 @@ First@Dictionary[dict:out,none] { typeid, node <- [dict]_First Type ID - l <- List[] - rawkey <- [[node]Left >>]_First[l] {} - { - rawkey <- [[node]Straight >>]_First[l] - } + rawkey <- [node]_First[List[]] + out <- [Build[Blueprint From ID[typeid]]]From Dict Key[rawkey] +} + +Next@Dictionary[dict,cur:out,none] +{ + [cur]Dict Type ID + { rawkey,typeid,none <- [dict]_Next Type ID[[~]+[1u32], cur] } + out <- [Build[Blueprint From ID[typeid]]]From Dict Key[rawkey] } +_Next@Empty Dictionary[dict:out,none] +{ + none <- dict +} + +_Next Type ID@Empty Dictionary[dict:out,typeid,none] +{ + none <- dict +} + +_Next Type ID@Dictionary[dict,curtypeid,key:out,typeid,none] +{ + If[[[dict]Bits >>]=[curtypeid]] + { + out <- [[dict]Straight >>]_Next[key,0,List[]] + { typeid <- [curtypeid]-[1u32] } + { + typeid,,none <- [[dict]Right >>]_First Type ID {} + { + l <- List[] + out <- [~]_First[l] {} + } + } + }{ + If[[curtypeid]<[[dict]Bits >>]] + { + out,typeid <- [[dict]Left >>]_Next Type ID[curtypeid,key] {} {} + { + typeid <- [curtypeid]-[1u32] + out <- [[dict]Straight >>]_First[List[]] + } + }{ + out,typeid,none <- [[dict]Right >>]_Next Type ID[curtypeid,key] + } + } +} + +_Next@Dictionary[dict,key,keyidx,newkey:out,none] +{ + [key]Dict Bits[keyidx] + { bits <- [~]+[1u32] } + { bits <- 0u32 } + + If[[[dict]Bits >>]=[bits]] + { + ,goright <- If[bits] + { + out,goright <- [[dict]Straight >>]_Next[key,[keyidx]+[1], [newkey]Append[[bits]-[1u32]]] + } + Val[goright] + { + out,none <- [[dict]Right >>]_First[newkey] + } + }{ + If[[bits]<[[dict]Bits >>]] + { + out <- [[dict]Left >>]_Next[key, keyidx, newkey] {} + { out <- [[dict]Straight >>]_First[[newkey]Append[[[dict]Bits >>]-[1u32]]] } + }{ + out,none <- [[dict]Right >>]_Next[key, keyidx, newkey] + } + } +} + +_Print Dict[dict,key] +{ + val <- String[[dict]Index[key]] + Print[ [[["\t"]Append[String[key]]]Append[": "]]Append[val] ] + { + [dict]Next[key] + { + _Print Dict[dict, ~] + } + } +} + +Print@Dictionary[dict:out] +{ + Print["Dictionary"] + { _Print Dict[dict, [dict]First] } +} + +Print@Empty Dictionary[dict:out] +{ + Print["Dictionary\n\t{Empty}"] +} + diff -r 5a195ee08eac -r c25d75c2440b string.rhope --- a/string.rhope Sat Jul 31 00:19:15 2010 -0400 +++ b/string.rhope Sat Jul 31 15:08:15 2010 -0400 @@ -569,3 +569,18 @@ out <- String[Fold[_From Dict String[?], Array[], data]] } +String@String[string:out] +{ + out <- string +} + +String@String Cat[string:out] +{ + out <- string +} + +String@String Slice[string:out] +{ + out <- string +} + diff -r 5a195ee08eac -r c25d75c2440b testdictfirstnext.rhope --- a/testdictfirstnext.rhope Sat Jul 31 00:19:15 2010 -0400 +++ b/testdictfirstnext.rhope Sat Jul 31 15:08:15 2010 -0400 @@ -8,6 +8,6 @@ ]Set["food", "fight"] ]Set["fool", "wise"] - Print[First[dict]] + Print[dict] }