Skip to content

Commit b5576f2

Browse files
committed
Perlito5 - js3 - use fetchsize() method
1 parent a185d00 commit b5576f2

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

perlito5.pl

Lines changed: 7 additions & 7 deletions
Large diffs are not rendered by default.

src5/lib/Perlito5/Javascript3/Emitter.pm

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ package Perlito5::AST::Var;
948948
# $s = $s . ' || (' . $s . ' = new p5Array([]))'; # init
949949
# $s = 'p5pkg[' . $s . ', "' . $self->{namespace} . '"]["' . $table->{$sigil} . $str_name . '"]';
950950
# if ( $self->{sigil} eq '@' && $wantarray eq 'scalar' ) {
951-
# $s .= '._array_.length';
951+
# $s .= '.FETCHSIZE()';
952952
# }
953953
# }
954954
# elsif ($sigil eq '%') {
@@ -957,20 +957,20 @@ package Perlito5::AST::Var;
957957
# }
958958

959959
# if ($self->{sigil} eq '$#') {
960-
# return '(' . $s . '._array_.length - 1)';
960+
# return '(' . $s . '.FETCHSIZE() - 1)';
961961
# }
962962
# return $s;
963963
}
964964
}
965965

966966
if ( $self->{sigil} eq '@' ) {
967967
if ( $wantarray eq 'scalar' ) {
968-
return $self->emit_javascript3($level, 'list') . '._array_.length';
968+
return $self->emit_javascript3($level, 'list') . '.FETCHSIZE()';
969969
}
970970
if ( $wantarray eq 'runtime' ) {
971971
return '(p5want'
972972
. ' ? ' . $self->emit_javascript3($level, 'list')
973-
. ' : ' . $self->emit_javascript3($level, 'list') . '._array_.length'
973+
. ' : ' . $self->emit_javascript3($level, 'list') . '.FETCHSIZE()'
974974
. ')';
975975
}
976976
}
@@ -987,7 +987,7 @@ package Perlito5::AST::Var;
987987
my $s = 'p5pkg["' . ($self->{namespace} || $decl->{namespace}) . '"]["' . $table->{$sigil} . $str_name . '"]';
988988

989989
if ($self->{sigil} eq '$#') {
990-
return '(' . $s . '._array_.length - 1)';
990+
return '(' . $s . '.FETCHSIZE() - 1)';
991991
}
992992
return $s;
993993
}
@@ -999,7 +999,7 @@ package Perlito5::AST::Var;
999999
{
10001000
# this is an undeclared global
10011001
if ($self->{sigil} eq '$#') {
1002-
return '(p5global("@", "' . $self->{namespace} . '", "' . $str_name . '")._array_.length - 1)';
1002+
return '(p5global("@", "' . $self->{namespace} . '", "' . $str_name . '").FETCHSIZE() - 1)';
10031003
}
10041004
return 'p5global("' . $self->{sigil} . '", "' . $self->{namespace} . '", "' . $str_name . '")';
10051005
}
@@ -1012,7 +1012,7 @@ package Perlito5::AST::Var;
10121012
}
10131013

10141014
if ($self->{sigil} eq '$#') {
1015-
return '(' . $ns . $table->{'@'} . $str_name . '._array_.length - 1)';
1015+
return '(' . $ns . $table->{'@'} . $str_name . '.FETCHSIZE() - 1)';
10161016
}
10171017

10181018
$ns . $table->{$self->{sigil}} . $str_name
@@ -1367,7 +1367,7 @@ package Perlito5::AST::Apply;
13671367
my $self = $_[0];
13681368
my $level = $_[1];
13691369
my $arg = $self->{arguments}->[0];
1370-
'(' . Perlito5::Javascript3::emit_javascript3_autovivify( $arg, $level, 'array' ) . '.aderef()._array_.length - 1)';
1370+
'(' . Perlito5::Javascript3::emit_javascript3_autovivify( $arg, $level, 'array' ) . '.aderef().FETCHSIZE() - 1)';
13711371
},
13721372
'prefix:<%>' => sub {
13731373
my $self = $_[0];

src5/lib/Perlito5/Javascript3/Runtime.pm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,9 @@ function p5Array(o) {
418418
};
419419
420420
// operations that can be tie()
421+
this.FETCHSIZE = function() {
422+
return this._array_.length;
423+
};
421424
this.PUSH = function(v) {
422425
for(var i = 0; i < v._array_.length; i++) {
423426
this._array_.push(v._array_[i] instanceof p5Scalar ? v._array_[i]._v_ : v._array_[i]);

0 commit comments

Comments
 (0)