Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'ng' of git@github.com:rakudo/rakudo into ng
  • Loading branch information
colomon committed Feb 6, 2010
2 parents 71b6ab9 + 0cc0f71 commit ecb6e5b
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
1 change: 1 addition & 0 deletions build/Makefile.in
Expand Up @@ -104,6 +104,7 @@ BUILTINS_PIR = \
src/builtins/Pair.pir \
src/builtins/Callable.pir \
src/builtins/Positional.pir \
src/builtins/Associative.pir \
src/builtins/Seq.pir \
src/builtins/SeqIter.pir \
src/builtins/Array.pir \
Expand Down
85 changes: 85 additions & 0 deletions src/builtins/Associative.pir
@@ -0,0 +1,85 @@
## $Id$

=head1 NAME

src/classes/Associative.pir - Associative Role

=head1 DESCRIPTION

=cut

.namespace ['Associative[::T]']

.sub '' :load :init
# Create a parametric role with 1 possible candidate.
.local pmc role
.const 'Sub' $P0 = '_Associative_role_body'
role = new ['Perl6Role']
role.'!add_variant'($P0)
set_hll_global 'Associative', role
.end


# This defines the body of the role, which is run per type the role is
# parameterized with.
.sub '' :anon :subid('_Associative_role_body')
.param pmc type :optional

# Need to capture the methods that belong in this role.
.const 'Sub' $P1 = 'Associative::of'
capture_lex $P1

# Capture type.
if null type goto no_type
type = type.'WHAT'()
goto type_done
no_type:
type = get_hll_global 'Mu'
type_done:
.lex 'T', type

# Create role.
.tailcall '!create_parametric_role'("Associative[::T]")
.end
.sub '' :load :init
.local pmc block, signature
.const 'Sub' $P0 = '_Associative_role_body'
block = $P0
signature = allocate_signature 1
setprop block, "$!signature", signature
null $P1
set_signature_elem signature, 0, "T", SIG_ELEM_IS_OPTIONAL, $P1, $P1, $P1, $P1, $P1, $P1
.end


=head2 Methods

=over

=item of

Returns the type constraining what may be stored.

=cut

.sub 'of' :method :outer('_Associative_role_body') :subid('Associative::of')
$P0 = find_lex 'T'
.return ($P0)
.end
.sub '' :load :init
.local pmc block, signature
.const 'Sub' block = 'Associative::of'
signature = allocate_signature 0
setprop block, "$!signature", signature
.end

=back

=cut

# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir:

0 comments on commit ecb6e5b

Please sign in to comment.