X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FSub%2FNary.pm;h=427ee8c7eb7cfe3b021d58ae0887117bd1523bfc;hb=cab48037c2f684dd60d1860bdc2efa3d10d3e7a3;hp=eb26dfce3d24a411987ab91e49aba22a3fcbb10c;hpb=08ec5acb4cc88d8cc10fec0520d8cd075c08fda1;p=perl%2Fmodules%2FSub-Nary.git diff --git a/lib/Sub/Nary.pm b/lib/Sub/Nary.pm index eb26dfc..427ee8c 100644 --- a/lib/Sub/Nary.pm +++ b/lib/Sub/Nary.pm @@ -198,18 +198,28 @@ sub add { } my %ops; + $ops{$_} = 1 for scalops; $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 }; + $ops{caller} = sub { my @a = caller 0; scalar @a }->(); $ops{localtime} = do { my @a = localtime; scalar @a }; $ops{gmtime} = do { my @a = gmtime; scalar @a }; +$ops{$_} = { 0 => 0.5, 10 => 0.5 } for map "gpw$_", qw/nam uid ent/; +$ops{$_} = { 0 => 0.5, 4 => 0.5 } for map "ggr$_", qw/nam gid ent/; +$ops{$_} = 'list' for qw/ghbyname ghbyaddr ghostent/; +$ops{$_} = { 0 => 0.5, 4 => 0.5 } for qw/gnbyname gnbyaddr gnetent/; +$ops{$_} = { 0 => 0.5, 3 => 0.5 } for qw/gpbyname gpbynumber gprotoent/; +$ops{$_} = { 0 => 0.5, 4 => 0.5 } for qw/gsbyname gsbyport gservent/; + sub enter { my ($self, $cv) = @_; @@ -436,6 +446,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.