Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[js] serialize code refs marked as static
  • Loading branch information
pmurias committed Oct 2, 2015
1 parent 8402ce0 commit d1fcbf0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/vm/js/QAST/Compiler.nqp
Expand Up @@ -724,7 +724,9 @@ class QAST::OperationsJS {
add_simple_op('deserialize', $T_OBJ, [$T_STR, $T_OBJ, $T_OBJ, $T_OBJ, $T_OBJ], :sideffects);
add_simple_op('scsetobj', $T_OBJ, [$T_OBJ, $T_INT, $T_OBJ], :sideffects);
add_simple_op('scgetobj', $T_OBJ, [$T_OBJ, $T_INT], :sideffects);
add_simple_op('scsetcode', $T_OBJ, [$T_OBJ, $T_INT, $T_OBJ], :sideffects);
add_simple_op('setobjsc', $T_OBJ, [$T_OBJ, $T_OBJ], :sideffects);
add_simple_op('markcodestatic', $T_OBJ, [$T_OBJ], :sideffects);

# Ops for NFA

Expand Down
5 changes: 5 additions & 0 deletions src/vm/js/nqp-runtime/core.js
Expand Up @@ -458,3 +458,8 @@ op.elems = function(obj) {
return obj.$$elems();
}
};

op.markcodestatic = function(code) {
code.isStatic = true;
return code;
};
11 changes: 8 additions & 3 deletions src/vm/js/nqp-runtime/serialization.js
Expand Up @@ -288,7 +288,7 @@ BinaryWriteCursor.prototype.ref = function(ref) {
else if (ref instanceof CodeRef || typeof ref == 'function') {
// console.log("serializing code ref");
discrim = REFVAR_VM_NULL;
if (ref._SC && ref.isStaticCodeRef) {
if (ref._SC && ref.isStatic) {
/* Static code reference. */
discrim = REFVAR_STATIC_CODEREF;
}
Expand Down Expand Up @@ -352,8 +352,7 @@ BinaryWriteCursor.prototype.ref = function(ref) {
case REFVAR_CLONED_CODEREF:
var scId = this.writer.getSCId(ref._SC);
var idx = ref._SC.root_codes.indexOf(ref);
this.I32(scId);
this.I32(idx);
this.idIdx(scId, idx);
break;
default:
throw 'Serialization Error: Unimplemented object type: ' + discrim;
Expand Down Expand Up @@ -673,4 +672,10 @@ op.setobjsc = function(obj, sc) {
return obj;
};

op.scsetcode = function(sc, idx, obj) {
sc.root_codes[idx] = obj;
obj._SC = sc;
return obj;
};

exports.BinaryWriteCursor = BinaryWriteCursor;

0 comments on commit d1fcbf0

Please sign in to comment.