From 1978fd1d7266f4a0a155d15c92d8e8850450a089 Mon Sep 17 00:00:00 2001 From: pmurias Date: Wed, 31 May 2017 15:36:24 +0200 Subject: [PATCH] [js] Fix nqp::p6finddispatcher and implement p6argsfordispatcher --- src/vm/js/Perl6/Ops.nqp | 6 +++++- src/vm/js/perl6-runtime/runtime.js | 19 ++++++++++++++++--- t/spectest.js.data | 4 ++++ tools/build/NQP_REVISION | 2 +- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/vm/js/Perl6/Ops.nqp b/src/vm/js/Perl6/Ops.nqp index c3245cd5f32..30c3775ab40 100644 --- a/src/vm/js/Perl6/Ops.nqp +++ b/src/vm/js/Perl6/Ops.nqp @@ -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)" }); diff --git a/src/vm/js/perl6-runtime/runtime.js b/src/vm/js/perl6-runtime/runtime.js index f96fb3ce528..2e015b18dba 100644 --- a/src/vm/js/perl6-runtime/runtime.js +++ b/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 = {}; @@ -231,7 +231,7 @@ 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) { @@ -239,7 +239,7 @@ module.exports.load = function(nqp, CodeRef, containerSpecs) { 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; @@ -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; diff --git a/t/spectest.js.data b/t/spectest.js.data index 7e12ae163a5..7bfe5aee3c9 100644 --- a/t/spectest.js.data +++ b/t/spectest.js.data @@ -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 diff --git a/tools/build/NQP_REVISION b/tools/build/NQP_REVISION index 6fd16df52bd..36a9c602ddd 100644 --- a/tools/build/NQP_REVISION +++ b/tools/build/NQP_REVISION @@ -1 +1 @@ -2017.05-52-gcb169e00b +2017.05-62-g2093461ee