X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FSub%2FNary.pm;h=707a2e627ee25228b9bc20432c6237014c661d3e;hb=097f9bafa7a1857d2798ab96fe54239c7464a97c;hp=5c263154fd0de43d5c1e124d6b5fd35ad6ec1529;hpb=8a8dfb1c7d8ea124bf65333fa975667185b4cd73;p=perl%2Fmodules%2FSub-Nary.git diff --git a/lib/Sub/Nary.pm b/lib/Sub/Nary.pm index 5c26315..707a2e6 100644 --- a/lib/Sub/Nary.pm +++ b/lib/Sub/Nary.pm @@ -204,7 +204,7 @@ $ops{$_} = 0 for qw/stub nextstate/; $ops{$_} = 1 for qw/padsv/; $ops{$_} = 'list' for qw/padav/; $ops{$_} = 'list' for qw/padhv rv2hv/; -$ops{$_} = 'list' for qw/padany flip match entereval readline/; +$ops{$_} = 'list' for qw/padany match entereval readline/; $ops{each} = { 0 => 0.5, 2 => 0.5 }; $ops{stat} = { 0 => 0.5, 13 => 0.5 }; @@ -416,13 +416,12 @@ sub pp_goto { sub pp_const { my ($self, $op) = @_; - if (class($op) eq 'SVOP' and (my $sv = $self->const_sv($op))) { - my $c = class($sv); - if ($c eq 'AV') { - return $sv->FILL + 1; - } elsif ($c eq 'HV') { - return 2 * $sv->FILL; - } + my $sv = $self->const_sv($op); + my $c = class($sv); + if ($c eq 'AV') { + return $sv->FILL + 1; + } elsif ($c eq 'HV') { + return 2 * $sv->FILL; } return 1; @@ -446,6 +445,32 @@ sub pp_aassign { $_[0]->expect_any($_[1]->first) } sub pp_leaveloop { $_[0]->expect_return($_[1]->first->sibling) } +sub pp_flip { + my ($self, $op) = @_; + + $op = $op->first; + return 'list' if name($op) ne 'range'; + + my $begin = $op->first; + if (name($begin) eq 'const') { + my $end = $begin->sibling; + if (name($end) eq 'const') { + $begin = $self->const_sv($begin); + $end = $self->const_sv($end); + no warnings 'numeric'; + return int(${$end->object_2svref}) - int(${$begin->object_2svref}) + 1; + } else { + my ($p, $r) = $self->expect_return($end); + return $p => 1 if $r; + } + } else { + my ($p, $r) = $self->expect_return($begin); + return $p => 1 if $r; + } + + return 'list' +} + =head1 EXPORT An object-oriented module shouldn't export any function, and so does this one.