From: Simon Cozens Date: Sun, 10 Dec 2000 00:06:47 +0000 (+0000) Subject: perlguts.pod X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9afa14e3eaac220f2db84245e03f30eb5513ce63;p=p5sagit%2Fp5-mst-13.2.git perlguts.pod Message-ID: <20001210000647.A16203@deep-dark-truthful-mirror.perlhacker.org> Documentation of the different types of ops, plus the functions in dump.c p4raw-id: //depot/perl@8063 --- diff --git a/pod/perlguts.pod b/pod/perlguts.pod index ded9191..f38bba3 100644 --- a/pod/perlguts.pod +++ b/pod/perlguts.pod @@ -1515,6 +1515,31 @@ The execution order is indicated by C<===E> marks, thus it is C<3 4 5 6> (node C<6> is not included into above listing), i.e., C. +Each of these nodes represents an op, a fundamental operation inside the +Perl core. The code which implements each operation can be found in the +F files; the function which implements the op with type C +is C, and so on. As the tree above shows, different ops have +different numbers of children: C is a binary operator, as one would +expect, and so has two children. To accommodate the various different +numbers of children, there are various types of op data structure, and +they link together in different ways. + +The simplest type of op structure is C: this has no children. Unary +operators, Cs, have one child, and this is pointed to by the +C field. Binary operators (Cs) have not only an +C field but also an C field. The most complex type of +op is a C, which has any number of children. In this case, the +first child is pointed to by C and the last child by +C. The children in between can be found by iteratively +following the C pointer from the first child to the last. + +There are also two other op types: a C holds a regular expression, +and has no children, and a C may or may not have children. If the +C field is non-zero, it behaves like a C. To +complicate matters, if a C is actually a C op after +optimization (see L) it will still +have children in accordance with its former type. + =head2 Compile pass 1: check routines The tree is created by the compiler while I code feeds it @@ -1575,6 +1600,41 @@ 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 Examining internal data structures with the C functions + +To aid debugging, the source file F contains a number of +functions which produce formatted output of internal data structures. + +The most commonly used of these functions is C; it's used +for dumping SVs, AVs, HVs, and CVs. The C module calls +C to produce debugging output from Perl-space, so users of that +module should already be familiar with its format. + +C can be used to dump an C structure or any of its +derivatives, and produces output similiar to C; in fact, +C will dump the main root of the code being evaluated, +exactly like C<-Dx>. + +Other useful functions are C, which turns a C into an +op tree, C which calls C on all the +subroutines in a package like so: (Thankfully, these are all xsubs, so +there is no op tree) + + (gdb) print Perl_dump_packsubs(PL_defstash) + + SUB attributes::bootstrap = (xsub 0x811fedc 0) + + SUB UNIVERSAL::can = (xsub 0x811f50c 0) + + SUB UNIVERSAL::isa = (xsub 0x811f304 0) + + SUB UNIVERSAL::VERSION = (xsub 0x811f7ac 0) + + SUB DynaLoader::boot_DynaLoader = (xsub 0x805b188 0) + +and C, which dumps all the subroutines in the stash and +the op tree of the main root. + =head1 How multiple interpreters and concurrency are supported =head2 Background and PERL_IMPLICIT_CONTEXT