Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Pass test 55.
Deserialize closures which have no context.
Set the code object on deserialized closures.
  • Loading branch information
pmurias committed Feb 14, 2015
1 parent 020a5af commit 6c9e703
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/vm/js/QAST/Compiler.nqp
Expand Up @@ -1502,7 +1502,7 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
method setup_cuids() {
my @cuids;
for %!cuids {
@cuids.push("{self.mangled_cuid($_.key)} = new nqp.CodeRef({quote_string($_.value.name)})");
@cuids.push("{self.mangled_cuid($_.key)} = new nqp.CodeRef({quote_string($_.value.name)},{quote_string($_.key)})");
}
self.declare_js_vars(@cuids);
}
Expand Down Expand Up @@ -1538,7 +1538,9 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
has $!closure_template;
has $!static_info;
has $!ctx;
has $!outer_ctx;
method ctx() {$!ctx}
method outer_ctx() {$!outer_ctx}
method static_info() {$!static_info}
method closure_template() {$!closure_template}
}
Expand Down Expand Up @@ -1609,6 +1611,7 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
%!serialized_code_ref_info{$node.cuid} := SerializedCodeRefInfo.new(
closure_template => Chunk.new($T_OBJ, "", $function).join(),
ctx => $*BLOCK.ctx,
outer_ctx => $*BLOCK.outer.ctx,
static_info => self.static_info_for_lexicals($*BLOCK)
);
}
Expand Down Expand Up @@ -1724,6 +1727,7 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
~ self.mangled_cuid($block.cuid)
~ ".setInfo("
~ quote_string($info.ctx) ~ ","
~ quote_string($info.outer_ctx) ~ ","
~ quote_string($info.closure_template) ~ ","
~ $info.static_info
~ ");\n";
Expand Down
2 changes: 1 addition & 1 deletion src/vm/js/bin/run_tests
@@ -1,3 +1,3 @@
#!/bin/bash
# 19 and 30 where moved out as they were parrot specific, 52,54 is missing, we can't pass 49 till we are bootstraped
prove "$@" -e './nqp-js' t/nqp/{01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,20,21,22,23,25,26,27,28,33,35,36,37,38,39,40,41,42,46,47,48,51,53,56,57,58,59,63,64,65,68,69,70,71,75,76,81,83,88,89,90,91,92,93}* t/js/getcomp-js.t t/qast/02*
prove "$@" -e './nqp-js' t/nqp/{01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,20,21,22,23,25,26,27,28,33,35,36,37,38,39,40,41,42,46,47,48,51,53,55,56,57,58,59,63,64,65,68,69,70,71,75,76,81,83,88,89,90,91,92,93}* t/js/getcomp-js.t t/qast/02*
7 changes: 5 additions & 2 deletions src/vm/js/nqp-runtime/code-ref.js
@@ -1,5 +1,6 @@
function CodeRef(name) {
function CodeRef(name, cuid) {
this.name = name;
this.cuid = cuid;
}

CodeRef.prototype.block = function(func) {
Expand All @@ -22,9 +23,10 @@ CodeRef.prototype.setCodeObj = function(codeObj) {
return this;
};

CodeRef.prototype.setInfo = function(ctx, closureTemplate, staticInfo) {
CodeRef.prototype.setInfo = function(ctx, outerCtx, closureTemplate, staticInfo) {
this.closureTemplate = closureTemplate;
this.ctx = ctx;
this.outerCtx = outerCtx;
this.staticInfo = staticInfo;
return this;
};
Expand All @@ -33,6 +35,7 @@ CodeRef.prototype.$$clone = function() {
var clone = new CodeRef(this.name);
clone.$call = this.$call;
clone.codeObj = this.codeObj;
clone.cuid = this.cuid+" clone";
return clone;
};

Expand Down
20 changes: 17 additions & 3 deletions src/vm/js/nqp-runtime/deserialization.js
Expand Up @@ -430,7 +430,8 @@ BinaryCursor.prototype.deserialize = function(sc) {

var closures_base = sc.code_refs.length
for (var i=0; i < closures.length; i++) {
sc.code_refs[closures_base+i] = new CodeRef();
sc.code_refs[closures_base+i] = new CodeRef('closure: ' + sc.handle + " " +(closures_base+i));
if (closures[i].codeObj) sc.code_refs[closures_base+i].codeObj = closures[i].codeObj;
closures[i].index = closures_base+i;
}

Expand Down Expand Up @@ -458,16 +459,29 @@ BinaryCursor.prototype.deserialize = function(sc) {
for (var i = 0; i < contexts.length ; i++) {
if (contexts[i].outer) contexts[contexts[i].outer-1].inner.push(contexts[i]);
}

var no_context_closures = [];


for (var i = 0; i < closures.length ; i++) {
if (closures[i].context) contexts[closures[i].context-1].closures.push(closures[i]);
if (closures[i].context) {
contexts[closures[i].context-1].closures.push(closures[i]);
} else {
no_context_closures.push(closures[i]);
}
}

var code = no_context_closures.map(function(closure) {
return 'var ' + closure.staticCode.outerCtx + ' = null;\n' +
'sc.code_refs[' + closure.index + '].block(' +
closure.staticCode.closureTemplate +
');\n'
}).join("");

for (var i = 0; i < contexts.length ; i++) {
}

var data = [];
var code = '';
for (var i = 0; i < contexts.length ; i++) {
if (contexts[i].outer == 0) {
code += this.contextToCode(contexts[i], data) + "\n\n";
Expand Down

0 comments on commit 6c9e703

Please sign in to comment.