Skip to content

Commit

Permalink
Override HLL::Compiler.eval for multi-line input
Browse files Browse the repository at this point in the history
The way this works is pretty dodgy, but it's good enough for
my experiment.  How this works is that we catch any exceptions
from evaluating the code; if there's an exception, it's an
X::Syntax::Missing, and it occurs at the end of the input string,
that means that more input is required.  Instead of just throwing
the exception at the user, we signal HLL::Compiler that we need
more input via self.needs-more-input
  • Loading branch information
hoelzro committed Feb 7, 2016
1 parent 7a22486 commit 2ecda56
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Perl6/Compiler.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,30 @@ class Perl6::Compiler is HLL::Compiler {
$line;
}

method eval($code, *@args, *%adverbs) {
my $super := nqp::findmethod(HLL::Compiler, 'eval');
my $output := '';
my $ex;
try {
$output := $super(self, $code, |@args, |%adverbs);

CATCH {
if nqp::what($_).HOW.name(nqp::what($_)) eq 'BOOTException' {
my $inner := nqp::getpayload(nqp::decont($_));

my $ex-type := nqp::what($inner).HOW.name(nqp::what($inner));
if $ex-type eq 'X::Syntax::Missing' {
if $inner.pos() == nqp::chars($code) {
return self.needs-more-input();
}
}
}
$ex := $_;
}
}
if $ex {
nqp::rethrow($ex);
}
$output;
}
}

0 comments on commit 2ecda56

Please sign in to comment.