Skip to content

Commit

Permalink
[js] Plugable and serializable container specs.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmurias committed May 19, 2016
1 parent 929d750 commit 45e0bfb
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 30 deletions.
46 changes: 46 additions & 0 deletions src/vm/js/nqp-runtime/container-configurer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
function CodePair(STable) {
this.STable = STable;
}

CodePair.prototype.configure = function(conf) {
this.fetch = conf.content.get('fetch');
this.store = conf.content.get('store');

this.setupSTable();

};

CodePair.prototype.setupSTable = function() {
var fetch = this.fetch;
var store = this.store;

this.STable.addInternalMethod('$$assignunchecked', function(ctx, value) {
store.$call(ctx, {}, this, value);
return value;
});

this.STable.addInternalMethod('$$assign', function(ctx, value) {
store.$call(ctx, {}, this, value);
return value;
});

this.STable.addInternalMethod('$$decont', function(ctx) {
return fetch.$call(ctx, {}, this);
});
};

CodePair.prototype.serialize = function(cursor) {
cursor.ref(this.fetch);
cursor.ref(this.store);
};

CodePair.prototype.deserialize = function(cursor) {
this.fetch = cursor.variant();
this.store = cursor.variant();

this.setupSTable();
};

CodePair.prototype.name = 'code_pair';

exports.code_pair = CodePair;
22 changes: 6 additions & 16 deletions src/vm/js/nqp-runtime/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ var nqp = require('nqp-runtime');

var constants = require('./constants.js');

var containerConfigurer = require('./container-configurer.js');

exports.CodeRef = CodeRef;

op.atpos = function(array, index) {
Expand Down Expand Up @@ -443,22 +445,10 @@ op.curlexpad = function(get, set) {
return new CurLexpad(get, set);
};

op.setcontspec = function(type, contSpecType, hash) {
if (contSpecType === 'code_pair') {
var fetch = hash.content.get('fetch');
var store = hash.content.get('store');

type._STable.addInternalMethod('$$assignunchecked', function(ctx, value) {
store.$call(ctx, {}, this, value);
return value;
});
type._STable.addInternalMethod('$$assign', function(ctx, value) {
store.$call(ctx, {}, this, value);
return value;
});
type._STable.addInternalMethod('$$decont', function(ctx) {
return fetch.$call(ctx, {}, this);
});
op.setcontspec = function(type, specType, conf) {
if (containerConfigurer[specType]) {
type._STable.containerSpec = new containerConfigurer[specType](type._STable);
type._STable.containerSpec.configure(conf);
} else {
console.warn('NYI cont spec: ' + contSpecType);
}
Expand Down
11 changes: 5 additions & 6 deletions src/vm/js/nqp-runtime/deserialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ var CodeRef = require('./code-ref.js');
var constants = require('./constants.js');
var NQPArray = require('./array.js');

var containerConfigurer = require('./container-configurer.js');

var hll = require('./hll.js');

/** All the loaded serialization contexts using their unique IDs as keys */
Expand Down Expand Up @@ -333,12 +335,9 @@ BinaryCursor.prototype.STable = function(STable) {
}

if (flags & STABLE_HAS_CONTAINER_SPEC) {
console.log('TODO container spec');
/* TODO - container stuff */
/* STable.container_class_handle = this.variant();
STable.containerAttrName = this.str();
STable.containerHint = this.I64();
STable.containerFetchMethod = this.variant();*/
var specType = this.str();
STable.containerSpec = new containerConfigurer[specType](STable);
STable.containerSpec.deserialize(this);
}

if (flags & STABLE_HAS_INVOCATION_SPEC) {
Expand Down
17 changes: 9 additions & 8 deletions src/vm/js/nqp-runtime/serialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,10 +485,9 @@ SerializationWriter.prototype.serializeSTable = function(st) {
flags = 0xF;
}

/*
if (st->containerSpec != NULL)
if (st.containerSpec) {
flags |= STABLE_HAS_CONTAINER_SPEC;
*/
}

if (st.invocationSpec) {
flags |= STABLE_HAS_INVOCATION_SPEC;
Expand All @@ -506,11 +505,13 @@ SerializationWriter.prototype.serializeSTable = function(st) {
this.stablesData.ref(st.boolificationSpec.method);
}

/*this.stablesData.writeInt(st.ContainerSpec == null ? 0 : 1);
if (st.ContainerSpec != null) {
writeStr(st.ContainerSpec.name());
st.ContainerSpec.serialize(tc, st, this);
}*/
if (st.containerSpec) {
/* Write container spec name. */
this.stablesData.str(st.containerSpec.name);

/* Give container spec a chance to serialize any data it wishes. */
st.containerSpec.serialize(this.stablesData);
}

/* Invocation spec. */

Expand Down

0 comments on commit 45e0bfb

Please sign in to comment.