Permalink
Browse files

Fix eval method to see the correct context.

Plus a bonus feature that you didn't see me add, but the debugger will
happily use. :-)
  • Loading branch information...
jnthn committed Oct 18, 2012
1 parent 27a6b84 commit 011ec66f8b0fed78d0576625cfda1a62aaf5141d
Showing with 6 additions and 8 deletions.
  1. +1 −1 src/core/Cool.pm
  2. +5 −7 src/core/control.pm
View
@@ -183,7 +183,7 @@ my class Cool {
method trim-trailing() { self.Stringy.trim-trailing };
method eval(*%opts) {
eval(self.Stringy, |%opts);
eval(self.Stringy, context => CALLER::, |%opts);
}
multi method Real() { self.Numeric.Real }
View
@@ -1,5 +1,6 @@
my class Nil { ... }
my class X::Eval::NoSuchLang { ... }
my class PseudoStash { ... }
my &THROW :=
-> | {
@@ -143,17 +144,14 @@ multi sub warn(*@msg) is hidden_from_backtrace {
}
proto sub eval(|) {*}
multi sub eval(Str $code, :$lang = 'perl6') {
my $caller_ctx := Q:PIR {
$P0 = getinterp
%r = $P0['context';1]
};
multi sub eval(Str $code, :$lang = 'perl6', PseudoStash :$context) {
my $eval_ctx := nqp::getattr(nqp::p6decont($context // CALLER::), PseudoStash, '$!ctx');
my $?FILES := 'eval_' ~ (state $no)++;
my $compiler := pir::compreg__PS($lang);
X::Eval::NoSuchLang.new(:$lang).throw
if nqp::isnull($compiler);
my $pbc := $compiler.compile($code, :outer_ctx($caller_ctx), :global(GLOBAL));
nqp::atpos($pbc, 0).set_outer_ctx($caller_ctx);
my $pbc := $compiler.compile($code, :outer_ctx($eval_ctx), :global(GLOBAL));
nqp::atpos($pbc, 0).set_outer_ctx($eval_ctx);
$pbc();
}

0 comments on commit 011ec66

Please sign in to comment.