B-C

 view release on metacpan or  search on metacpan

bytecode.pl  view on Meta::CPAN

All bytecode values are already portable.
Cross-platform portability is implemented, cross-version not yet.

Cross-version portability will be very limited, cross-platform only
for the same threading model.

=head2 CROSS-PLATFORM PORTABILITY

For different endian-ness there are ByteLoader converters in effect.
Header entry: byteorder.

64int - 64all - 32int is portable. Header entry: ivsize

ITHREADS are unportable; header entry: archflag - bitflag 1.
MULTIPLICITY is also unportable; header entry: archflag - bitflag 2

TODO For cross-version portability we will try to translate older
bytecode ops to the current perl op via L<ByteLoader::Translate>.
Asmdata already contains the old ops, all with the PUT method 0.
Header entry: perlversion

=head2 CROSS-VERSION PORTABILITY (TODO - HARD)

Bytecode ops:
We can only reliably load bytecode from previous versions and promise
that from 5.10.0 on future versions will only add new op numbers at
the end, but will never replace old opcodes with incompatible arguments.
Unsupported insn's are supported by disassemble, and if C<force> in the
ByteLoader is set, it is tried to load/set them also, with probably fatal
consequences.
On the first unknown bytecode op from a future version - added to the end
- we will die.

L<ByteLoader::BcVersions> contains logic to translate previous errors
from this bytecode policy. E.g. 5.8 violated the 5.6 bytecode order policy
and began to juggle it around (similar to parrot), in detail removed
various bytecodes, like ldspecsvx:7, xpv_cur, xpv_len, xiv64:26.
So in theory it would have been possible to load 5.6 into 5.8 bytecode
as the underlying perl pp_code ops didn't change that much, but it is risky.

We have unused tables of all bytecode ops for all version-specific changes
to the bytecode table. This only changed with
the ByteLoader version, ithreads and major Perl versions.

Also special replacements in the byteloader for all the unsupported
ops, like xiv64, cop_arybase.

=head1 AUTHOR

Malcolm Beattie C<MICB at cpan.org> I<(retired)>,
Reini Urban added the version logic, support >= 5.10, portability.

=cut

# ex: set ro:
EOT

close ASMDATA_PM or die "Error closing $targets[0]: $!";
close BYTERUN_C or die "Error closing $targets[1]: $!";
close BYTERUN_H or die "Error closing $targets[2]: $!";
chmod 0444, @targets;

# TODO 5.10:
#   stpv (?)
#   pv_free: free the bs_pv and the SvPVX? (?)

__END__
# First set instruction ord("#") to read comment to end-of-line (sneaky)
35 0 comment	arg			comment_t
# Then make ord("\n") into a no-op
10 0 nop	none			none

# Now for the rest of the ordinary ones, beginning with \0 which is
# ret so that \0-terminated strings can be read properly as bytecode.
#
# The argtype is either a single type or "rightvaluecast/argtype".
# The version is either "i" or "!i" for ITHREADS or not,
#   "m" or "!m" for MULTI or not,
#   or num, num-num, >num or <num.
#   "0" is for all, "<10" requires PERL_VERSION<10, "10" requires
#   PERL_VERSION>=10, ">10" requires PERL_VERSION>10, "10-10"
#   requires PERL_VERSION>==10 only.
# lvalue is the (statemachine) value to read or write.
# argtype specifies the reader or writer method.
# flags x specifies a special writer method BSET_$insn in bytecode.h
# flags s store instructions to bytecode_obj_list[arg]. "lvalue" field is rvalue.
# flags \d+ specifies the maximal length.
#
# bc numbering policy: <=5.6: leave out, >=5.8 leave holes
# Note: ver 8 is really 8.001. 5.008000 had the same bytecodes as 5.006002.

#idx version opcode	lvalue				argtype		flags
#
0  0	ret		none				none		x
1  0 	ldsv		bstate->u.bs_sv			svindex
2  0 	ldop		PL_op				opindex
3  0 	stsv		bstate->u.bs_sv			U32		s
4  0 	stop		PL_op				U32		s
5  6.001 stpv		bstate->bs_pv.pv		U32		x
6  0 	ldspecsv	bstate->u.bs_sv			U8		x
7  8 	ldspecsvx	bstate->u.bs_sv			U8		x
8  0 	newsv		bstate->u.bs_sv			U8		x
9  8 	newsvx		bstate->u.bs_sv			U32		x
#10 0 	nop		none				none
11 0 	newop		PL_op				U8		x
12 8	newopx		PL_op				U16		x
13 0 	newopn		PL_op				U8		x
14 0 	newpv		none				U32/PV
15 0 	pv_cur		bstate->bs_pv.cur		STRLEN
16 0 	pv_free		bstate->bs_pv			none		x
17 0 	sv_upgrade	bstate->u.bs_sv			U8		x
18 0 	sv_refcnt	SvREFCNT(bstate->u.bs_sv)	U32
19 0 	sv_refcnt_add	SvREFCNT(bstate->u.bs_sv)	I32		x
20 0 	sv_flags	SvFLAGS(bstate->u.bs_sv)	U32
21 0 	xrv		bstate->u.bs_sv			svindex		x
22 0 	xpv		bstate->u.bs_sv			none		x
23 8	xpv_cur		bstate->u.bs_sv	 		STRLEN		x
24 8	xpv_len		bstate->u.bs_sv			STRLEN		x
25 8	xiv		bstate->u.bs_sv			IV		x
25 <8 	xiv32		SvIVX(bstate->u.bs_sv)		I32
0  <8 	xiv64		SvIVX(bstate->u.bs_sv)		IV64



( run in 1.950 second using v1.01-cache-2.11-cpan-d8267643d1d )