Skip to content

Commit

Permalink
callframe().my returns a LexPad.
Browse files Browse the repository at this point in the history
You can index a lexpad with .{ }, or obtain its .keys.
  • Loading branch information
moritz committed Jun 12, 2010
1 parent 02d164d commit c19f148
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
1 change: 1 addition & 0 deletions build/Makefile.in
Expand Up @@ -222,6 +222,7 @@ CORE_SOURCES = \
src/core/Match.pm \
src/core/Attribute.pm \
src/core/CallFrame.pm \
src/core/LexPad.pm \
src/core/MAIN.pm \
src/core/YOU_ARE_HERE.pm \

Expand Down
29 changes: 27 additions & 2 deletions src/core/CallFrame.pm
Expand Up @@ -24,9 +24,34 @@ class CallFrame {
my $ann = self!annotations();
$ann<file>;
}
method callframe(Int $level) {
CallFrame.new(:interp($!interp), :level($!level + $level));
}

method my() {
my $i = $!interp;
my $l = $!level;
my $pad = Q:PIR {
.local pmc interp
.local int level
interp = find_lex '$i'
$P0 = find_lex '$l'
level = $P0
# no idea why we need this:
dec level

%r = interp["lexpad"; level]
};
::LexPad.new(parrot_lexpad => $pad);
}
}

our multi sub callframe($level = 0) {
our multi sub callframe(Int $level = 0) {
my $interp = pir::getinterp__p();
CallFrame.new(:$interp, level => $level + 2);
CallFrame.new(:$interp, level => ($level + 2));
}

# vim: ft=perl6
37 changes: 37 additions & 0 deletions src/core/LexPad.pm
@@ -0,0 +1,37 @@
# probably wants to inherit from Stash, which is NYI
class LexPad is Associative {
has $!parrot_lexpad;

multi method postcircumfix:<{ }>($thing) {
Q:PIR {
.local pmc key
key = find_lex '$thing'
$P0 = find_lex 'self'
$P1 = getattribute $P0, '$!parrot_lexpad'
$P1 = descalarref $P1
%r = $P1[key]
unless null %r goto done
%r = get_hll_global 'Mu'
done:
}
}

method keys {
my @keys;
Q:PIR {
.local pmc self, it, res
self = find_lex 'self'
res = find_lex '@keys'
$P0 = getattribute self, '$!parrot_lexpad'
it = iter $P0
iter_loop:
unless it goto iter_end
$P0 = shift it
push res, $P0
goto iter_loop
iter_end:
};
@keys;
}
}

0 comments on commit c19f148

Please sign in to comment.