Mercurial > repos > rhope
view pattern.rhope @ 121:1af91ceaaf49
Fixed memory leak when an output is only attached to a single null input
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 28 Oct 2010 21:04:12 -0400 |
parents | a7add4db4a25 |
children | d86df83402f3 |
line wrap: on
line source
Blueprint Empty Pattern { } Empty Pattern[:out] { out <- Build[Empty Pattern()] } Add String@Empty Pattern[pattern,string,idx:out] { out <- [pattern]_Add String[string,0,idx] } _Add String@Empty Pattern[pattern,string,n,idx:out] { If[[n]<[[string]Byte Length]] { out <- [[[[[[Build[Pattern()] ]Byte <<[[string]Byte[n]] ]Left <<[pattern] ]Right <<[pattern] ]Straight <<[[pattern]_Add String[string, [n]+[1],idx]] ]Terminal? <<[[n]=[[[string]Byte Length]-[1]]] ]Index <<[idx] }{ out <- pattern } } Blueprint Pattern { Byte Left Right Straight Terminal? Index } _Add String@Pattern[pattern,string,n,idx:out] { If[[n]<[[string]Byte Length]] { b <- [string]Byte[n] myb <- [pattern]Byte >> If[[b]<[myb]] { out <- [pattern]Left <<[[[pattern]Left >>]_Add String[string,n,idx]] }{ If[[b]>[myb]] { out <- [pattern]Right <<[[[pattern]Right >>]_Add String[string,n,idx]] }{ newpat <- [pattern]Straight <<[[[pattern]Straight >>]_Add String[string,[n]+[1],idx]] If[[n]=[[[string]Byte Length]-[1]]] { out <- [newpat]Terminal? <<[Yes] }{ out <- Val[newpat] } } } }{ out <- pattern } } Add String@Pattern[pattern,string,idx:out] { out <- [pattern]_Add String[string,0,idx] } Pattern@List[list:out] { out <- Fold[Add String[?], Empty Pattern[], list] } Pattern@List Leaf[list:out] { out <- Fold[Add String[?], Empty Pattern[], list] } Pattern@Pattern[p:out] { out <- p } _Match@Empty Pattern[pattern,string,n:num,no match] { no match <- Yes } Match@Empty Pattern[pattern,string:num,no match] { no match <- Yes } Match@Pattern[pattern,string:num,no match,idx] { num,no match,idx <- [pattern]_Match[string,0] } _Match@Pattern[pattern,string,n:num,no match,idx] { b <- [string]Byte[n] myb <- [pattern]Byte >> If[[b]=[myb]] { num, ,idx <- [[pattern]Straight >>]_Match[string, [n]+[1]] { } { ,no match <- If[[pattern]Terminal? >>] { num <- [n]+[1] idx <- Index >>[pattern] } } }{ If[[b]<[myb]] { num, no match, idx <- [[pattern]Left >>]_Match[string, n] }{ num, no match, idx <- [[pattern]Right >>]_Match[string, n] } } }