Perl virtual machine: Difference between revisions

Content deleted Content added
D3xter (talk | contribs)
m Data structures: RV
D3xter (talk | contribs)
Data stuctures: padlist. Variables.
Line 24:
 
Some opcodes (entereval, dofile, require) call Perl compiler functions which generate another 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 ''savestack'' and restore it later.
 
Lexical variables are stored on ''padlist''.
 
===Data structures===
Perl VM data structures are represented internally by [[typedef|typedefs]].
 
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>.
 
====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 simple signed integer type (''IV''), an unsigned integer (''IV''), a floating point number (''NV'') and string (''PV'').
 
Line 34 ⟶ 46:
Other typedefs are Glob Value (''GV'') which contains named references to the various objects, Code Value (''CV'') which contains a reference to Perl subroutine, I/O Handler (''IO''), a reference to [[Regular expression|regular expression]] (''REGEXP''; ''RV'' in Perl before 5.11), reference to compiled format for output record (''FM'') and simple reference which is a special type of scalar that point to other data types (''RV'').
 
====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===