Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Preserve interactive eval context as an attribute of the compiler
  • Loading branch information
hoelzro committed Apr 24, 2015
1 parent f12e63a commit cf14f27
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/HLL/Compiler.nqp
Expand Up @@ -11,6 +11,7 @@ class HLL::Compiler does HLL::Backend::Default {
has @!cli-arguments;
has %!cli-options;
has $!backend;
has $!save_ctx;

method BUILD() {
# Backend is set to the default one, by default.
Expand Down Expand Up @@ -56,6 +57,10 @@ class HLL::Compiler does HLL::Backend::Default {
return nqp::readlinefh($stdin);
}

method context() {
$!save_ctx # XXX starting value?
}

method interactive(*%adverbs) {
nqp::printfh(nqp::getstderr(), self.interactive_banner);

Expand All @@ -67,7 +72,6 @@ class HLL::Compiler does HLL::Backend::Default {
}

my $target := nqp::lc(%adverbs<target>);
my $save_ctx;
my $prompt := self.interactive_prompt // '> ';
my $code;
while 1 {
Expand Down Expand Up @@ -100,13 +104,13 @@ class HLL::Compiler does HLL::Backend::Default {
$code := $code ~ "\n";
my $output;
{
$output := self.eval($code, :outer_ctx($save_ctx), |%adverbs);
$output := self.eval($code, :outer_ctx($!save_ctx), |%adverbs);
CATCH {
self.interactive_exception($!);
}
};
if nqp::defined($*MAIN_CTX) {
$save_ctx := $*MAIN_CTX;
$!save_ctx := $*MAIN_CTX;
}

$code := "";
Expand Down

0 comments on commit cf14f27

Please sign in to comment.