perlguts.pod
来自「ARM上的如果你对底层感兴趣」· POD 代码 · 共 1,725 行 · 第 1/5 页
POD
1,725 行
null null
| |
gvsv gvsv
The execution order is indicated by C<===E<gt>> marks, thus it is C<3
4 5 6> (node C<6> is not included into above listing), i.e.,
C<gvsv gvsv add whatever>.
=head2 Compile pass 1: check routines
The tree is created by the I<pseudo-compiler> while yacc code feeds it
the constructions it recognizes. Since yacc works bottom-up, so does
the first pass of perl compilation.
What makes this pass interesting for perl developers is that some
optimization may be performed on this pass. This is optimization by
so-called I<check routines>. The correspondence between node names
and corresponding check routines is described in F<opcode.pl> (do not
forget to run C<make regen_headers> if you modify this file).
A check routine is called when the node is fully constructed except
for the execution-order thread. Since at this time there are no
back-links to the currently constructed node, one can do most any
operation to the top-level node, including freeing it and/or creating
new nodes above/below it.
The check routine returns the node which should be inserted into the
tree (if the top-level node was not modified, check routine returns
its argument).
By convention, check routines have names C<ck_*>. They are usually
called from C<new*OP> subroutines (or C<convert>) (which in turn are
called from F<perly.y>).
=head2 Compile pass 1a: constant folding
Immediately after the check routine is called the returned node is
checked for being compile-time executable. If it is (the value is
judged to be constant) it is immediately executed, and a I<constant>
node with the "return value" of the corresponding subtree is
substituted instead. The subtree is deleted.
If constant folding was not performed, the execution-order thread is
created.
=head2 Compile pass 2: context propagation
When a context for a part of compile tree is known, it is propagated
down through the tree. At this time the context can have 5 values
(instead of 2 for runtime context): void, boolean, scalar, list, and
lvalue. In contrast with the pass 1 this pass is processed from top
to bottom: a node's context determines the context for its children.
Additional context-dependent optimizations are performed at this time.
Since at this moment the compile tree contains back-references (via
"thread" pointers), nodes cannot be free()d now. To allow
optimized-away nodes at this stage, such nodes are null()ified instead
of free()ing (i.e. their type is changed to OP_NULL).
=head2 Compile pass 3: peephole optimization
After the compile tree for a subroutine (or for an C<eval> or a file)
is created, an additional pass over the code is performed. This pass
is neither top-down or bottom-up, but in the execution order (with
additional complications for conditionals). These optimizations are
done in the subroutine peep(). Optimizations performed at this stage
are subject to the same restrictions as in the pass 2.
=head1 API LISTING
This is a listing of functions, macros, flags, and variables that may be
useful to extension writers or that may be found while reading other
extensions.
Note that all Perl API global variables must be referenced with the C<PL_>
prefix. Some macros are provided for compatibility with the older,
unadorned names, but this support will be removed in a future release.
It is strongly recommended that all Perl API functions that don't begin
with C<perl> be referenced with an explicit C<Perl_> prefix.
The sort order of the listing is case insensitive, with any
occurrences of '_' ignored for the the purpose of sorting.
=over 8
=item av_clear
Clears an array, making it empty. Does not free the memory used by the
array itself.
void av_clear (AV* ar)
=item av_extend
Pre-extend an array. The C<key> is the index to which the array should be
extended.
void av_extend (AV* ar, I32 key)
=item av_fetch
Returns the SV at the specified index in the array. The C<key> is the
index. If C<lval> is set then the fetch will be part of a store. Check
that the return value is non-null before dereferencing it to a C<SV*>.
See L<Understanding the Magic of Tied Hashes and Arrays> for more
information on how to use this function on tied arrays.
SV** av_fetch (AV* ar, I32 key, I32 lval)
=item AvFILL
Same as C<av_len()>. Deprecated, use C<av_len()> instead.
=item av_len
Returns the highest index in the array. Returns -1 if the array is empty.
I32 av_len (AV* ar)
=item av_make
Creates a new AV and populates it with a list of SVs. The SVs are copied
into the array, so they may be freed after the call to av_make. The new AV
will have a reference count of 1.
AV* av_make (I32 size, SV** svp)
=item av_pop
Pops an SV off the end of the array. Returns C<&PL_sv_undef> if the array is
empty.
SV* av_pop (AV* ar)
=item av_push
Pushes an SV onto the end of the array. The array will grow automatically
to accommodate the addition.
void av_push (AV* ar, SV* val)
=item av_shift
Shifts an SV off the beginning of the array.
SV* av_shift (AV* ar)
=item av_store
Stores an SV in an array. The array index is specified as C<key>. The
return value will be NULL if the operation failed or if the value did not
need to be actually stored within the array (as in the case of tied arrays).
Otherwise it can be dereferenced to get the original C<SV*>. Note that the
caller is responsible for suitably incrementing the reference count of C<val>
before the call, and decrementing it if the function returned NULL.
See L<Understanding the Magic of Tied Hashes and Arrays> for more
information on how to use this function on tied arrays.
SV** av_store (AV* ar, I32 key, SV* val)
=item av_undef
Undefines the array. Frees the memory used by the array itself.
void av_undef (AV* ar)
=item av_unshift
Unshift the given number of C<undef> values onto the beginning of the
array. The array will grow automatically to accommodate the addition.
You must then use C<av_store> to assign values to these new elements.
void av_unshift (AV* ar, I32 num)
=item CLASS
Variable which is setup by C<xsubpp> to indicate the class name for a C++ XS
constructor. This is always a C<char*>. See C<THIS> and
L<perlxs/"Using XS With C++">.
=item Copy
The XSUB-writer's interface to the C C<memcpy> function. The C<s> is the
source, C<d> is the destination, C<n> is the number of items, and C<t> is
the type. May fail on overlapping copies. See also C<Move>.
void Copy( s, d, n, t )
=item croak
This is the XSUB-writer's interface to Perl's C<die> function. Use this
function the same way you use the C C<printf> function. See C<warn>.
=item CvSTASH
Returns the stash of the CV.
HV* CvSTASH( SV* sv )
=item PL_DBsingle
When Perl is run in debugging mode, with the B<-d> switch, this SV is a
boolean which indicates whether subs are being single-stepped.
Single-stepping is automatically turned on after every step. This is the C
variable which corresponds to Perl's $DB::single variable. See C<PL_DBsub>.
=item PL_DBsub
When Perl is run in debugging mode, with the B<-d> switch, this GV contains
the SV which holds the name of the sub being debugged. This is the C
variable which corresponds to Perl's $DB::sub variable. See C<PL_DBsingle>.
The sub name can be found by
SvPV( GvSV( PL_DBsub ), PL_na )
=item PL_DBtrace
Trace variable used when Perl is run in debugging mode, with the B<-d>
switch. This is the C variable which corresponds to Perl's $DB::trace
variable. See C<PL_DBsingle>.
=item dMARK
Declare a stack marker variable, C<mark>, for the XSUB. See C<MARK> and
C<dORIGMARK>.
=item dORIGMARK
Saves the original stack mark for the XSUB. See C<ORIGMARK>.
=item PL_dowarn
The C variable which corresponds to Perl's $^W warning variable.
=item dSP
Declares a local copy of perl's stack pointer for the XSUB, available via
the C<SP> macro. See C<SP>.
=item dXSARGS
Sets up stack and mark pointers for an XSUB, calling dSP and dMARK. This is
usually handled automatically by C<xsubpp>. Declares the C<items> variable
to indicate the number of items on the stack.
=item dXSI32
Sets up the C<ix> variable for an XSUB which has aliases. This is usually
handled automatically by C<xsubpp>.
=item do_binmode
Switches filehandle to binmode. C<iotype> is what C<IoTYPE(io)> would
contain.
do_binmode(fp, iotype, TRUE);
=item ENTER
Opening bracket on a callback. See C<LEAVE> and L<perlcall>.
ENTER;
=item EXTEND
Used to extend the argument stack for an XSUB's return values.
EXTEND( sp, int x )
=item fbm_compile
Analyses the string in order to make fast searches on it using fbm_instr() --
the Boyer-Moore algorithm.
void fbm_compile(SV* sv, U32 flags)
=item fbm_instr
Returns the location of the SV in the string delimited by C<str> and
C<strend>. It returns C<Nullch> if the string can't be found. The
C<sv> does not have to be fbm_compiled, but the search will not be as
fast then.
char* fbm_instr(char *str, char *strend, SV *sv, U32 flags)
=item FREETMPS
Closing bracket for temporaries on a callback. See C<SAVETMPS> and
L<perlcall>.
FREETMPS;
=item G_ARRAY
Used to indicate array context. See C<GIMME_V>, C<GIMME> and L<perlcall>.
=item G_DISCARD
Indicates that arguments returned from a callback should be discarded. See
L<perlcall>.
=item G_EVAL
Used to force a Perl C<eval> wrapper around a callback. See L<perlcall>.
=item GIMME
A backward-compatible version of C<GIMME_V> which can only return
C<G_SCALAR> or C<G_ARRAY>; in a void context, it returns C<G_SCALAR>.
=item GIMME_V
The XSUB-writer's equivalent to Perl's C<wantarray>. Returns
C<G_VOID>, C<G_SCALAR> or C<G_ARRAY> for void, scalar or array
context, respectively.
=item G_NOARGS
Indicates that no arguments are being sent to a callback. See L<perlcall>.
=item G_SCALAR
Used to indicate scalar context. See C<GIMME_V>, C<GIMME>, and L<perlcall>.
=item gv_fetchmeth
Returns the glob with the given C<name> and a defined subroutine or
C<NULL>. The glob lives in the given C<stash>, or in the stashes
accessible via @ISA and @UNIVERSAL.
The argument C<level> should be either 0 or -1. If C<level==0>, as a
side-effect creates a glob with the given C<name> in the given
C<stash> which in the case of success contains an alias for the
subroutine, and sets up caching info for this glob. Similarly for all
the searched stashes.
This function grants C<"SUPER"> token as a postfix of the stash name.
The GV returned from C<gv_fetchmeth> may be a method cache entry,
which is not visible to Perl code. So when calling C<perl_call_sv>,
you should not use the GV directly; instead, you should use the
method's CV, which can be obtained from the GV wit
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?