Perl virtual machine: Difference between revisions

Content deleted Content added
Topbanana (talk | contribs)
m Link repair: Category:Free software articles needing expert attention -> Category:Free Software articles needing expert attention - You can help!
m copy ed using AWB
Line 3:
 
==Implementation==
 
===Opcodes===
The Perl compiler outputs a compiled program into memory as an internal structure which can be represented as a tree graph in which each node represents an opcode. Opcodes are represented internally by [[typedef]]s. Each opcode has ''next'' / ''other'' and ''first'' / ''sibling'' pointers, so the opcode tree can be drawn as a basic OP tree starting from root node or as flat OP list in the order they would normally execute from start node. Opcodes tree can be mapped to the source code, so it is possible to [[Decompiler|decompile]] to high-level source code.<ref>{{cite web | url=http://perldoc.perl.org/B/Deparse.html | title=B::Deparse - Perl compiler backend to produce perl code}}</ref>
Line 8 ⟶ 9:
Perl's opcodes interpreter is implemented as a tree walker which travels by opcode tree in execute order from start node, following the ''next'' or ''other'' pointers. Each opcode has a function pointer to a pp_''opname'' function, i.e. ''say'' opcode calls ''pp_say'' function of internal Perl API.
 
The phase of compiling the Perl program is hidden for the end user, but it can be exposed with B Perl module<ref name="B">{{cite web | url=http://search.cpan.org/perldoc?B | title=B - The Perl Compiler Backend}}</ref> or other specialized modules like B::Concise Perl module.<ref>{{cite web | url=http://perldoc.perl.org/B/Concise.html | title=B::Concise - Walk Perl syntax tree, printing concise info about ops}}</ref>.
 
An example of compiled simple [[Hello world]] program with a help of B::Concise Perl module, dumped in execute order:
Line 36 ⟶ 37:
Perl VM data structures are represented internally by [[typedef]]s.
 
The internal data structures can be examined with B Perl module<ref name="B" /> or other specialized tools like Devel::Peek Perl module.<ref>{{cite web | url=http://search.cpan.org/perldoc?Devel::Peek | title=Devel::Peek - A data debugging tool for the XS programmer}}</ref>.
 
====data types====
Line 52 ⟶ 53:
 
===Stacks===
Perl has a number of stacks to store things it's currentlyis working on.
 
====Argument stack====