Skip to content

Instantly share code, notes, and snippets.

@FROGGS

FROGGS/wip.patch Secret

Created December 4, 2015 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FROGGS/8d2235c0fdf5b70bd4be to your computer and use it in GitHub Desktop.
Save FROGGS/8d2235c0fdf5b70bd4be to your computer and use it in GitHub Desktop.
diff --git a/src/Perl6/Actions.nqp b/src/Perl6/Actions.nqp
index 28f9095..b5b1607 100644
--- a/src/Perl6/Actions.nqp
+++ b/src/Perl6/Actions.nqp
@@ -2192,6 +2192,32 @@ Compilation unit '$file' contained the following violations:
$past := $*W.add_string_constant($*W.current_file);
}
}
+ elsif $name eq '%?RESOURCES' {
+ my $resources := nqp::getlexdyn('$*RESOURCES');
+ unless $resources {
+ nqp::sayfh(nqp::getstderr(), "Fallback to precomp ENV var");
+ my $Resources := $*W.find_symbol(['Distribution', 'Resources']);
+ nqp::sayfh(nqp::getstderr(), "Got Distribution::Resources");
+ $resources := $Resources.from-precomp();
+ nqp::sayfh(nqp::getstderr(), "Created resources object");
+ }
+ if $resources {
+ nqp::sayfh(nqp::getstderr(), "Got an object!");
+ $past := QAST::WVal.new( :value($resources) );
+ if nqp::isnull(nqp::getobjsc($resources)) {
+ nqp::sayfh(nqp::getstderr(), "Adding to SC");
+ $*W.add_object($resources);
+ nqp::sayfh(nqp::getstderr(), "Added");
+ }
+ }
+ else {
+ #~ $resources := QAST::Op.new( :op('call'), :name('&DYNAMIC'),
+ #~ $*W.add_string_constant('$*RESOURCES'));
+ nqp::sayfh(nqp::getstderr(), "empty!");
+ $past := QAST::WVal.new( :value($*W.find_symbol(['Nil'])) );
+ }
+ #~ $past := QAST::WVal.new( :value($*W.find_symbol(['Nil'])) );
+ }
elsif $name eq '&?BLOCK' || $name eq '&?ROUTINE' {
if $*IN_DECL eq 'variable' {
$*W.throw($/, 'X::Syntax::Variable::Twigil',
diff --git a/src/core/CompUnit/Handle.pm b/src/core/CompUnit/Handle.pm
index ec9b150..09da3a4 100644
--- a/src/core/CompUnit/Handle.pm
+++ b/src/core/CompUnit/Handle.pm
@@ -1,10 +1,12 @@
class CompUnit::Handle {
- has Mu $!module_ctx;
+ #~ has Mu $!module_ctx;
+ has Mu $!lexpad;
has Mu $!unit;
- submethod new(Mu \module_ctx) {
+ submethod new(Mu \lexpad) {
my $self := nqp::create(self);
- nqp::bindattr($self, CompUnit::Handle, '$!module_ctx', module_ctx);
+ #~ nqp::bindattr($self, CompUnit::Handle, '$!module_ctx', module_ctx);
+ nqp::bindattr($self, CompUnit::Handle, '$!lexpad', nqp::ctxlexpad(lexpad));
$self
}
@@ -61,9 +63,9 @@ class CompUnit::Handle {
# (the module's contributions to GLOBAL, for merging); a Stash
# type object if none.
method globalish-package() { # returns Stash {
- if nqp::defined($!module_ctx) {
- my $lexpad := nqp::ctxlexpad($!module_ctx);
- nqp::isnull(nqp::atkey($lexpad, 'GLOBALish')) ?? Nil !! nqp::atkey($lexpad, 'GLOBALish')
+ if nqp::defined($!lexpad) {
+ #~ my $lexpad := nqp::ctxlexpad($!module_ctx);
+ nqp::isnull(nqp::atkey($!lexpad, 'GLOBALish')) ?? Nil !! nqp::atkey($!lexpad, 'GLOBALish')
}
else {
Nil
@@ -73,7 +75,7 @@ class CompUnit::Handle {
method unit() {
nqp::defined($!unit)
?? $!unit
- !! nqp::defined($!module_ctx) ?? nqp::ctxlexpad($!module_ctx) !! {}
+ !! nqp::defined($!lexpad) ?? $!lexpad !! {}
}
}
diff --git a/src/core/CompUnit/PrecompilationRepository.pm b/src/core/CompUnit/PrecompilationRepository.pm
index 0b5d0a3..9f67ace 100644
--- a/src/core/CompUnit/PrecompilationRepository.pm
+++ b/src/core/CompUnit/PrecompilationRepository.pm
@@ -36,6 +36,7 @@ class CompUnit::PrecompilationRepository::Default does CompUnit::PrecompilationR
my $modified = $path.modified;
if not $since or $modified > $since and self!check-dependencies($path, $modified) {
my $preserve_global := nqp::ifnull(nqp::gethllsym('perl6', 'GLOBAL'), Mu);
+RAKUDO_MODULE_DEBUG("Loading precompiled $path") if $*RAKUDO_MODULE_DEBUG;
my $handle := CompUnit::Loader.load-precompilation-file($path);
nqp::bindhllsym('perl6', 'GLOBAL', $preserve_global);
CATCH {
@@ -68,18 +69,23 @@ class CompUnit::PrecompilationRepository::Default does CompUnit::PrecompilationR
!! Empty;
%*ENV<RAKUDO_PRECOMP_WITH> = $*REPO.repo-chain>>.path-spec.join(',');
%*ENV<RAKUDO_PRECOMP_LOADING> = to-json @*MODULES;
+ my $current_dist = %*ENV<RAKUDO_PRECOMP_DIST>;
+ %*ENV<RAKUDO_PRECOMP_DIST> = $*RESOURCES ?? $*RESOURCES.Str !! '{}';
-RAKUDO_MODULE_DEBUG("Precomping with %*ENV<RAKUDO_PRECOMP_WITH>")
- if $*RAKUDO_MODULE_DEBUG;
+RAKUDO_MODULE_DEBUG("Precomping $path with %*ENV<RAKUDO_PRECOMP_WITH>") if $*RAKUDO_MODULE_DEBUG;
my $proc = run($*EXECUTABLE, $lle, "--target={$*VM.precomp-target}", "--output=$io", $path, :out);
+RAKUDO_MODULE_DEBUG("Done precomping $path") if $*RAKUDO_MODULE_DEBUG;
%*ENV<RAKUDO_PRECOMP_WITH>:delete;
%*ENV<RAKUDO_PRECOMP_LOADING>:delete;
+RAKUDO_MODULE_DEBUG("Restoring RAKUDO_PRECOMP_DIST: $current_dist") if $*RAKUDO_MODULE_DEBUG;
+ %*ENV<RAKUDO_PRECOMP_DIST> = $current_dist;
my @result = $proc.out.lines;
if not $proc.out.close or $proc.status { # something wrong
self.store.unlock;
push @result, "Return status { $proc.status }\n";
+RAKUDO_MODULE_DEBUG("Precomping $path failed: {@result}") if $*RAKUDO_MODULE_DEBUG;
fail @result if @result;
}
else {
diff --git a/src/core/CompUnit/Repository/FileSystem.pm b/src/core/CompUnit/Repository/FileSystem.pm
index 096cbea..39558a0 100644
--- a/src/core/CompUnit/Repository/FileSystem.pm
+++ b/src/core/CompUnit/Repository/FileSystem.pm
@@ -51,6 +51,7 @@ class CompUnit::Repository::FileSystem does CompUnit::Repository::Locally does C
if $found {
my $id = nqp::sha1($name ~ $*REPO.id);
say "$id $found" if $*W and $*W.is_precompilation_mode;
+ my $*RESOURCES = Distribution::Resources.new(:repo(self), :dist-id(''));
my $handle = (
$precomp.may-precomp and (
$precomp.load($id, :since($found.modified)) # already precompiled?
@@ -61,7 +62,8 @@ class CompUnit::Repository::FileSystem does CompUnit::Repository::Locally does C
$handle ||= CompUnit::Loader.load-source-file($found); # precomp failed
- return %!loaded{$name} = %seen{$base} = CompUnit.new(
+ #~ return %!loaded{$name} = %seen{$base} = CompUnit.new(
+ return CompUnit.new(
:short-name($name), :$handle, :repo(self), :repo-id($id), :$precompiled
);
}
@@ -80,7 +82,8 @@ class CompUnit::Repository::FileSystem does CompUnit::Repository::Locally does C
!! $!prefix.child($file);
if $path.f {
- return %!loaded{$file} = %seen{$path} = CompUnit.new(
+ #~ return %!loaded{$file} = %seen{$path} = CompUnit.new(
+ return CompUnit.new(
:handle(CompUnit::Loader.load-source-file($path)),
:short-name($file.Str),
:repo(self),
@@ -106,6 +109,10 @@ class CompUnit::Repository::FileSystem does CompUnit::Repository::Locally does C
!! ();
}
+ method resource($dist-id, $key) {
+ $.prefix.parent.child('resources').child($key);
+ }
+
method precomp-repository() returns CompUnit::PrecompilationRepository {
$!precomp := CompUnit::PrecompilationRepository::Default.new(
:store(
diff --git a/src/core/CompUnit/Repository/Installation.pm b/src/core/CompUnit/Repository/Installation.pm
index 527de41..01d62fd 100644
--- a/src/core/CompUnit/Repository/Installation.pm
+++ b/src/core/CompUnit/Repository/Installation.pm
@@ -247,6 +247,7 @@ sub MAIN(:$name is copy, :$auth, :$ver, *@, *%) {
my $loader = $.prefix.child('sources').child(
$dist<provides>{$spec.short-name}<pm pm6>.first(*.so)<file>
);
+ my $*RESOURCES = Distribution::Resources.new(:repo(self), :$dist-id);
my $handle;
my $id = self!precomp-id($loader.Str);
if $precomp.may-precomp {
@@ -268,7 +269,8 @@ sub MAIN(:$name is copy, :$auth, :$ver, *@, *%) {
:$precompiled,
:distribution(Distribution.new(|$dist)),
);
- return %!loaded{$compunit.short-name} = $compunit;
+ #~ return %!loaded{$compunit.short-name} = $compunit;
+ return $compunit;
}
}
}
diff --git a/src/core/Distribution.pm b/src/core/Distribution.pm
index 06a43b8..7dd8756 100644
--- a/src/core/Distribution.pm
+++ b/src/core/Distribution.pm
@@ -38,4 +38,26 @@ class CompUnitRepo::Distribution is Distribution {
method Hash { self.hash }
}
+role CompUnit::Repository { ... }
+class CompUnitRepo { ... }
+class Distribution::Resources does Associative {
+ has Str $.dist-id;
+ has CompUnit::Repository $.repo;
+
+ method from-precomp() {
+ return unless %*ENV<RAKUDO_PRECOMP_DIST>;
+ my %data := from-json %*ENV<RAKUDO_PRECOMP_DIST>;
+ self.new(:repo(CompUnitRepo.new(%data<repo>)), :dist-id(%data<dist-id>))
+ }
+
+ method AT-KEY($key) {
+ note "Accessing $key of $.dist-id in $.repo";
+ $.repo.resource($.dist-id, $key)
+ }
+
+ method Str() {
+ to-json {repo => $.repo.Str, dist-id => $.dist-id};
+ }
+}
+
# vim: ft=perl6 expandtab sw=4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment