Skip to content

Commit

Permalink
Use the CompUnit::Handle as $*CTXSAVE instead of CompUnit::Loader
Browse files Browse the repository at this point in the history
Save a contextual and keeps more code dealing with module_ctx in
CompUnit::Handle.
  • Loading branch information
niner committed Jul 5, 2016
1 parent d5abea9 commit 41b685e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
10 changes: 9 additions & 1 deletion src/core/CompUnit/Handle.pm
Expand Up @@ -2,7 +2,15 @@ class CompUnit::Handle {
has Mu $!module_ctx;
has Mu $!unit;

submethod new(Mu \module_ctx) {
multi submethod new() {
nqp::create(self)
}

method ctxsave() {
$!module_ctx := nqp::ctxcaller(nqp::ctx()) unless $!module_ctx;
}

multi submethod new(Mu \module_ctx) {
nqp::p6bindattrinvres(
nqp::create(self),CompUnit::Handle,'$!module_ctx', module_ctx
)
Expand Down
33 changes: 14 additions & 19 deletions src/core/CompUnit/Loader.pm
Expand Up @@ -11,10 +11,10 @@ class CompUnit::Loader is repr('Uninstantiable') {
method load-source(Blob:D $bytes) returns CompUnit::Handle {
my $preserve_global := nqp::ifnull(nqp::gethllsym('perl6', 'GLOBAL'), Mu);

my $*CTXSAVE := self;
my $handle := CompUnit::Handle.new;
my $*CTXSAVE := $handle;
my $eval := nqp::getcomp('perl6').compile($bytes.decode);

my $*MAIN_CTX;
$eval();

nqp::bindhllsym('perl6', 'GLOBAL', $preserve_global);
Expand All @@ -26,42 +26,37 @@ class CompUnit::Loader is repr('Uninstantiable') {
}
}

CompUnit::Handle.new($*MAIN_CTX)
$handle
}

# Load a pre-compiled file
proto method load-precompilation-file(|) { * }
multi method load-precompilation-file(IO::Path $path) returns CompUnit::Handle {
my $*CTXSAVE := self;
my $handle := CompUnit::Handle.new;
my $*CTXSAVE := $handle;
my %*COMPILING := nqp::hash();
my Mu $*MAIN_CTX;
nqp::loadbytecode($path.Str);
CompUnit::Handle.new($*MAIN_CTX)
$handle
}

multi method load-precompilation-file(IO::Handle $handle) returns CompUnit::Handle {
my $*CTXSAVE := self;
multi method load-precompilation-file(IO::Handle $file) returns CompUnit::Handle {
my $handle := CompUnit::Handle.new;
my $*CTXSAVE := $handle;
my %*COMPILING := nqp::hash();
my Mu $*MAIN_CTX;
#?if moar
nqp::loadbytecodefh(nqp::getattr($handle, IO::Handle, '$!PIO'), $handle.path.Str);
nqp::loadbytecodefh(nqp::getattr($file, IO::Handle, '$!PIO'), $file.path.Str);
#?endif
CompUnit::Handle.new($*MAIN_CTX)
$handle
}

# Load the specified byte buffer as if it was the contents of a
# precompiled file
method load-precompilation(Blob:D $bytes) returns CompUnit::Handle {
my $*CTXSAVE := self;
my $handle := CompUnit::Handle.new;
my $*CTXSAVE := $handle;
my %*COMPILING := nqp::hash();
my Mu $*MAIN_CTX;
nqp::loadbytecodebuffer($bytes);
CompUnit::Handle.new($*MAIN_CTX)
}

method ctxsave() {
$*MAIN_CTX := nqp::ctxcaller(nqp::ctx());
$*CTXSAVE := 0;
$handle
}
}

Expand Down

0 comments on commit 41b685e

Please sign in to comment.