Skip to content

Commit

Permalink
Unpacking of hashes works, and objects nearly works, once I fix attri…
Browse files Browse the repository at this point in the history
…bute introspection.
  • Loading branch information
jnthn committed Feb 13, 2010
1 parent 04a857f commit df72c91
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/builtins/Capture.pir
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ them.
.end


=item postcircumfix:<{ }>

=cut

.sub 'postcircumfix:<{ }>' :method :vtable('get_pmc_keyed_str')
.param pmc key
$P0 = getattribute self, '$!named'
$P0 = $P0[key]
.return ($P0)
.end


=item elems

The number of positional elements in the Capture.
Expand Down
9 changes: 9 additions & 0 deletions src/core/EnumMap.pm
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,13 @@ role EnumMap does Associative {
method Int() {
pir::box__PI(pir::set__IP($!storage))
}

method Capture() {
Q:PIR {
$P0 = get_hll_global 'Capture'
$P1 = find_lex 'self'
$P1 = getattribute $P1, '$!storage'
%r = $P0.'new'($P1 :flat :named)
}
}
}
14 changes: 14 additions & 0 deletions src/core/Mu.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,18 @@ augment class Mu {
method Bool { $.defined }

multi method notdef() { !self.defined; }

method Capture() {
my %attrs;
my @mro = self, self.^parents;
for @mro -> $class {
for $class.^attributes() -> $attr {
if $attr.accessor {
my $name = substr($attr.name, 2);
%attrs{$name} //= self."$name"();
}
}
}
%attrs.Capture()
}
}

0 comments on commit df72c91

Please sign in to comment.