@@ -18,25 +18,11 @@ var NQPArray = require('./array.js');
18
18
exports . CodeRef = CodeRef ;
19
19
20
20
op . atpos = function ( array , index ) {
21
- if ( array instanceof Array ) {
22
- if ( index < 0 ) {
23
- index = array . length + index ;
24
- }
25
- return array [ index ] ;
26
- } else {
27
- return array . $$atpos ( index ) ;
28
- }
21
+ return array . $$atpos ( index ) ;
29
22
} ;
30
23
31
24
op . bindpos = function ( array , index , value ) {
32
- if ( array instanceof Array ) {
33
- if ( index < 0 ) {
34
- index = array . length + index ;
35
- }
36
- return ( array [ index ] = value ) ;
37
- } else {
38
- return array . $$bindpos ( index , value ) ;
39
- }
25
+ return array . $$bindpos ( index , value ) ;
40
26
} ;
41
27
42
28
op . getcomp = function ( lang ) {
@@ -93,10 +79,10 @@ exports.radix_helper = radix_helper;
93
79
op . radix = function ( radix , str , zpos , flags ) {
94
80
var extracted = radix_helper ( radix , str , zpos , flags ) ;
95
81
if ( extracted == null ) {
96
- return [ 0 , 1 , - 1 ] ;
82
+ return new NQPArray ( [ 0 , 1 , - 1 ] ) ;
97
83
}
98
84
var pow = Math . pow ( radix , extracted . power ) ;
99
- return [ parseInt ( extracted . number , radix ) , pow , extracted . offset ] ;
85
+ return new NQPArray ( [ parseInt ( extracted . number , radix ) , pow , extracted . offset ] ) ;
100
86
} ;
101
87
102
88
function Iter ( array ) {
@@ -155,8 +141,6 @@ IterPair.prototype.value = function(ctx, named) {
155
141
op . iterator = function ( obj ) {
156
142
if ( obj instanceof NQPArray ) {
157
143
return new Iter ( obj . array ) ;
158
- } else if ( obj instanceof Array ) {
159
- return new Iter ( obj ) ;
160
144
} else if ( obj instanceof Hash ) {
161
145
return new HashIter ( obj ) ;
162
146
} else if ( obj instanceof LexPadHack ) {
@@ -339,7 +323,7 @@ op.istype = function(obj, type) {
339
323
}
340
324
341
325
// HACK
342
- if ( obj instanceof Array || obj instanceof NQPArray ) {
326
+ if ( obj instanceof NQPArray ) {
343
327
if ( hll . hllConfigs . nqp && type == hll . hllConfigs . nqp . content . get ( 'list' ) ) {
344
328
return 1 ;
345
329
} else {
@@ -424,8 +408,6 @@ op.composetype = function(obj, reprinfo) {
424
408
op . clone = function ( obj ) {
425
409
if ( obj . $$clone ) {
426
410
return obj . $$clone ( ) ;
427
- } else if ( obj instanceof Array ) {
428
- return obj . slice ( ) ;
429
411
} else {
430
412
// STUB
431
413
console . log ( 'NYI cloning' , obj ) ;
@@ -511,21 +493,12 @@ op.unbox_s = function(obj) {
511
493
} ;
512
494
513
495
op . elems = function ( obj ) {
514
- if ( obj instanceof Array ) {
515
- return obj . length ;
516
- } else {
517
- return obj . $$elems ( ) ;
518
- }
496
+ return obj . $$elems ( ) ;
519
497
} ;
520
498
521
499
op . setelems = function ( obj , elems ) {
522
- if ( obj instanceof Array ) {
523
- obj . length = elems ;
524
- return obj ;
525
- } else {
526
- obj . $$setelems ( elems ) ;
527
- return obj ;
528
- }
500
+ obj . $$setelems ( elems ) ;
501
+ return obj ;
529
502
} ;
530
503
531
504
op . markcodestatic = function ( code ) {
@@ -915,57 +888,27 @@ op.getcodecuid = function(codeRef) {
915
888
} ;
916
889
917
890
op . numdimensions = function ( array ) {
918
- if ( array instanceof Array ) {
919
- return 1 ;
920
- } else {
921
- return array . $$numdimensions ( ) ;
922
- }
891
+ return array . $$numdimensions ( ) ;
923
892
} ;
924
893
925
894
op . dimensions = function ( array ) {
926
- if ( array instanceof Array ) {
927
- return [ array . length ] ;
928
- } else {
929
- return array . $$dimensions ( ) ;
930
- }
895
+ return array . $$dimensions ( ) ;
931
896
} ;
932
897
933
898
op . setdimensions = function ( array , dimensions ) {
934
- if ( array instanceof Array ) {
935
- if ( dimensions . length != 1 ) {
936
- throw new NQPException ( "A dynamic array can only have a single dimension" ) ;
937
- } else {
938
- array . length = dimensions [ 0 ] ;
939
- }
940
- } else {
941
- array . $$setdimensions ( dimensions ) ;
942
- }
899
+ array . $$setdimensions ( dimensions ) ;
943
900
return dimensions ;
944
901
} ;
945
902
946
903
// TODO optimize
947
904
948
905
[ '_n' , '_s' , '_i' , '' ] . forEach ( function ( type ) {
949
906
op [ 'atposnd' + type ] = function ( array , idx ) {
950
- if ( array instanceof Array ) {
951
- if ( idx . length != 1 ) {
952
- throw new NQPException ( "A dynamic array can only be indexed with a single dimension" ) ;
953
- }
954
- return array [ idx [ 0 ] ] ;
955
- } else {
956
- return array [ '$$atposnd' + type ] ( idx ) ;
957
- }
907
+ return array [ '$$atposnd' + type ] ( idx ) ;
958
908
} ;
959
909
960
910
op [ 'bindposnd' + type ] = function ( array , idx , value ) {
961
- if ( array instanceof Array ) {
962
- if ( idx . length != 1 ) {
963
- throw new NQPException ( "A dynamic array can only be indexed with a single dimension" ) ;
964
- }
965
- return ( array [ idx [ 0 ] ] = value ) ;
966
- } else {
967
- return array [ '$$bindposnd' + type ] ( idx , value ) ;
968
- }
911
+ return array [ '$$bindposnd' + type ] ( idx , value ) ;
969
912
} ;
970
913
971
914
op [ 'atpos2d' + type ] = function ( array , x , y ) {
0 commit comments