Skip to content

Commit

Permalink
[js] Implement p6decontrv
Browse files Browse the repository at this point in the history
  • Loading branch information
pmurias committed Apr 15, 2017
1 parent bf1d35f commit 631468e
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/vm/js/perl6-runtime/runtime.js
Expand Up @@ -3,7 +3,7 @@ var Null = nqp.Null;
var CodeRef = require('nqp-runtime/code-ref');
var op = {};

var Scalar, True, False, Int, Num, Str, Code, Mu, Any, ContainerDescriptor;
var Scalar, True, False, Int, Num, Str, Code, Mu, Any, ContainerDescriptor, Routine;

var defaultContainerDescriptor;

Expand All @@ -17,6 +17,7 @@ op.p6settypes = function(types) {
Code = types.content.get('Code');
Mu = types.content.get('Mu');
Any = types.content.get('Any');
Routine = types.content.get('Routine');
ContainerDescriptor = types.content.get('ContainerDescriptor');

defaultContainerDescriptor = ContainerDescriptor._STable.REPR.allocate(ContainerDescriptor._STable);
Expand All @@ -43,8 +44,31 @@ op.p6typecheckrv = function(rv, routine, bypassType) {
return rv;
};

op.p6decontrv = function(rountine, cont) {
// STUB
function isRWScalar(check) {
if (check._STable === Scalar._STable && !check.typeObject_) {
let desc = check.$$getattr(Scalar, '$!descriptor');
if (desc === Null) {
return false;
}
return desc.$$getattr_i(ContainerDescriptor, '$!rw') !== 0;
}
return false;
}

op.p6decontrv = function(routine, cont) {
if (isRWScalar(cont)) {
let isRW = routine.$$getattr_i(Routine, '$!rw');
if (isRW === 0) {
let roCont = Scalar._STable.REPR.allocate(Scalar._STable);
roCont.$$bindattr(Scalar, '$!value', cont.$$decont(null));
return roCont;
}
} else if (cont._STable && cont._STable.REPR instanceof nqp.NativeRef) {
let isRW = routine.$$getattr_i(Routine, '$!rw');
if (isRW === 0) {
return cont.$$decont();
}
}
return cont;
};

Expand Down

0 comments on commit 631468e

Please sign in to comment.