Skip to content

Commit

Permalink
BC: more PADLIST + PAD work
Browse files Browse the repository at this point in the history
rename padl_new to newpadl
fix Assembler (1.11) not to skip newpadl with arg = 0
seperate B::PAD::bsave method from B::AV::bsave for convenience
  (need only av_extend and av_pushx)
fix newpadl ix/bsave order: first save elements (ix),
  then store the two PAD* arrays into padl
support Disassembler newpadl ix++

(does not work yet)
  • Loading branch information
Reini Urban committed Oct 31, 2012
1 parent 9928495 commit 87d023f
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 32 deletions.
15 changes: 7 additions & 8 deletions ByteLoader/bytecode.h
Original file line number Diff line number Diff line change
Expand Up @@ -733,9 +733,7 @@ static int bget_swab = 0;
#endif

/* old reading new + new reading old */
#define BSET_op_pmflags(r, arg) STMT_START { \
r = arg; \
} STMT_END
#define BSET_op_pmflags(r, arg) r = arg

/* restore dups for stdin, stdout and stderr */
#define BSET_xio_ifp(sv,fd) \
Expand All @@ -750,13 +748,14 @@ static int bget_swab = 0;
} STMT_END

#if PERL_VERSION >= 17
#define BSET_padl_new(padlist) \
STMT_START { \
bstate->bs_sv = (SV*)Perl_pad_new(0); \
} STMT_END
#define BSET_newpadl(padl, arg) STMT_START { \
padl = (SV*)Perl_pad_new(arg); \
BSET_OBJ_STOREX(padl); \
} STMT_END
#define BSET_padl_name(padl, pad) PadlistARRAY((PADLIST*)padl)[0] = (PAD*)pad;
#define BSET_padl_sym(padl, pad) PadlistARRAY((PADLIST*)padl)[1] = (PAD*)pad;
#endif


