Skip to content

Commit bb7b097

Browse files
committed
[js] Implement nqp::{shift,unshift}_{s,i}. Remove legacy raw array support.
1 parent afa5dbf commit bb7b097

File tree

2 files changed

+8
-32
lines changed

2 files changed

+8
-32
lines changed

src/vm/js/Operations.nqp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -408,11 +408,14 @@ class QAST::OperationsJS {
408408

409409
if $type != $T_OBJ {
410410
add_simple_op('bindpos' ~ $suffix, $type, [$T_OBJ, $T_INT, $type], sub ($list, $index, $value) {"$list.\$\$bindpos($index, $value)"}, :sideffects);
411-
add_simple_op('pop' ~ $suffix, $type, [$T_OBJ], sub ($array) {"$array.\$\$pop()"}, :sideffects);
412-
add_simple_op('push' ~ $suffix, $type, [$T_OBJ, $type], sub ($array, $elem) {"$array.\$\$push($elem)"}, :sideffects);
413411
add_simple_op('atpos' ~ $suffix, $type, [$T_OBJ, $T_INT], sub ($list, $index) {"$list.\$\$atpos$suffix($index)"});
414412

415413
}
414+
415+
add_simple_op('pop' ~ $suffix, $type, [$T_OBJ], sub ($array) {"$array.\$\$pop()"}, :sideffects);
416+
add_simple_op('push' ~ $suffix, $type, [$T_OBJ, $type], sub ($array, $elem) {"$array.\$\$push($elem)"}, :sideffects);
417+
add_simple_op('unshift' ~ $suffix, $type, [$T_OBJ, $type], sub ($array, $elem) {"$array.\$\$unshift($elem)"}, :sideffects);
418+
add_simple_op('shift' ~ $suffix, $type, [$T_OBJ], sub ($array) {"$array.\$\$shift()"}, :sideffects);
416419

417420

418421
add_simple_op('atposnd' ~ $suffix, $type, [$T_OBJ, $T_OBJ]);
@@ -723,12 +726,6 @@ class QAST::OperationsJS {
723726
Chunk.new($T_OBJ, "new nqp.CurLexpad(\{{nqp::join(',', @get)}\}, \{{nqp::join(',', @set)}\})", [], :$node);
724727
});
725728

726-
727-
add_simple_op('shift', $T_OBJ, [$T_OBJ], :sideffects);
728-
add_simple_op('unshift', $T_OBJ, [$T_OBJ, $T_OBJ], :sideffects);
729-
add_simple_op('pop', $T_OBJ, [$T_OBJ], :sideffects);
730-
add_simple_op('push', $T_OBJ, [$T_OBJ, $T_OBJ], :sideffects);
731-
732729
add_simple_op('splice', $T_OBJ, [$T_OBJ, $T_OBJ, $T_INT, $T_INT], :sideffects);
733730

734731
add_simple_op('setelems', $T_OBJ, [$T_OBJ, $T_INT], :sideffects);
@@ -990,7 +987,7 @@ class QAST::OperationsJS {
990987
my $arity := @operands[1].arity || 1;
991988
while $arity > 0 {
992989
my $iterval := $*BLOCK.add_tmp();
993-
@body_args.push(Chunk.new($T_OBJ, $iterval, ["$iterval = $iterator.shift();\n"]));
990+
@body_args.push(Chunk.new($T_OBJ, $iterval, ["$iterval = $iterator.\$\$shift();\n"]));
994991
$arity := $arity - 1;
995992
}
996993

src/vm/js/nqp-runtime/core.js

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function Iter(array) {
9393
this.idx = 0;
9494
}
9595

96-
Iter.prototype.shift = function() {
96+
Iter.prototype.$$shift = function() {
9797
return this.array[this.idx++];
9898
};
9999

@@ -108,7 +108,7 @@ function HashIter(hash) {
108108
this.idx = 0;
109109
}
110110

111-
HashIter.prototype.shift = function() {
111+
HashIter.prototype.$$shift = function() {
112112
return new IterPair(this.hash, this.keys[this.idx++]);
113113
};
114114

@@ -606,27 +606,6 @@ op.setpayload = function(exception, payload) {
606606
return (exception.payload = payload);
607607
};
608608

609-
op.unshift = function(target, value) {
610-
if (target.$$unshift) return target.$$unshift(value);
611-
target.unshift(value);
612-
return value;
613-
};
614-
615-
op.pop = function(target, value) {
616-
if (target.$$pop) return target.$$pop(value);
617-
return target.pop(value);
618-
};
619-
620-
op.push = function(target, value) {
621-
if (target.$$push) return target.$$push(value);
622-
return target.push(value);
623-
};
624-
625-
op.shift = function(target, value) {
626-
if (target.$$shift) return target.$$shift(value);
627-
return target.shift(value);
628-
};
629-
630609
op.isnum = function(value) {
631610
return (typeof value == 'number') ? 1 : 0;
632611
};

0 commit comments

Comments
 (0)