Skip to content

Commit

Permalink
introduce EVAL
Browse files Browse the repository at this point in the history
this mostly duplicates the code, because calling something that introspects
its caller is a bit icky
  • Loading branch information
moritz committed Dec 30, 2013
1 parent 1747273 commit 9487aba
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/deprecations
@@ -1,3 +1,7 @@
Deprecations in 2013.12

eval is now spelled EVAL

Deprecations in 2013.11

Order::Increase and Order::Decrease are now called Order::Less and
Expand Down
5 changes: 4 additions & 1 deletion src/core/Cool.pm
Expand Up @@ -215,7 +215,10 @@ my class Cool { # declared in BOOTSTRAP
method trim-trailing() { self.Stringy.trim-trailing };

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

multi method Real() { self.Numeric.Real }
Expand Down
11 changes: 11 additions & 0 deletions src/core/control.pm
Expand Up @@ -158,6 +158,17 @@ multi sub eval(Str $code, :$lang = 'perl6', PseudoStash :$context) {
nqp::forceouterctx(nqp::getattr($compiled, ForeignCode, '$!do'), $eval_ctx);
$compiled();
}
proto sub EVAL($, *%) {*}
multi sub EVAL(Str $code, :$lang = 'perl6', PseudoStash :$context) {
my $eval_ctx := nqp::getattr(nqp::decont($context // CALLER::CALLER::), PseudoStash, '$!ctx');
my $?FILES := 'eval_' ~ (state $no)++;
my $compiler := nqp::getcomp($lang);
X::Eval::NoSuchLang.new(:$lang).throw
if nqp::isnull($compiler);
my $compiled := $compiler.compile($code, :outer_ctx($eval_ctx), :global(GLOBAL));
nqp::forceouterctx(nqp::getattr($compiled, ForeignCode, '$!do'), $eval_ctx);
$compiled();
}


sub exit($status = 0) {
Expand Down

0 comments on commit 9487aba

Please sign in to comment.