Skip to content

Commit

Permalink
0.03_01 fixes for 5.10
Browse files Browse the repository at this point in the history
- enabled block-level register/unregister
- stabilized 11-integer.t left shift test (newlib)
  • Loading branch information
Reini Urban committed Feb 27, 2011
1 parent 5d7db4a commit e62b489
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Build.PL
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ my $build = Module::Build->new
Hook::Scope => '0.02',
'B::Generate' => '1.05',
'optimizer' => '0.02',
'perl' => '5.8',
'perl' => '5.008',
}
);
$build->create_build_script();
6 changes: 5 additions & 1 deletion Changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Revision history for Perl extension optimize

0.03 Sun Aug 11 23:45:10 CEST 2002
0.03_01 2011-02-19 rurban
- enabled register/unregister
- stablized 11-integer left shift test

0.03 Sun Aug 11 23:45:10 CEST 2002 abergman
- Fixed bug when a constant was a AV in which we would get bizare
copy of Array

Expand Down
28 changes: 25 additions & 3 deletions Makefile.PL
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
use 5.008;
use ExtUtils::MakeMaker;
WriteMakefile
(
'NAME' => 'optimize',
'VERSION_FROM' => 'lib/optimize.pm',
'PREREQ_PM' =>
{
'DynaLoader' => 0,
'B::Generate' => '1.34'
},
AUTHOR => 'Arthur Bergman',
($ExtUtils::MakeMaker::VERSION gt '6.46' ?
('META_MERGE' =>
{
resources =>
{
license => 'http://dev.perl.org/licenses/',
repository => 'http://github.com/rurban/optimize',
},
}
) : ()),
);

sub MY::depend { "README : lib/optimize.pm\n\tpod2text lib/optimize.pm > README\n"; }

use Module::Build::Compat;
Module::Build::Compat->run_build_pl(args => \@ARGV);
Module::Build::Compat->write_makefile();
62 changes: 35 additions & 27 deletions lib/optimize.pm
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use strict;

package optimize;
Expand All @@ -8,28 +7,31 @@ use B::Utils qw(walkallops_simple);
use B qw(OPf_KIDS OPf_MOD OPf_PARENS OPf_WANT_SCALAR OPf_STACKED);
use Attribute::Handlers;
use Hook::Scope qw(POST);
our $VERSION = 0.03;
our $VERSION = "0.03_01";

our %pads;
our $state;
our $old_op;
our %loaded;
our $stash;
our $stash = '';
our %register;
use optimizer "extend-c" => sub {

use optimizer "extend-c" => sub {
my $op = shift;
POST { $old_op = $op; return () };
POST(sub{$old_op = $op;()});
return unless $op;
if($op->name eq 'nextstate') {
$state = $op;
$stash = $state->stash->NAME;
# print $state->file . ":" . $state->line . "-" . $state->stash->NAME . "\n";;
}
if($stash =~/^(optimize|B::|type|float|int|^O$)/) {
# print "Don't optimize ourself\n";
return;
# print $state->file . ":" . $state->line . "-" . $state->stash->NAME . "\n";

if($stash =~/^(optimize|B::|types$|float$|double$|int$|number$|^O$)/) {
# print "Don't optimize ourself\n";
return;
}
}

# print "$op - " . $op->name . " - " . $op->next . " - " . ($op->next->can('name') ? $op->next->name : "") . "\n";
# print "$op - " . $op->name . " - " . $op->next . " - " . ($op->next->can('name') ? $op->next->name : "") . "\n";
my $cv;
eval {
$cv = $op->find_cv;
Expand All @@ -39,32 +41,29 @@ use optimizer "extend-c" => sub {
print "$@ in " . $state->file . ":" . $state->line . "\n";;
return;
}




if($op->name eq 'const' &&
ref($op->sv) eq 'B::PV' &&
$op->sv->sv eq 'attributes' &&
$op->sv->sv eq 'attributes' &&
$op->can('next') &&
$op->next->can('next') &&
$op->next->next->can('next') &&
$op->next->next->next->can('next') &&
$op->next->next->next->next->can('next') &&
$op->next->next->next->next->next->can('next') &&
$op->next->next->next->next->next->can('next') &&
$op->next->next->next->next->next->next &&
$op->next->next->next->next->next->next->name eq 'method_named' &&
$op->next->next->next->next->next->next->sv->sv eq 'import') {

#Here we establish that this is an use of attributes on lexicals
#however we want to establish what attribute it is
$op->next->next->next->next->next->next->sv->sv eq 'import')
{

# Here we establish that this is an use of attributes on lexicals
# however we want to establish what attribute it is

my $attribute = $op->next->next->next->next->next->sv->sv;

if($attribute =~/^optimize\(\s*(.*)\s*\)/) {
# print "$attribute\n";
# print "$attribute\n";
my @attributes = split /\s*,\s*/, $1;
# print "GOT " . join("-", @attributes) . "\n";
# print "GOT " . join("-", @attributes) . "\n";

if($op->next->next->name eq 'padsv') {
my $sv = (($cv->PADLIST->ARRAY)[0]->ARRAY)[$op->next->next->targ];
Expand All @@ -81,10 +80,11 @@ use optimizer "extend-c" => sub {
}

for (values %loaded) {
# print "Calling $_\n";
# print "Calling $_\n";
$_->check($op);
# print "Called $_\n";
# print "Called $_\n";
}
# calling types
if(exists($register{$stash})) {
for my $callback (values %{$register{$stash}}) {
if($callback) {
Expand All @@ -111,9 +111,12 @@ sub unregister {
}

sub UNIVERSAL::optimize : ATTR {

;
}

1;
__END__
=head1 NAME
optimize - Pragma for hinting optimizations on variables
Expand Down Expand Up @@ -154,4 +157,9 @@ L<optimize::int> L<B::Generate>
=cut
1;
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4:
2 changes: 1 addition & 1 deletion lib/optimize/int.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ sub check {
if(exists($int{$op->name})) {
my $cv = $op->find_cv();
if(exists($optimize::pads{$cv->ROOT->seq}) &&
$optimize::pads{$cv->ROOT->seq}->[$op->targ]->[1]->{int}) {
$optimize::pads{$cv->ROOT->seq}->[$op->targ]->[1]->{int}) {
$mutate++;
} elsif($op->can('first') && $op->first->name eq 'padsv' &&
exists($optimize::pads{$cv->ROOT->seq}) &&
Expand Down
2 changes: 1 addition & 1 deletion t/02-register.t
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

use Test::More tests=> 9;
use Test::More tests=> 7;
use optimize;

package foo;
Expand Down
11 changes: 5 additions & 6 deletions t/11-integer.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!./perl



use Test::More tests => 11;
use Config;
use optimize;
Expand All @@ -28,13 +26,13 @@ $z = $x / $y;
is($z, 0, "modulo");

is($x, 4.5, "scalar still floating point");

isnt(sqrt($x), 2, "functions still floating point");

isnt($x ** .5, 2, "power still floating point");

is(++$x, 5.5, "++ still floating point");

SKIP: {
my $ivsize = $Config{ivsize};
skip "ivsize == $ivsize", 2 unless $ivsize == 4 || $ivsize == 8;
Expand All @@ -44,7 +42,8 @@ SKIP: {
is($z + 1, -2147483648, "left shift");
} elsif ($ivsize == 8) {
$z = 2**63 - 1;
is($z + 1, -9223372036854775808, "left shift");
my $i = $z + 1;
ok("$i" =~ /-922337203685477580[6-9]$/, "left shift");
}
}
$z = 0;
Expand Down

0 comments on commit e62b489

Please sign in to comment.