Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Start of methods support.
knowhow Foo {
    method lol() {
        say("yay, this works");
    }
}
Foo.lol();
  • Loading branch information
pmurias committed Sep 26, 2014
1 parent c2f2d39 commit ac78dbd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/vm/js/nqp-runtime/deserialization.js
Expand Up @@ -17,8 +17,9 @@ module.exports.wval = function(handle, idx) {
return serialization_contexts[handle].root_objects[idx];
};

op.deserialize = function(blob, sc, sh, cr, conflict) {
op.deserialize = function(blob, sc, sh, code_refs, conflict) {
var buffer = new Buffer(blob, 'base64');
sc.code_refs = code_refs;
var cursor = new BinaryCursor(buffer, 0, sh, sc);

cursor.deserialize(sc);
Expand Down Expand Up @@ -147,9 +148,8 @@ BinaryCursor.prototype.variant = function() {
case 10:
return this.hashOfVariants(this);
case 11:
return new StubedCodeRef(this.I32(), this.I32());
case 12:
return new StubedCodeRef(this.I32(), this.I32());
return this.sc.deps[this.I32()].code_refs[this.I32()];
default:
console.trace('unknown variant');
throw 'unknown variant: ' + type;
Expand All @@ -159,14 +159,14 @@ BinaryCursor.prototype.variant = function() {

/** Read an entry from the STable table */
BinaryCursor.prototype.STable = function(STable) {
var STable = {};
STable.HOW = this.objRef();
STable.WHAT = this.objRef();
STable.WHO = this.variant();

var method_cache = this.variant();

//console.log("method_cache", method_cache);
STable.setMethodCache(method_cache);

//TODO: maybe we should just get rid of the vtable
var vtable = [];
Expand Down
30 changes: 29 additions & 1 deletion src/vm/js/nqp-runtime/sixmodel.js
Expand Up @@ -3,9 +3,37 @@ function STable(REPR, HOW) {
this.HOW = HOW;
this.obj_constructor = function() {};
this.obj_constructor.prototype._STable = this;
// this.obj_constructor.prototype.repr_clone = repr_clone;

if (this.REPR.setup_STable) {
this.REPR.setup_STable(this);
}
}

function injectMethod(proto, name, method) {
proto[name] = function() {
// console.log("calling method:",name,method);
if (method.$call) {
var args = [];
args.push(arguments[0]);
args.push(arguments[1]);
args.push(this);
for (var i = 2; i < arguments.length; i++) {
args.push(arguments[i]);
}
return method.$call.apply(this, args);
}
};
}

STable.prototype.setMethodCache = function(method_cache) {
// TODO delete old methods
var proto = this.obj_constructor.prototype;
this.method_cache = method_cache;
for (var name in method_cache) {
if (method_cache.hasOwnProperty(name)) {
injectMethod(proto, name, method_cache[name]);
}
}
};

module.exports.STable = STable;

0 comments on commit ac78dbd

Please sign in to comment.