Perl virtual machine: Difference between revisions

Content deleted Content added
m clean up, typos fixed: internaly → internally using AWB
Opcodes: spelling
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 and ''sibling'' node, so the opcode tree can be draweddrawn 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. Each opcode is assigned with internal 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:
Line 22:
</source>
 
Some opcodes (entereval, dofile, require) call Perl compiler functions which generate anotherother opcodes in the same Perl virtual machine.
 
===Variables===