Skip to content

Commit

Permalink
Fix eval method to see the correct context.
Browse files Browse the repository at this point in the history
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 011ec66
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/core/Cool.pm
Expand Up @@ -183,7 +183,7 @@ my class Cool {
method trim-trailing() { self.Stringy.trim-trailing }; method trim-trailing() { self.Stringy.trim-trailing };


method eval(*%opts) { method eval(*%opts) {
eval(self.Stringy, |%opts); eval(self.Stringy, context => CALLER::, |%opts);
} }


multi method Real() { self.Numeric.Real } multi method Real() { self.Numeric.Real }
Expand Down
12 changes: 5 additions & 7 deletions src/core/control.pm
@@ -1,5 +1,6 @@
my class Nil { ... } my class Nil { ... }
my class X::Eval::NoSuchLang { ... } my class X::Eval::NoSuchLang { ... }
my class PseudoStash { ... }


my &THROW := my &THROW :=
-> | { -> | {
Expand Down Expand Up @@ -143,17 +144,14 @@ multi sub warn(*@msg) is hidden_from_backtrace {
} }


proto sub eval(|) {*} proto sub eval(|) {*}
multi sub eval(Str $code, :$lang = 'perl6') { multi sub eval(Str $code, :$lang = 'perl6', PseudoStash :$context) {
my $caller_ctx := Q:PIR { my $eval_ctx := nqp::getattr(nqp::p6decont($context // CALLER::), PseudoStash, '$!ctx');
$P0 = getinterp
%r = $P0['context';1]
};
my $?FILES := 'eval_' ~ (state $no)++; my $?FILES := 'eval_' ~ (state $no)++;
my $compiler := pir::compreg__PS($lang); my $compiler := pir::compreg__PS($lang);
X::Eval::NoSuchLang.new(:$lang).throw X::Eval::NoSuchLang.new(:$lang).throw
if nqp::isnull($compiler); if nqp::isnull($compiler);
my $pbc := $compiler.compile($code, :outer_ctx($caller_ctx), :global(GLOBAL)); my $pbc := $compiler.compile($code, :outer_ctx($eval_ctx), :global(GLOBAL));
nqp::atpos($pbc, 0).set_outer_ctx($caller_ctx); nqp::atpos($pbc, 0).set_outer_ctx($eval_ctx);
$pbc(); $pbc();
} }


Expand Down

0 comments on commit 011ec66

Please sign in to comment.