Content deleted Content added
Mindmatrix (talk | contribs) revert - rm link, as it is not specifically about the subject; formatting: whitespace (using Advisor.js) |
m Bot: http → https |
||
(12 intermediate revisions by 11 users not shown) | |||
Line 1:
The '''Perl virtual machine''' is a [[Stack machine|stack-based]] [[Application virtual machine|process virtual machine]] implemented as an [[opcode]]s [[Interpreter (computing)|interpreter]] which runs previously compiled programs written in the [[Perl]] language. The opcodes interpreter is a part of the Perl interpreter, which also contains a [[compiler]] ([[Lexical analysis|lexer]], [[Parsing|parser]] and [[Compiler optimization|optimizer]]) in one executable file, commonly /usr/bin/perl on various [[Unix-like]] systems or perl.exe on [[Microsoft Windows]] systems.
Line 5 ⟶ 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=
Perl's opcodes interpreter is implemented as a tree walker which travels
The phase of compiling
An example of
<
$ perl -MO=Concise,-exec -E 'say "Hello, world!"'
1 <0> enter
Line 21 ⟶ 20:
5 <@> say vK
6 <@> leave[1 ref] vKP/REFC
</syntaxhighlight>
Some opcodes (entereval, dofile, require) call Perl compiler functions which in turn generate other opcodes in the same Perl virtual machine.
===Variables===
Perl variables can be global, dynamic (''local'' keyword), or lexical (''my'' and ''our'' keywords).
Global variables are accessible via the stash and the corresponding [[typeglob]].
Local variables are the same as global variables but a special opcode is generated to save its value on the ''savestack'' and restore it later.
Lexical variables are stored
===Data structures===
Perl VM data structures are represented internally by [[typedef]]s.
The internal data structures can be examined with the B Perl module<ref name="B" /> or other specialized tools like the Devel::Peek Perl module.<ref>{{cite web | url=
====data types====
Perl has three typedefs that handle Perl's three main data types: Scalar Value (''SV''), Array Value (''AV''), Hash Value (''HV''). Perl uses a special typedef for the simple signed integer type (''IV''),
Perl uses a [[Reference counting|reference count]]-driven garbage collection mechanism. SVs, AVs, or HVs start their life with a reference count of 1. If the reference count of a data value
Other typedefs are Glob Value (''GV'') which
====stash====
Line 62 ⟶ 61:
====Save stack====
This stack is used for saving and restoring
====Scope stack====
This stack stores information about the actual scope and it is used only for debugging purposes.
===Other implementations===
There is no
The most known and most stable implementation is
Another implementation is an Acme::Perl::VM Perl module<ref>{{cite web | url=
==See also==
Line 81 ⟶ 80:
==External links==
*[
*[
*[
{{Perl}}
Line 89 ⟶ 88:
{{DEFAULTSORT:Perl Virtual Machine}}
[[Category:Perl]]
[[Category:
|