Perl virtual machine: Difference between revisions

Content deleted Content added
grammar
Jjore (talk | contribs)
Line 4:
==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 a ''next'' node/ ''other'' and ''first'' / ''sibling'' nodepointers, 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 actual 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>
 
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 ishas assigneda withfunction internalpointer 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 which provides an access to internal API of compilator and opcode walker 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: