Skip to content

Commit

Permalink
[js] Fix nqp::p6finddispatcher and implement p6argsfordispatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
pmurias committed May 31, 2017
1 parent 2e0d8b3 commit 1978fd1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/vm/js/Perl6/Ops.nqp
Expand Up @@ -139,5 +139,9 @@ $ops.add_op('p6return', :!inlinable, sub ($comp, $node, :$want, :$cps) {
$ops.add_simple_op('p6decodelocaltime', $ops.OBJ, [$ops.INT], :side_effects); # TODO not really :side_effects just needs marking as returning a fresh value

$ops.add_simple_op('p6finddispatcher', $ops.OBJ, [$ops.STR], :side_effects, sub ($usage) {
"nqp.op.p6finddispatcher({$*BLOCK.ctx}, $usage, nqp.op.savecapture(Array.prototype.slice.call(arguments)))"
"nqp.op.p6finddispatcher({$*BLOCK.ctx}, $usage)"
});

$ops.add_simple_op('p6argsfordispatcher', $ops.OBJ, [$ops.OBJ], :side_effects, sub ($dispatcher) {
"nqp.op.p6argsfordispatcher({$*BLOCK.ctx}, $dispatcher)"
});
19 changes: 16 additions & 3 deletions src/vm/js/perl6-runtime/runtime.js
@@ -1,4 +1,4 @@
module.exports.load = function(nqp, CodeRef, containerSpecs) {
module.exports.load = function(nqp, CodeRef, Capture, containerSpecs) {
var Null = nqp.Null;
var op = {};

Expand Down Expand Up @@ -231,15 +231,15 @@ module.exports.load = function(nqp, CodeRef, containerSpecs) {
]);
}

op.p6finddispatcher = function(ctx, usage, argss) {
op.p6finddispatcher = function(ctx, usage) {
let dispatcher;
let search = ctx.$$caller;
while (search) {
/* Do we have a dispatcher here? */
if (search.hasOwnProperty(["$*DISPATCHER"])) {
dispatcher = search["$*DISPATCHER"];
if (dispatcher.typeObject_) {
dispatcher = dispatcher.vivify_for(dispatcher, ctx.codeRef().codeObj, ctx, args);
dispatcher = dispatcher.vivify_for(ctx, null, dispatcher, search.codeRef().codeObj, search, new Capture(search.$$args[1], Array.prototype.slice.call(search.$$args, 2)));
search["$*DISPATCHER"] = dispatcher;
}
return dispatcher;
Expand All @@ -251,6 +251,19 @@ module.exports.load = function(nqp, CodeRef, containerSpecs) {
throw usage + ' is not in the dynamic scope of a dispatcher';
};

op.p6argsfordispatcher = function(ctx, dispatcher) {
console.log("calling p6argsfordispatcher");
let search = ctx;
while (search) {
/* Do we have the dispatcher we're looking for? */
if (search['$*DISPATCHER'] === dispatcher) {
return new Capture(search.$$args[1], Array.prototype.slice.call(search.$$args, 2));
}
/* Follow dynamic chain. */
search = search.$$caller;
}
throw 'Could not find arguments for dispatcher';
};

function RakudoScalar(STable) {
this.STable = STable;
Expand Down
4 changes: 4 additions & 0 deletions t/spectest.js.data
Expand Up @@ -60,3 +60,7 @@ S02-literals/subscript.t
S02-literals/types.t
S02-literals/underscores.t
#S02-literals/version.t
S03-junctions/associative.t
S03-junctions/autothreading.t
S03-junctions/boolean-context.t
S03-junctions/misc.t
2 changes: 1 addition & 1 deletion tools/build/NQP_REVISION
@@ -1 +1 @@
2017.05-52-gcb169e00b
2017.05-62-g2093461ee

0 comments on commit 1978fd1

Please sign in to comment.