Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Perlito5 - use scalar() instead of .elems()

  • Loading branch information...
commit 399a3d2ac88e9e997db1a016a583b0871d1d6f33 1 parent 7c8e06c
@fglock authored
View
4 TODO-perlito5
@@ -22,6 +22,8 @@ TODO list for Perlito5
-- remove Perl6 "match" special variables: $<..>, $/
+-- remove the dependency on "pairs()" for macros
+
* libraries
@@ -32,6 +34,8 @@ TODO list for Perlito5
-- remove "Match" overloads
+-- remove *all* runtime (everything should work natively)
+
* Javascript backend
View
741 html/perlito5.js
607 additions, 134 deletions not shown
View
30 lib5/Perlito5/Expression.pm
@@ -57,14 +57,14 @@ package GLOBAL;
return scalar ($o)
};
((my $stmts) = $o->stmts());
- if (((!((defined($stmts)))) || (((scalar( @{$stmts} )) == 0)))) {
+ if (((!((defined($stmts)))) || (((scalar( @{($stmts)} )) == 0)))) {
return scalar (Lit::Hash->new(('hash1' => do {
(my $List_a = bless [], 'ARRAY');
(my $List_v = bless [], 'ARRAY');
$List_a
})))
};
- if (((scalar( @{$stmts} )) != 1)) {
+ if (((scalar( @{($stmts)} )) != 1)) {
return scalar ($o)
};
((my $stmt) = $stmts->[0]);
@@ -157,7 +157,7 @@ package GLOBAL;
($v = Lookup->new(('obj' => undef()), ('index_exp' => $v->[2])));
return scalar ($v)
};
- if ((Main::isa(($v->[1]), 'Array') && (((scalar( @{($v->[1])} )) == 2)))) {
+ if (((Main::isa($v->[1], 'Array') && (scalar( @{$v->[1]} ) == 2)))) {
($v = Apply->new(('code' => 'pair'), ('arguments' => $v->[1]), ('namespace' => '')));
return scalar ($v)
};
@@ -259,7 +259,7 @@ package GLOBAL;
else {
if ((Perlito5::Precedence::is_assoc_type('list', $last_op->[1]))) {
(my $arg);
- if (((scalar( @{$num_stack} ) < 2))) {
+ if (((scalar( @{($num_stack)} ) < 2))) {
((my $v2) = pop_term($num_stack));
if (((Main::isa($v2, 'Apply')) && (($v2->code() eq (('list:<' . $last_op->[1] . '>')))))) {
push( @{($num_stack)}, Apply->new(('namespace' => $v2->namespace()), ('code' => $v2->code()), ('arguments' => do {
@@ -311,7 +311,7 @@ package GLOBAL;
}
else {
if ((Perlito5::Precedence::is_assoc_type('chain', $last_op->[1]))) {
- if (((scalar( @{$num_stack} ) < 2))) {
+ if (((scalar( @{($num_stack)} ) < 2))) {
die(('Missing value after operator ' . $last_op->[1]))
};
((my $v2) = pop_term($num_stack));
@@ -326,7 +326,7 @@ package GLOBAL;
}
else {
if ((($last_op->[0] eq 'ternary'))) {
- if (((scalar( @{$num_stack} ) < 2))) {
+ if (((scalar( @{($num_stack)} ) < 2))) {
die(('Missing value after ternary operator'))
};
((my $v2) = pop_term($num_stack));
@@ -340,7 +340,7 @@ package GLOBAL;
})) )
}
else {
- if (((scalar( @{$num_stack} ) < 2))) {
+ if (((scalar( @{($num_stack)} ) < 2))) {
die(('missing value after operator ' . chr(39) . $last_op->[1] . (chr(39))))
};
((my $v2) = pop_term($num_stack));
@@ -1534,7 +1534,7 @@ package GLOBAL;
((my $get_token) = sub {
my $List__ = bless \@_, "ARRAY";
(my $v);
- if ((scalar( @{$lexer_stack} ))) {
+ if ((scalar( @{($lexer_stack)} ))) {
($v = pop( @{($lexer_stack)} ));
if (((($is_first_token && (($v->[0] eq 'op'))) && !((Perlito5::Precedence::is_fixity_type('prefix', $v->[1])))))) {
($v->[0] = 'end')
@@ -1608,7 +1608,7 @@ package GLOBAL;
$List_a
})));
((my $res) = $prec->precedence_parse());
- if (((scalar( @{$res} ) == 0))) {
+ if (((scalar( @{($res)} ) == 0))) {
return scalar (Perlito5::Match->new(('str' => $str), ('from' => $pos), ('to' => $last_pos), ('bool' => 1), ('capture' => do {
(my $Hash_a = bless {}, 'HASH');
($Hash_a->{'exp'} = '*undef*');
@@ -1618,12 +1618,12 @@ package GLOBAL;
})))
};
(my $block);
- if (((scalar( @{$res} ) > 1))) {
+ if (((scalar( @{($res)} ) > 1))) {
($block = pop( @{($res)} ));
($block = Lit::Block->new(('stmts' => $block->[2]), ('sig' => $block->[3])))
};
((my $result) = pop_term($res));
- if (((scalar( @{$res} ) > 0))) {
+ if (((scalar( @{($res)} ) > 0))) {
($block = pop( @{($res)} ));
($block = Lit::Block->new(('stmts' => $block->[2]), ('sig' => $block->[3])))
};
@@ -1727,7 +1727,7 @@ package GLOBAL;
((my $get_token) = sub {
my $List__ = bless \@_, "ARRAY";
(my $v);
- if ((scalar( @{$lexer_stack} ))) {
+ if ((scalar( @{($lexer_stack)} ))) {
($v = pop( @{($lexer_stack)} ))
}
else {
@@ -1778,16 +1778,16 @@ package GLOBAL;
$List_a
})));
((my $res) = $prec->precedence_parse());
- if (((scalar( @{$res} ) == 0))) {
+ if (((scalar( @{($res)} ) == 0))) {
return scalar (Perlito5::Match->new(('bool' => 0)))
};
(my $block);
- if (((scalar( @{$res} ) > 1))) {
+ if (((scalar( @{($res)} ) > 1))) {
($block = pop( @{($res)} ));
($block = Lit::Block->new(('stmts' => $block->[2]), ('sig' => $block->[3])))
};
((my $result) = pop_term($res));
- if (((scalar( @{$res} ) > 0))) {
+ if (((scalar( @{($res)} ) > 0))) {
($block = pop( @{($res)} ));
if ((!((Main::isa($block, 'Lit::Block'))))) {
($block = Lit::Block->new(('stmts' => $block->[2]), ('sig' => $block->[3])))
View
2  lib5/Perlito5/Javascript/Emitter.pm
@@ -515,7 +515,6 @@ package GLOBAL;
($Hash_a->{'keys'} = 'keys');
($Hash_a->{'values'} = 'values');
($Hash_a->{'pairs'} = 'pairs');
- ($Hash_a->{'elems'} = 'elems');
($Hash_a->{'say'} = 'say');
($Hash_a->{'chars'} = 'chars');
$Hash_a
@@ -619,6 +618,7 @@ package GLOBAL;
($Hash_a->{'bless'} = 1);
($Hash_a->{'print'} = 1);
($Hash_a->{'warn'} = 1);
+ ($Hash_a->{'scalar'} = 1);
$Hash_a
});
sub emit_javascript {
View
16 lib5/Perlito5/Javascript/Runtime.js
@@ -170,12 +170,12 @@ chr = function(o) {
return String.fromCharCode(num(o));
};
-elems = function(o) {
+scalar = function(o) {
if (o == null) {
return 1;
};
- if (typeof o.elems === 'function') {
- return o.elems();
+ if (typeof o.scalar === 'function') {
+ return o.scalar();
}
if (typeof o === 'object' && (o instanceof Array)) {
return o.length;
@@ -322,16 +322,6 @@ isa = function(o, s) {
return false;
};
-scalar = function(o) {
- if (o == null) {
- return o;
- }
- if (typeof o.scalar === 'function') {
- return o.scalar();
- }
- return o;
-};
-
string = function(o) {
if (o == null) {
return "";
View
14 lib5/Perlito5/Macro.pm
@@ -68,11 +68,12 @@ package GLOBAL;
push( @{$List_a}, Apply->new(('arguments' => do {
(my $List_a = bless [], 'ARRAY');
(my $List_v = bless [], 'ARRAY');
- push( @{$List_a}, Call->new(('arguments' => do {
+ push( @{$List_a}, Apply->new(('arguments' => do {
(my $List_a = bless [], 'ARRAY');
(my $List_v = bless [], 'ARRAY');
+ push( @{$List_a}, Var->new(('name' => 'v'), ('namespace' => ''), ('sigil' => chr(64)), ('twigil' => '')) );
$List_a
-}), ('hyper' => ''), ('invocant' => Var->new(('name' => 'v'), ('namespace' => ''), ('sigil' => chr(64)), ('twigil' => ''))), ('method' => 'elems')) );
+}), ('code' => 'scalar'), ('namespace' => '')) );
push( @{$List_a}, Val::Int->new(('int' => 1)) );
$List_a
}), ('code' => 'infix:<->'), ('namespace' => '')) );
@@ -220,7 +221,12 @@ package GLOBAL;
(my $List_a = bless [], 'ARRAY');
(my $List_v = bless [], 'ARRAY');
push( @{$List_a}, Var->new(('name' => '_i'), ('namespace' => ''), ('sigil' => chr(36)), ('twigil' => '')) );
- push( @{$List_a}, Call->new(('hyper' => ''), ('invocant' => Var->new(('name' => '_a'), ('namespace' => ''), ('sigil' => chr(64)), ('twigil' => ''))), ('method' => 'elems')) );
+ push( @{$List_a}, Apply->new(('arguments' => do {
+ (my $List_a = bless [], 'ARRAY');
+ (my $List_v = bless [], 'ARRAY');
+ push( @{$List_a}, Var->new(('name' => '_a'), ('namespace' => ''), ('sigil' => chr(64)), ('twigil' => '')) );
+ $List_a
+}), ('code' => 'scalar'), ('namespace' => '')) );
$List_a
}), ('code' => 'infix:<<>'), ('namespace' => '')) );
$List_a
@@ -308,7 +314,7 @@ package GLOBAL;
$List_a
})
};
- if (((scalar( @{$block} ) == 1))) {
+ if (((scalar( @{($block)} ) == 1))) {
((my $stmt) = $block->[0]);
if (((Main::isa($stmt, 'Apply') && ($stmt->code() eq 'circumfix:<( )>')))) {
((my $args) = $stmt->arguments());
View
10 lib5/Perlito5/Precedence.pm
@@ -469,7 +469,7 @@ package GLOBAL;
else {
if (((($Operator->{'postfix'})->{$token->[1]} && is_term($last)) && (($Allow_space_before->{'postfix'}->{$token->[1]} || !(($last_has_space)))))) {
((my $pr) = $Precedence->{$token->[1]});
- for ( ; (scalar( @{$op_stack} ) && (($pr <= $Precedence->{($op_stack->[0])->[1]}))); ) {
+ for ( ; (scalar( @{($op_stack)} ) && (($pr <= $Precedence->{($op_stack->[0])->[1]}))); ) {
$reduce->($op_stack, $num_stack)
};
if ((($token->[0]) ne 'postfix_or_term')) {
@@ -479,7 +479,7 @@ package GLOBAL;
}
else {
if ((((($token->[1] eq 'block')) && is_term($last)) && $last_has_space)) {
- for ( ; scalar( @{$op_stack} ); ) {
+ for ( ; (scalar( @{($op_stack)} )); ) {
$reduce->($op_stack, $num_stack)
};
push( @{($num_stack)}, $token );
@@ -501,12 +501,12 @@ package GLOBAL;
if (($Precedence->{$token->[1]})) {
((my $pr) = $Precedence->{$token->[1]});
if (($Assoc->{'right'}->{$token->[1]})) {
- for ( ; (scalar( @{$op_stack} ) && (($pr < $Precedence->{($op_stack->[0])->[1]}))); ) {
+ for ( ; ((scalar( @{($op_stack)} ) && (($pr < $Precedence->{($op_stack->[0])->[1]})))); ) {
$reduce->($op_stack, $num_stack)
}
}
else {
- for ( ; (scalar( @{$op_stack} ) && (($pr <= $Precedence->{($op_stack->[0])->[1]}))); ) {
+ for ( ; ((scalar( @{($op_stack)} ) && (($pr <= $Precedence->{($op_stack->[0])->[1]})))); ) {
$reduce->($op_stack, $num_stack)
}
};
@@ -538,7 +538,7 @@ package GLOBAL;
if (((defined($token) && (($token->[0] ne 'end'))))) {
die(('Unexpected end token: '), $token)
};
- for ( ; scalar( @{$op_stack} ); ) {
+ for ( ; (scalar( @{($op_stack)} )); ) {
$reduce->($op_stack, $num_stack)
};
($End_token = $last_end_token);
View
30 src5/lib/Perlito5/Expression.pm
@@ -32,11 +32,11 @@ class Perlito5::Expression {
return $o
}
my $stmts = $o->stmts;
- if (!(defined $stmts)) || (($stmts->elems) == 0) {
+ if (!(defined $stmts)) || ((scalar(@$stmts)) == 0) {
# say "# no contents -- empty hash";
return Lit::Hash->new(hash1 => [])
}
- if ($stmts->elems) != 1 {
+ if (scalar(@$stmts)) != 1 {
# say "# more statements -- not hash";
return $o
}
@@ -150,7 +150,7 @@ class Perlito5::Expression {
# say "# ", $v->perl;
return $v;
}
- if ($v->[1])->isa('Array') && ((($v->[1])->elems) == 2) {
+ if ($v->[1]->isa('Array') && scalar($v->[1]) == 2) {
# say "# old style Pair ", $v->perl;
# old style Pair - wrap it into a subroutine for now
$v = Apply->new( code => 'pair', arguments => $v->[1], namespace => '' );
@@ -260,7 +260,7 @@ class Perlito5::Expression {
}
elsif (Perlito5::Precedence::is_assoc_type('list', $last_op->[1])) {
my $arg;
- if ($num_stack->elems < 2) {
+ if (scalar(@$num_stack) < 2) {
my $v2 = pop_term($num_stack);
if ($v2->isa('Apply')) && ($v2->code eq ('list:<' . $last_op->[1] . '>')) {
push @$num_stack,
@@ -305,7 +305,7 @@ class Perlito5::Expression {
);
}
elsif (Perlito5::Precedence::is_assoc_type('chain', $last_op->[1])) {
- if ($num_stack->elems < 2) {
+ if (scalar(@$num_stack) < 2) {
die("Missing value after operator " . $last_op->[1]);
}
my $v2 = pop_term($num_stack);
@@ -335,7 +335,7 @@ class Perlito5::Expression {
);
}
elsif ($last_op->[0] eq 'ternary') {
- if ( $num_stack->elems < 2 ) {
+ if ( scalar(@$num_stack) < 2 ) {
die "Missing value after ternary operator";
}
my $v2 = pop_term($num_stack);
@@ -347,7 +347,7 @@ class Perlito5::Expression {
);
}
else {
- if ( $num_stack->elems < 2 ) {
+ if ( scalar(@$num_stack) < 2 ) {
die("missing value after operator '" . $last_op->[1] . "'");
}
my $v2 = pop_term($num_stack);
@@ -520,7 +520,7 @@ class Perlito5::Expression {
my $last_token_was_space = 1;
my $get_token = sub {
my $v;
- if ($lexer_stack->elems()) {
+ if (scalar(@$lexer_stack)) {
$v = pop @$lexer_stack;
if ( $is_first_token
&& ($v->[0] eq 'op')
@@ -577,7 +577,7 @@ class Perlito5::Expression {
end_token => [ 'and', 'or', ':', ']', ')', '}', ';', 'if', 'else', 'elsif', 'unless', 'when', 'for', 'while', 'loop' ] );
my $res = $prec->precedence_parse;
# say "# list_lexer return: ", $res->perl;
- if ($res->elems == 0) {
+ if (scalar(@$res) == 0) {
return Perlito5::Match->new(
'str' => $str, 'from' => $pos, 'to' => $last_pos, 'bool' => 1,
capture => {
@@ -587,13 +587,13 @@ class Perlito5::Expression {
}
# if the expression terminates in a block, the block was pushed to num_stack
my $block;
- if ($res->elems > 1) {
+ if (scalar(@$res) > 1) {
$block = pop @$res; # pop_term($res);
$block = Lit::Block->new( stmts => $block->[2], sig => $block->[3] );
# say "# list exp terminated with a block: ", $block->perl;
}
my $result = pop_term($res);
- if ($res->elems > 0) {
+ if (scalar(@$res) > 0) {
$block = pop @$res; # pop_term($res);
$block = Lit::Block->new( stmts => $block->[2], sig => $block->[3] );
# say "# list exp terminated with a block (2): ", $block->perl;
@@ -681,7 +681,7 @@ class Perlito5::Expression {
my $terminated = 0;
my $get_token = sub {
my $v;
- if ($lexer_stack->elems()) {
+ if (scalar(@$lexer_stack)) {
$v = pop @$lexer_stack;
}
else {
@@ -716,19 +716,19 @@ class Perlito5::Expression {
end_token => [ ']', ')', '}', ';', 'if', 'else', 'elsif', 'unless', 'when', 'for', 'while', 'loop' ] );
my $res = $prec->precedence_parse;
# say "# exp terminated";
- if ($res->elems == 0) {
+ if (scalar(@$res) == 0) {
# say "# exp terminated with false";
return Perlito5::Match->new(bool => 0);
}
# if the expression terminates in a block, the block was pushed to num_stack
my $block;
- if ($res->elems > 1) {
+ if (scalar(@$res) > 1) {
$block = pop @$res; # pop_term($res);
$block = Lit::Block->new( stmts => $block->[2], sig => $block->[3] );
# say "# exp terminated with a block: ", $block->perl;
}
my $result = pop_term($res);
- if ($res->elems > 0) {
+ if (scalar(@$res) > 0) {
$block = pop @$res; # pop_term($res);
if (!($block->isa('Lit::Block'))) {
$block = Lit::Block->new( stmts => $block->[2], sig => $block->[3] );
View
6 src5/lib/Perlito5/Javascript/Emitter.pm
@@ -234,14 +234,14 @@ class CompUnit {
# process 'package' statements
my @body;
my $i = 0;
- while ( $i <= @.body->elems ) {
+ while ( $i <= scalar @.body ) {
my $stmt = @.body->[$i];
if ( $stmt->isa( 'Apply' ) && $stmt->code eq 'package' ) {
# found an inner package
my $name = $stmt->namespace;
my @stmts;
$i++;
- while ( $i <= @.body->elems
+ while ( $i <= scalar( @.body )
&& !( @.body->[$i]->isa( 'Apply' ) && @.body->[$i]->code eq 'package' )
)
{
@@ -479,7 +479,6 @@ class Call {
'keys' => 'keys',
'values' => 'values',
'pairs' => 'pairs',
- 'elems' => 'elems',
'say' => 'say',
'chars' => 'chars',
);
@@ -607,6 +606,7 @@ class Apply {
'bless' => 1,
'print' => 1,
'warn' => 1,
+ 'scalar' => 1,
);
sub emit_javascript { $_[0]->emit_javascript_indented(0) }
View
16 src5/lib/Perlito5/Javascript/Runtime.js
@@ -170,12 +170,12 @@ chr = function(o) {
return String.fromCharCode(num(o));
};
-elems = function(o) {
+scalar = function(o) {
if (o == null) {
return 1;
};
- if (typeof o.elems === 'function') {
- return o.elems();
+ if (typeof o.scalar === 'function') {
+ return o.scalar();
}
if (typeof o === 'object' && (o instanceof Array)) {
return o.length;
@@ -322,16 +322,6 @@ isa = function(o, s) {
return false;
};
-scalar = function(o) {
- if (o == null) {
- return o;
- }
- if (typeof o.scalar === 'function') {
- return o.scalar();
- }
- return o;
-};
-
string = function(o) {
if (o == null) {
return "";
View
28 src5/lib/Perlito5/Macro.pm
@@ -24,7 +24,7 @@ class Lit::Array {
$needs_interpolation = 1;
}
}
- if ($needs_interpolation && @items->elems() == 1) {
+ if ($needs_interpolation && scalar(@items) == 1) {
return @items[0];
}
my @s;
@@ -58,7 +58,20 @@ class Lit::Array {
'cond' => Apply->new(
'arguments' => [
Val::Int->new('int' => 0),
- Apply->new('arguments' => [Apply->new('arguments' => [Call->new('arguments' => [], 'hyper' => '', 'invocant' => Var->new('name' => 'v', 'namespace' => '', 'sigil' => '@', 'twigil' => ''), 'method' => 'elems'), Val::Int->new('int' => 1)], 'code' => 'infix:<->', 'namespace' => '')], 'code' => 'circumfix:<( )>', 'namespace' => '')
+ Apply->new(
+ 'arguments' => [
+ Apply->new(
+ 'arguments' => [
+ Apply->new(
+ 'arguments' => [
+ Var->new('name' => 'v', 'namespace' => '', 'sigil' => '@', 'twigil' => '')],
+ 'code' => 'scalar',
+ 'namespace' => ''),
+ Val::Int->new('int' => 1)
+ ],
+ 'code' => 'infix:<->', 'namespace' => '')],
+ 'code' => 'circumfix:<( )>',
+ 'namespace' => '')
],
'code' => 'infix:<..>',
'namespace' => ''
@@ -208,7 +221,14 @@ class Lit::Hash {
Apply->new( 'arguments' => [ Var->new( 'name' => '_i', 'namespace' => '', 'sigil' => '$', 'twigil' => '' ), Apply->new( 'arguments' => [ Var->new( 'name' => '_i', 'namespace' => '', 'sigil' => '$', 'twigil' => '' ), Val::Int->new( 'int' => 2 ) ], 'code' => 'infix:<+>', 'namespace' => '' ) ], 'code' => 'infix:<=>', 'namespace' => '' )
]
),
- 'cond' => Apply->new( 'arguments' => [ Apply->new( 'arguments' => [ Var->new( 'name' => '_i', 'namespace' => '', 'sigil' => '$', 'twigil' => '' ), Call->new( 'hyper' => '', 'invocant' => Var->new( 'name' => '_a', 'namespace' => '', 'sigil' => '@', 'twigil' => '' ), 'method' => 'elems' ) ], 'code' => 'infix:<<>', 'namespace' => '' ) ], 'code' => 'circumfix:<( )>', 'namespace' => '' )
+ 'cond' => Apply->new( 'arguments' => [
+ Apply->new( 'arguments' => [
+ Var->new( 'name' => '_i', 'namespace' => '', 'sigil' => '$', 'twigil' => '' ),
+ Apply->new(
+ 'arguments' => [Var->new( 'name' => '_a', 'namespace' => '', 'sigil' => '@', 'twigil' => '' )], 'code' => 'scalar', 'namespace' => ''
+ ) ],
+ 'code' => 'infix:<<>', 'namespace' => '' )
+ ], 'code' => 'circumfix:<( )>', 'namespace' => '' )
)
]
)
@@ -284,7 +304,7 @@ class Do {
else {
$block = [ $.block ]
}
- if ($block->elems() == 1) {
+ if (scalar(@$block) == 1) {
# optimize some code generated by the regex compiler
my $stmt = $block->[0];
if ($stmt->isa('Apply') && $stmt->code() eq 'circumfix:<( )>') {
View
10 src5/lib/Perlito5/Precedence.pm
@@ -261,7 +261,7 @@ class Perlito5::Precedence {
)
{
my $pr = $Precedence->{$token->[1]};
- while $op_stack->elems && ($pr <= $Precedence->{ ($op_stack->[0])[1] }) {
+ while scalar(@$op_stack) && ($pr <= $Precedence->{ ($op_stack->[0])[1] }) {
$reduce->($op_stack, $num_stack);
}
if ($token->[0]) ne 'postfix_or_term' {
@@ -272,7 +272,7 @@ class Perlito5::Precedence {
elsif ($token->[1] eq 'block') && is_term($last) && $last_has_space {
# a block in this position terminates the current expression
# say "# there is a block after the expression: ", $token->perl;
- while $op_stack->elems() {
+ while (scalar(@$op_stack)) {
$reduce->($op_stack, $num_stack);
}
push( @$num_stack, $token); # save the block
@@ -296,12 +296,12 @@ class Perlito5::Precedence {
elsif ($Precedence->{$token->[1]}) {
my $pr = $Precedence->{$token->[1]};
if ($Assoc->{'right'}{$token->[1]}) {
- while $op_stack->elems && ( $pr < $Precedence->{ ($op_stack->[0])[1] } ) {
+ while (scalar(@$op_stack) && ( $pr < $Precedence->{ ($op_stack->[0])[1] } )) {
$reduce->($op_stack, $num_stack);
}
}
else {
- while $op_stack->elems && ( $pr <= $Precedence->{ ($op_stack->[0])[1] } ) {
+ while (scalar(@$op_stack) && ( $pr <= $Precedence->{ ($op_stack->[0])[1] } )) {
$reduce->($op_stack, $num_stack);
}
}
@@ -330,7 +330,7 @@ class Perlito5::Precedence {
if (defined($token) && ($token->[0] ne 'end')) {
die "Unexpected end token: ",$token;
}
- while $op_stack->elems() {
+ while (scalar(@$op_stack)) {
$reduce->($op_stack, $num_stack);
}
# say "# precedence return";
View
2  t5/05-array.t
@@ -48,7 +48,7 @@ $x->[4] = 5;
print 'not ' if !defined $x->[4];
say "ok 10 - defined item";
-$x->unshift(6);
+unshift($x, 6);
print 'not ' if $x->[0] != 6;
say "ok 11 - unshift";
print 'not ' if $x->[5] != 5;
View
8 t5/05-hash.t
@@ -18,19 +18,19 @@ my %a1 = (a => 2);
if $a1{'a'} ne 2 {
print 'not '
}
-say "ok 4 - assign list to hash # {%a1->perl}";
+say "ok 4 - assign list to hash # {%a1}";
my %b1 = %a1;
if $b1{'a'} ne 2 {
print 'not '
}
-say "ok 5 - assign hash to hash # {%b1->perl}";
+say "ok 5 - assign hash to hash # {%b1}";
my $c1 = { %b1, b => 3 };
if $c1->{'a'} ne 2 || $c1->{'b'} ne 3 {
print 'not '
}
-say "ok 6 - interpolate hash in hash composer # {$c1->perl}";
+say "ok 6 - interpolate hash in hash composer "; # {$c1};
print 'not ' if defined $c1->{'c'};
say "ok 7 - undefined item";
@@ -47,5 +47,5 @@ say "ok 9 - defined item";
# if $d1[0] ne 'a' || $d1[1] != 2 || $d1[2] ne 'b' {
# print 'not '
# }
-# say "ok 7 - interpolate hash in array composer # {$d1->perl}";
+# say "ok 7 - interpolate hash in array composer # {$d1}";
Please sign in to comment.
Something went wrong with that request. Please try again.