/* NOTE: The bytecode header only sanity-checks the bytecode. If a script cares about
* what version of Perl it's being called under, it should do a 'use 5.006_001' or
* equivalent. However, since the header includes checks for a match in
Expand Down
10 changes: 8 additions & 2 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The Perl compiler was in CORE from alpha4 until Perl 5.9.4
and worked quite fine with Perl 5.6 and 5.8

1.43 2012-06-xx rurban
1.43 2012-10-xx rurban
Improved package detection: methods, functions, require, new and bless.
Bigger compile sizes. Store all subs of dependent packages.
5.16 support
Expand Down Expand Up @@ -39,16 +39,22 @@
amagic_generation was removed with 5.17
Fixed $$ ($PID) to be dynamic, issue 108. Thanks to flexvault for reporting this.
Fixed double precision to 16 digits. The nbody shootout test passes now
Fixed refcounts of *ENV, issue 111.
* CC (1.13): added check_entersub, check_bless - bless and new caching.
Use the B::C integer and double precision logic (ivx, nvx).
Fixed double precision to 16 digits. The nbody shootout is now 2x faster than perl
* Bytecode (1.14): fixed require and op_first, issue 97
Fixed regex_pad offset in threaded perls >= 5.11, issue 68
Fixed regex_pad offset in threaded perls >= 5.11, issue 68.
new type B::PAD isa B::AV (PADLIST for 5.17.5),
new bytecodes newpadl, padl_name, padl_sym (PADLIST for 5.17.5)
* Assembler (1.11): allow "newpadl 0"
* t/perldoc.t: perlcc fails with 5.8 because Cwd disturbs the
fragile method package finder for File::Spec. Use cc_harness.
* Stash (1.03): fix compilation for 5.8.8 and below: gv_fetchsv missing
* perlcc (2.14): new option --dryrun, -v5 does not -Dsp,-v.
new option -f passthru to C and CC
* perlcc (2.15): fixed default --spawn: use waitpid which was broken for parallel builds.
fixed --no-spawn

1.42 2012-02-01 rurban
stable up to 5.14
Expand Down
6 changes: 3 additions & 3 deletions bytecode.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,6 @@ =head1 AUTHOR
# restore dup to stdio handles 0-2
158 0 xio_ifp bstate->bs_sv char x
159 10 xpvshared bstate->bs_sv none x
160 17.005 padl_new bstate->bs_sv none x
161 17.005 padl_name PadlistARRAY((PADLIST*)bstate->bs_sv)[0] svindex
162 17.005 padl_set PadlistARRAY((PADLIST*)bstate->bs_sv)[1] svindex
160 17.005 newpadl bstate->bs_sv U8 x
161 17.005 padl_name PadlistARRAY((PADLIST*)bstate->bs_sv)[0] svindex x
162 17.005 padl_sym PadlistARRAY((PADLIST*)bstate->bs_sv)[1] svindex x
6 changes: 3 additions & 3 deletions lib/B/Assembler.pm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Assembler.pm
#
# Copyright (c) 1996 Malcolm Beattie
# Copyright (c) 2008,2009,2010,2011 Reini Urban
# Copyright (c) 2008,2009,2010,2011,2012 Reini Urban
#
# You may distribute under the terms of either the GNU General Public
# License or the Artistic License, as specified in the README file.
Expand All @@ -17,7 +17,7 @@ no warnings; # XXX

@ISA = qw(Exporter);
@EXPORT_OK = qw(assemble_fh newasm endasm assemble asm maxopix maxsvix);
$VERSION = '1.10';
$VERSION = '1.11';

use strict;
my %opnumber;
Expand Down Expand Up @@ -425,7 +425,7 @@ sub asm ($;$$) {
if ( defined $_[1] ) {
return
if $_[1] eq "0"
and $_[0] !~ /^(?:ldsv|stsv|newsvx?|av_pushx?|av_extend|xav_flags)$/;
and $_[0] !~ /^(?:ldsv|stsv|newsvx?|newpadl|av_pushx?|av_extend|xav_flags)$/;
return if $_[1] eq "1" and $]>5.007 and $_[0] =~ /^(?:sv_refcnt)$/;
}
my ( $insn, $arg, $comment ) = @_;
Expand Down
35 changes: 22 additions & 13 deletions lib/B/Bytecode.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

# Reviving 5.6 support here is work in progress, and not yet enabled.
# So far the original is used instead, even if the list of failed tests
# is impressive: 3,6,8..10,12,15,16,18,25..28. Pretty broken.
# is impressive: 3,6,8..10,12,15,16,18,25..28. Pretty broken on 5.6.
# 5.17.5 is also not supported yet (new PADLIST type)

package B::Bytecode;
Expand Down Expand Up @@ -232,7 +232,7 @@ sub B::SV::ix {
nice '[' . class($sv) . " $tix]";
B::Assembler::maxsvix($tix) if $debug{A};
my $type = $sv->FLAGS & 0xff; # SVTYPEMASK
asm "newsvx", $sv->FLAGS,
asm "newsvx", $sv->FLAGS,
$debug{Comment} ? sprintf("type=%d,flags=0x%x,%s", $type, $sv->FLAGS,sv_flags($sv)) : '';
asm "stsv", $tix if $PERL56;
$svtab{$$sv} = $varix = $ix = $tix++;
Expand All @@ -248,7 +248,7 @@ sub B::PADLIST::ix {
defined($ix) ? $ix : do {
nice '[' . class($padl) . " $tix]";
B::Assembler::maxsvix($tix) if $debug{A};
asm "padl_new";
asm "newpadl", 0;
$svtab{$$padl} = $varix = $ix = $tix++;
$padl->bsave($ix);
$ix;
Expand Down Expand Up @@ -647,6 +647,15 @@ sub B::FM::bsave {
asm "xfm_lines", $form->LINES;
}

sub B::PAD::bsave {
my ( $av, $ix ) = @_;
my @array = $av->ARRAY;
$_ = $_->ix for @array; # save the elements
$av->B::NULL::bsave($ix);
asm "av_extend", scalar @array if @array;
asm "av_pushx", $_ for @array;
}

sub B::AV::bsave {
my ( $av, $ix ) = @_;
if (!$PERL56 and $av->MAGICAL) {
Expand Down Expand Up @@ -677,29 +686,29 @@ sub B::AV::bsave {
asm "sv_flags", $av->FLAGS if $av->FLAGS & SVf_READONLY; # restore flags
} else {
#$av->domagic($ix) if $av->MAGICAL; # XXX need tests for magic arrays
# check for 5.17.5 PADLIST
asm "av_extend", $av->MAX if $av->MAX >= 0 and ref($av) ne 'B::PAD';
asm "av_extend", $av->MAX if $av->MAX >= 0;
asm "av_pushx", $_ for @array;
if ( !$PERL510 ) { # VERSION < 5.009
asm "xav_flags", $av->AvFLAGS, as_hex($av->AvFLAGS);
}
# asm "xav_alloc", $av->AvALLOC if $] > 5.013002; # XXX new but not needed
}
asm "sv_refcnt", $av->REFCNT unless ref($av) eq 'B::PAD';
asm "xmg_stash", $stashix unless ref($av) eq 'B::PAD';
asm "sv_refcnt", $av->REFCNT;
asm "xmg_stash", $stashix;
}

sub B::PADLIST::bsave {
my ( $padl, $ix ) = @_;
my @array = $padl->ARRAY;
for (@array) {
bless $_, 'B::PAD'; # skip av_extend
$_ = $_->ix; # hack. call ->ix methods to save the pad array elements
}
bless $array[0], 'B::PAD';
bless $array[1], 'B::PAD';
my $ix0 = $array[0]->ix; # comppad_name
my $ix1 = $array[1]->ix; # comppad syms

nice "-PADLIST-",
asm "ldsv", $varix = $ix unless $ix == $varix;
asm "padl_name", $array[0]; # comppad_name
asm "padl_set", $array[1]; # comppad
asm "padl_name", $ix0;
asm "padl_sym", $ix1;
}

sub B::GV::desired {
Expand Down
10 changes: 7 additions & 3 deletions lib/B/Disassembler.pm
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Disassembler.pm
#
# Copyright (c) 1996 Malcolm Beattie
# Copyright (c) 2008,2009,2010,2011 Reini Urban
# Copyright (c) 2008,2009,2010,2011,2012 Reini Urban
#
# You may distribute under the terms of either the GNU General Public
# License or the Artistic License, as specified in the README file.

$B::Disassembler::VERSION = '1.10';
$B::Disassembler::VERSION = '1.11';

package B::Disassembler::BytecodeStream;

Expand Down Expand Up @@ -316,7 +316,11 @@ sub print_insn {
my $type = $arg >> 7;
my $size = $arg - ( $type << 7 );
$arg .= sprintf( " \t# size:%d, type:%d %s", $size, $type ) if $comment;
printf "\n# [%s %d]\n", $opname[$type], $ix++ if $comment;
printf "\n# [%s %d]\n", $opname[$type], $ix++;
}
elsif ( $insn eq 'newpadl' ) {
$arg .= "\t# " . $comment if $comment ne '1';
printf "\n# [%s %d]\n", "PADLIST", $ix++;
}
elsif ( !$comment ) {
;
Expand Down

0 comments on commit 87d023f

Please sign in to comment.