From 9eeaa6f267068dc5566b0cbd71c0ee55adddc294 Mon Sep 17 00:00:00 2001 From: Pawel Murias Date: Mon, 17 Oct 2016 11:05:27 +0200 Subject: [PATCH] [js] Implement nqp::p6store. --- src/vm/js/Perl6/Ops.nqp | 1 + src/vm/js/perl6-runtime/runtime.js | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/vm/js/Perl6/Ops.nqp b/src/vm/js/Perl6/Ops.nqp index 449214b871b..65b99aeaf58 100644 --- a/src/vm/js/Perl6/Ops.nqp +++ b/src/vm/js/Perl6/Ops.nqp @@ -76,5 +76,6 @@ $ops.add_simple_op('p6captureouters', $ops.OBJ, [$ops.OBJ], :ctx); $ops.add_simple_op('p6capturelex', $ops.OBJ, [$ops.OBJ], :ctx); $ops.add_simple_op('p6bindassert', $ops.OBJ, [$ops.OBJ, $ops.OBJ], :ctx); +$ops.add_simple_op('p6store', $ops.OBJ, [$ops.OBJ, $ops.OBJ], :ctx); $ops.add_simple_op('p6var', $ops.OBJ, [$ops.OBJ], :sideffects); # TODO not really just needs marking as returning a fresh value diff --git a/src/vm/js/perl6-runtime/runtime.js b/src/vm/js/perl6-runtime/runtime.js index d552cfd3b10..9bdf1b1c4ea 100644 --- a/src/vm/js/perl6-runtime/runtime.js +++ b/src/vm/js/perl6-runtime/runtime.js @@ -125,6 +125,20 @@ op.p6bindassert = function(ctx, value, type) { return value; }; +op.p6store = function(ctx, cont, value) { + if (cont) { + cont.$$assign(nqp.op.decont(ctx, value)); + } else { + if (!cont.STORE) { + // TODO throw typed exception X::Assignment::RO + ctx.die("Cannot assign to a non-container"); + } else { + cont.STORE(ctx, null, cont, value); + } + } + return cont; +}; + var containerSpecs = require('nqp-runtime/container-specs.js'); function RakudoScalar(STable) { @@ -138,12 +152,13 @@ RakudoScalar.prototype.configure = function(conf) { RakudoScalar.prototype.setupSTable = function() { this.STable.addInternalMethod('$$assignunchecked', function(ctx, value) { console.log('storing into rakudo_scalar unchecked'); - process.exit(); + return this.$$bindattr(Scalar, '$!value', value); }); this.STable.addInternalMethod('$$assign', function(ctx, value) { console.log('storing into rakudo_scalar'); - process.exit(); + /* TODO - checking and WHENCE */ + return this.$$bindattr(Scalar, '$!value', value); }); this.STable.addInternalMethod('$$decont', function(ctx) {