Browse files

Start sketching out more efficient approach to handling $_, $/, $! an…

…d %_.
  • Loading branch information...
1 parent cca4603 commit a49f251138f35a801a9d02de365a6812bf232407 @jnthn jnthn committed May 19, 2011
Showing with 30 additions and 10 deletions.
  1. +14 −10 src/Perl6/Actions.pm
  2. +16 −0 src/pmc/perl6lexpad.pmc
View
24 src/Perl6/Actions.pm
@@ -3006,16 +3006,20 @@ class Perl6::Actions is HLL::Actions {
}
sub add_implicit_var($block, $name, $outer) {
- my $base := $outer
- ?? PAST::Op.new( :inline(" %r = new ['Perl6Scalar'], %0"),
- PAST::Op.new(:pirop('find_lex_skip_current Ps'), $name)
- )
- !! PAST::Op.new( :inline(" %r = new ['Perl6Scalar']") );
- $base := PAST::Op.new( $base, 'rw', $TRUE, :pirop('setprop') );
- $block[0].push(
- PAST::Var.new( :name($name), :scope('lexical'), :isdecl(1),
- :viviself($base) )
- );
+ # If we have an outer block, set $_ explicitly to what it is in the outer
+ # block. For routines they are auto-viv. (TODO: make routine case more
+ # optimal too.)
+ if $outer {
+ my $base := PAST::Op.new( :inline(" %r = new ['Perl6Scalar'], %0"),
+ PAST::Op.new(:pirop('find_lex_skip_current Ps'), $name)
+ );
+ $base := PAST::Op.new( $base, 'rw', $TRUE, :pirop('setprop') ); # XXX
+ $block[0].push(PAST::Op.new(
+ :pasttype('bind'),
+ PAST::Var.new( :name($name), :scope('lexical') ),
+ $base
+ ));
+ }
$block.symbol($name, :scope('lexical') );
}
View
16 src/pmc/perl6lexpad.pmc
@@ -7,8 +7,24 @@ pmclass Perl6LexPad
hll perl6
maps LexPad
{
+ /* The static lexical info. */
ATTR PMC *lexinfo;
+
+ /* The current context, including the registers. */
ATTR PMC *ctx;
+
+ /* We keep a vivified-on-demand store for $_, $! and $/. Every block has them
+ * but they often go unused, so saves a bunch of memory allocations to just
+ * create them on demand if used. */
+ ATTR PMC *topic;
+ ATTR PMC *error;
+ ATTR PMC *match;
+
+ /* For %_ we rarely need it, but methods always want to collect it by default.
+ * We can't really statically eliminate it, but we can make sure we only create
+ * it on demand. This contains a Parrot hash by default, or NULL if there's no
+ * named args. It will become a Perl 6 hash "magically" if asked for. */
+ ATTR PMC *default_named_slurpy;
VTABLE void init() {
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,

0 comments on commit a49f251

Please sign in to comment.