Skip to content
Permalink
Browse files

[js] Implement recording of modules loaded at compile time

  • Loading branch information...
pmurias committed Nov 7, 2018
1 parent f460ad1 commit cbbe16edd1015cb9894efe3d49d038bcc9526b73
@@ -10,6 +10,10 @@ class CompUnit::Repository::JavaRuntime { ... }
class CompUnit::Repository::Java { ... }
#?endif

#?if js
class CompUnit::Repository::FileSystemWithRecording { ... }
#?endif

class CompUnit::RepositoryRegistry {
my $lock = Lock.new;
my %include-spec2cur;
@@ -345,6 +349,9 @@ class CompUnit::RepositoryRegistry {
#?if jvm
'javart', CompUnit::Repository::JavaRuntime,
'java', CompUnit::Repository::Java,
#?endif
#?if js
'filerecording', CompUnit::Repository::FileSystemWithRecording,
#?endif
);
my $sid-lock := Lock.new;
@@ -0,0 +1,21 @@
my class CompUnit::Repository::FileSystemWithRecording is CompUnit::Repository::FileSystem {
my class CompUnit::PrecompilationStore::FileSystemWithRecording is CompUnit::PrecompilationStore::File {
method load-unit(CompUnit::PrecompilationId $compiler-id,
CompUnit::PrecompilationId $precomp-id)
{
my $unit = self.CompUnit::PrecompilationStore::File::load-unit($compiler-id, $precomp-id);
if $unit {
say('LOAD-UNIT ID:', $precomp-id.id, ' DEPS:', $unit.dependencies.map(*.id.id).join(','), ' PATH:', $unit.path.Str);
}
$unit;
}
}

has $!precomp-store;
method precomp-store(--> CompUnit::PrecompilationStore:D) {
$!precomp-store //= CompUnit::PrecompilationStore::FileSystemWithRecording.new(
:prefix(self.prefix.add('.precomp')),
)
}

}
@@ -24,7 +24,7 @@ const code = require('./rakudo.js');

const core = require('nqp-runtime/core.js');

module.exports = function(source) {
module.exports = function(source, options = {}) {
const tmpFile = tmp.tmpNameSync();

passedArgs = ['perl6-js', '--output', tmpFile, '--target=js', source];
@@ -35,7 +35,14 @@ module.exports = function(source) {
output.push(core.toRawBuffer(buf));
}

code();
if (options.rakudoPrecompWith) {
const oldValue = options.rakudoPrecompWith;
process.env.RAKUDO_PRECOMP_WITH = options.rakudoPrecompWith;
code();
process.env.RAKUDO_PRECOMP_WITH = oldValue;
} else {
code();
}

nqp.op.getstdout().constructor.prototype.$$writefh = oldWritefh;
const lines = Buffer.concat(output).toString().split(/\n/);
@@ -45,9 +52,11 @@ module.exports = function(source) {
for (const line of lines) {
let match;
if (/^[A-Z0-9]{40}\0/.test(line)) {
} else if (match = line.match(/^load-unit: (.+)/)) {
loaded.push(match[1]);
} else if (match = line.match(/^LOAD-UNIT ID:(.*?) DEPS:(.*?) PATH:(.*)/)) {
const deps = match[2] == '' ? [] : match[2].split(',');
loaded.push({id: match[1], deps: deps, path: match[3]});
} else {
console.warn('extra line', line);
}
}

@@ -204,6 +204,7 @@ src/core/CompUnit/Repository/AbsolutePath.pm6
src/core/CompUnit/Repository/NQP.pm6
src/core/CompUnit/Repository/Perl5.pm6
src/core/CompUnit/Repository/Unknown.pm6
src/vm/js/CompUnit/Repository/FileSystemWithRecording.pm6
src/core/Argfiles.pm6
src/core/Process.pm6
src/core/Slang.pm6

0 comments on commit cbbe16e

Please sign in to comment.
You can’t perform that action at this time.