Skip to content

Commit

Permalink
Remove Junction's deendence on Array and List, then move it to an ear…
Browse files Browse the repository at this point in the history
…lier spot in the built-ins list.
  • Loading branch information
jnthn committed Apr 3, 2009
1 parent f6886e3 commit b015a2a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build/Makefile.in
Expand Up @@ -50,6 +50,7 @@ BUILTINS_PIR = \
src/classes/ClassHOW.pir \
src/classes/Object.pir \
src/classes/Any.pir \
src/classes/Junction.pir \
src/classes/Signature.pir \
src/classes/Role.pir \
src/classes/Abstraction.pir \
Expand Down Expand Up @@ -77,7 +78,6 @@ BUILTINS_PIR = \
src/classes/Method.pir \
src/classes/Submethod.pir \
src/classes/Multi.pir \
src/classes/Junction.pir \
src/classes/Failure.pir \
src/classes/Exception.pir \
src/classes/Nil.pir \
Expand Down
37 changes: 33 additions & 4 deletions src/classes/Junction.pir
Expand Up @@ -16,7 +16,7 @@ src/classes/Junction.pir - Perl 6 Junction and related functions
.sub 'onload' :anon :load :init
.local pmc p6meta
p6meta = get_hll_global ['Perl6Object'], '$!P6META'
p6meta.'new_class'('Junction', 'parent'=>'Perl6Object', 'attr'=>'@!eigenstates $!type')
p6meta.'new_class'('Junction', 'parent'=>'Perl6Object', 'attr'=>'$!eigenstates $!type')
.end

=head2 Methods
Expand Down Expand Up @@ -181,7 +181,7 @@ Return the components of the Junction.
.end

.sub 'eigenstates' :method
$P0 = getattribute self, '@!eigenstates'
$P0 = getattribute self, '$!eigenstates'
.return ($P0)
.end

Expand Down Expand Up @@ -216,12 +216,41 @@ Return the components of the Junction.
# Make eigenstates unique if possible
if type == JUNCTION_TYPE_ONE goto set_eigenstates
$P0 = get_hll_global 'infix:==='
eigenstates = eigenstates.'uniq'($P0)
eigenstates = '!junction_unique_helper'(eigenstates, $P0)
set_eigenstates:
setattribute junc, '@!eigenstates', eigenstates
setattribute junc, '$!eigenstates', eigenstates
.return (junc)
.end


.sub '!junction_unique_helper'
.param pmc self
.param pmc comparer

.local pmc ulist
ulist = new 'ResizablePMCArray'

.local pmc it_inner, it_outer, val
it_outer = iter self
outer_loop:
unless it_outer goto outer_done
val = shift it_outer
it_inner = iter ulist
inner_loop:
unless it_inner goto inner_done
$P0 = shift it_inner
$P1 = comparer(val, $P0)
if $P1 goto outer_loop
goto inner_loop
inner_done:
ulist.'push'(val)
goto outer_loop

outer_done:
.return (ulist)
.end


=over

=item !DISPATCH_JUNCTION
Expand Down

0 comments on commit b015a2a

Please sign in to comment.