From 41b685ee102bcd483ad367a904577cad497dd0cb Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Tue, 5 Jul 2016 23:05:28 +0200 Subject: [PATCH] Use the CompUnit::Handle as $*CTXSAVE instead of CompUnit::Loader Save a contextual and keeps more code dealing with module_ctx in CompUnit::Handle. --- src/core/CompUnit/Handle.pm | 10 +++++++++- src/core/CompUnit/Loader.pm | 33 ++++++++++++++------------------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/core/CompUnit/Handle.pm b/src/core/CompUnit/Handle.pm index 691882006cc..3dbb08d76b6 100644 --- a/src/core/CompUnit/Handle.pm +++ b/src/core/CompUnit/Handle.pm @@ -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 ) diff --git a/src/core/CompUnit/Loader.pm b/src/core/CompUnit/Loader.pm index 9977123d41f..52eafd562a7 100644 --- a/src/core/CompUnit/Loader.pm +++ b/src/core/CompUnit/Loader.pm @@ -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); @@ -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 } }