Content deleted Content added
Category:Perl |
m Bot: http → https |
||
(29 intermediate revisions by 24 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
▲The '''Perl virtual machine''' is a [[Stack machine|stack-based]] [[Application virtual machine|process virtual machine]] implemented as [[opcode|opcodes]] [[Interpreter (computing)|interpreter]] which runs a previously compiled [[Perl]] programs. Opcodes interpreter is is a part of Perl interpreter which contains also [[Compiler|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.
==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
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
2 <;> nextstate(main 46 -e:1) v:%,{
3 <0> pushmark s
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
===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 in the ''padlist''.
===Data structures===
Perl VM data structures are represented internally by [[typedef
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====
Special Hash Value is ''stash'', a hash that contains all variables that are defined within a package. Each value in this hash table is a Glob Value (''GV'').
====padlist====
▲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>.
Special Array Value is ''padlist'' which is an array of array. Its 0th element to an AV containing all lexical variable names (with prefix symbols) used within that subroutine. The padlist's first element points to a scratchpad AV, whose elements contain the values corresponding to the lexical variables named in the 0th row. Another elements of padlist are created when the subroutine recurses or new thread is created.
===Stacks===
Perl has a number of stacks to store things it
====Argument stack====
Line 48 ⟶ 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 67 ⟶ 80:
==External links==
*[
*[
*[
{{Perl}}
{{DEFAULTSORT:Perl Virtual Machine}}
[[Category:Perl]]
[[Category:
|