Skip to content

Commit

Permalink
[js] Implement nqp::p6store.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmurias committed Oct 17, 2016
1 parent 5c1b5e6 commit 9eeaa6f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/vm/js/Perl6/Ops.nqp
Expand Up @@ -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
19 changes: 17 additions & 2 deletions src/vm/js/perl6-runtime/runtime.js
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 9eeaa6f

Please sign in to comment.