Perl virtual machine: Difference between revisions

Content deleted Content added
PrimeBOT (talk | contribs)
m top: Task 24: remove a maintenance template following a TFD
m Bot: http → https
 
(One intermediate revision by one other user not shown)
Line 4:
 
===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=httphttps://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 the opcode tree in execution order from the start node, following the ''next'' or ''other'' pointers. Each opcode has a function pointer to a pp_''opname'' function, i.e. the ''say'' opcode calls the ''pp_say'' function of internal Perl API.
 
The phase of compiling a Perl program is hidden from the end user, but it can be exposed with the B Perl module<ref name="B">{{cite web | url=https://metacpan.org/module/B | title=B - The Perl Compiler Backend}}</ref> or other specialized modules, as the B::Concise Perl module.<ref>{{cite web | url=httphttps://perldoc.perl.org/B/Concise.html | title=B::Concise - Walk Perl syntax tree, printing concise info about ops}}</ref>
 
An example of a simple compiled [["Hello, World!" program|Hello world]] program dumped in execute order (with the B::Concise Perl module):
 
<syntaxhighlight lang="console">
Line 80:
 
==External links==
*[httphttps://perldoc.perl.org/perlhack.html#Running The Perl internals: running stage]
*[httphttps://perldoc.perl.org/perlguts.html Introduction to the Perl API]
*[https://metacpan.org/module/RURBAN/B-C-1.42/perloptree.pod The "B" op tree.]