Re: Where to find info on low level perl internals names?
by bart (Canon) on Oct 25, 2011 at 11:02 UTC
|
I've read through the most obvious places...
Have you also checked out Perlguts Illustrated? I don't thinks so, or you'd have seen this:
The first things to look at are the data structures that represent Perl data; scalars of various kinds, arrays and hashes. Internally Perl calls a scalar SV (scalar value), an array AV (array value) and a hash HV (hash value). In addition it uses IV for integer value, NV for numeric value (aka double), PV for a pointer value (aka string value (char*), but 'S' was already taken), and RV for reference value. The IVs are further guaranteed to be big enough to hold a void* pointer.
update Link updated (future proofed) to always point to the latest version, as per the follow-up. Thanks, anon! I knew about "dist", but not that it would work for this particular case.
| [reply] |
|
|
| [reply] |
Re: Where to find info on low level perl internals names?
by Corion (Patriarch) on Oct 25, 2011 at 11:04 UTC
|
For general information on Perls internal memory structures, I would look at illguts. The names for the various structures are best treated as Just Names, but the following mnemonics work for me:
SV - Scalar Value
IV - Integer Value
NV - Numerical Value
RV - Reference Value
PV - Pointer Value (like *char, for example)
LV - I haven't encountered this one, maybe it lives in illguts
GV - glob value. The glob is (I think) shorthand for global
AV - Array Value
HV - Hash Value
CV - Code Value (think subroutine reference)
FM - Format
IO - Filehandle
The ops are also documented in illguts I believe.
Update: Typoo | [reply] [d/l] |
|
|
LV = left hand value, used for "substr($string, 0, 10) = "replacement value";" system.
| [reply] |
Re: Where to find info on low level perl internals names?
by BrowserUk (Patriarch) on Oct 25, 2011 at 10:57 UTC
|
A few:
(WTF does the 'V' stand for?)
Also wild-assed guess: 'V' stands for variable. So SV stands for Scalar Variable.
(WTF does 'P' stand for?)
'P' stands for Pointer; as in the value stored here is a pointer to the (string) value as opposed to IV where the value stored here is the Integer Variable itself; or NV where the value is the value of the Number Variable itself.
LV is ? ("LeftValue?" LVALUE? Local? )
Left value in the C language lvalue sense of, a value that can appear on the left side of the assignment operator. (eg. not a constant).
GV is ? (General? Global?, Garbage-Collected?)
Global Variable.
- CV => Code Variable (a perl subroutine pointer.)
- IO => io object handle: Like STDIN, STDOUT STDERR, ARGV etc.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] |
|
|
GV is a "glob", short for "typeglob", as in "a bunch of types". They are used as symbol table entries, although they can exist outside the symbol table, so they aren't necessarily global. open my $fh, ... populates $fh with a reference to a "non-global" glob.
| [reply] [d/l] [select] |
|
|
| [reply] |
|
|
|
|
|
|
|
|
Re: Where to find info on low level perl internals names?
by Not_a_Number (Prior) on Oct 25, 2011 at 10:59 UTC
|
| [reply] |
Re: Where to find info on low level perl internals names?
by Tux (Canon) on Oct 25, 2011 at 12:49 UTC
|
$ perldoc guts
:
Variables
Datatypes
Perl has three typedefs that handle Perl's three main data type
+s:
SV Scalar Value
AV Array Value
HV Hash Value
Each typedef has specific routines that manipulate the various
+data
types.
What is an "IV"?
Perl uses a special typedef IV which is a simple signed integer
+ type
that is guaranteed to be large enough to hold a pointer (as wel
+l as an
integer). Additionally, there is the UV, which is simply an un
+signed
IV.
Perl also uses two special typedefs, I32 and I16, which will al
+ways be
at least 32-bits and 16-bits long, respectively. (Again, there
+are U32
and U16, as well.) They will usually be exactly 32 and 16 bits
+ long,
but on Crays they will both be 64 bits.
:
:
etc etc
$
Next to guts you might want to take a look at xs and xstut.
I don't think your WTF?'s are appropriate.
Enjoy, Have FUN! H.Merijn
| [reply] [d/l] |
|
|
| [reply] |
Re: Where to find info on low level perl internals names?
by ikegami (Patriarch) on Oct 25, 2011 at 19:38 UTC
|
$ perl -MB -E'$_=123; $_=undef; say B::class B::svref_2object \$_'
IV
SV is the base "class" for all Perl variables (not just scalars), but yeah, the "S" stands for "scalar".
Here goes:
| B class name | Actual SV type | Description | Example
|
|---|
| SPECIAL | NULL | Can hold undef | perl -MB -E'say B::class B::svref_2object \undef'
| | PV | PV | Can hold undef, a string of 8 bit chars or a string of 32/64 bit chars | perl -MB -E'say B::class B::svref_2object \"a"'
| | IV | IV | Can hold undef, a reference, a signed int or an unsigned integer | perl -MB -E'say B::class B::svref_2object \123'
| | NV | NV | Can hold undef or a floating point number | perl -MB -E'say B::class B::svref_2object \1.3'
| | PVIV | PVIV | Can hold undef, a reference, a signed int, an unsigned integer, a string of 8 bit chars and/or a string of 32/64 bit chars | perl -MB -E'$_=123; "".$_; say B::class B::svref_2object \$_'
| | PVNV | PVNV | Can hold undef, a reference, a signed int, an unsigned integer, a floating point number, a string of 8 bit chars and/or a string of 32/64 bit chars | perl -MB -E'$_=1.3; "".$_; say B::class B::svref_2object \$_'
| | PVMG | PVMG | A PVNV that supports magic | perl -MB -E'say B::class B::svref_2object \$|'
| | PVLV | PVLV | A PVMG with extra fields, used for lvalues | perl -MB -E'say B::class B::svref_2object \substr("",0)'
| | GV | PVGV | A glob | perl -MB -E'say B::class B::svref_2object \*FOO'
| | AV | PVAV | An array | perl -MB -E'say B::class B::svref_2object []'
| | HV | PVHV | A hash | perl -MB -E'say B::class B::svref_2object {}'
| | CV | PVCV | A sub | perl -MB -E'say B::class B::svref_2object sub{}'
| | FM | PVFM | A format | use B;
use feature qw( say );
format X =
Foo
.
say B::class B::svref_2object *X{FORMAT};
| | IO | PVIO | Can hold a file handle or a directory handle | perl -MB -E'say B::class B::svref_2object *STDOUT{IO}'
| | REGEXP | REGEXP | A regexp object | perl -MB -E'say B::class B::svref_2object qr//'
|
The "P" in "PV" is for "pointer".
Where "and/or" is used, all combinations are possible, with the following exceptions:
- An undefined scalar is one that contains nothing at all, so a scalar cannot contain both undef and something else.
- A scalar cannot contain two or more of the following at a time: a reference, a signed integer and an unsigned integer.
- A scalar cannot contain both of the following at a time: a string of 8 bit chars and a string of 32/64 bit chars
While it is technically possible for some scalars to contain both a reference and something else, Perl doesn't create these, and I don't know how safe it is.
| [reply] [d/l] [select] |
|
|
$ perl -MDP -we'open DH,$0;DDump*DH'
SV = PVGV(0x11d7dc0) at 0x76a5e0
REFCNT = 3
FLAGS = (MULTI)
NAME = "DH"
NAMELEN = 2
GvSTASH = 0x74af48 "main"
GP = 0x771bc0
SV = 0x0
REFCNT = 1
IO = 0x76a5f8
FORM = 0x0
AV = 0x0
HV = 0x0
CV = 0x0
CVGEN = 0x0
LINE = 1
FILE = "-e"
FLAGS = 0x2
EGV = 0x76a5e0 "DH"
$ perl -MDP -we'opendir DH,".";DDump*DH'
SV = PVGV(0x11d7e00) at 0x76a5f0
REFCNT = 3
FLAGS = (MULTI)
NAME = "DH"
NAMELEN = 2
GvSTASH = 0x74af48 "main"
GP = 0x771b30
SV = 0x0
REFCNT = 1
IO = 0x76a620
FORM = 0x0
AV = 0x0
HV = 0x0
CV = 0x0
CVGEN = 0x0
LINE = 1
FILE = "-e"
FLAGS = 0x2
EGV = 0x76a5f0 "DH"
Enjoy, Have FUN! H.Merijn
| [reply] [d/l] [select] |
|
|
In both case, we have scalars of the same type (PVIO). But just like an IV can hold more than one kind of data, PVIO can contain one of two types of handles. I'll clarify that in my table.
By the way, you didn't show the difference, so here goes:
$ perl -MDevel::Peek -we'open FH,$^X; Dump *FH{IO}'
SV = IV(0x7564a8) at 0x7564b0
REFCNT = 1
FLAGS = (TEMP,ROK)
RV = 0x7693f0
SV = PVIO(0x76ccb8) at 0x7693f0
REFCNT = 2
FLAGS = (OBJECT)
STASH = 0x768b68 "IO::File"
IFP = 0x763b30
OFP = 0x0
DIRP = 0x0
LINES = 0
PAGE = 0
PAGE_LEN = 60
LINES_LEFT = 0
TOP_GV = 0x0
FMT_GV = 0x0
BOTTOM_GV = 0x0
TYPE = '<'
FLAGS = 0x0
$ perl -MDevel::Peek -we'opendir DH,"."; Dump *DH{IO}'
SV = IV(0x759d18) at 0x759d20
REFCNT = 1
FLAGS = (TEMP,ROK)
RV = 0x76cc78
SV = PVIO(0x770528) at 0x76cc78
REFCNT = 2
FLAGS = (OBJECT)
STASH = 0x76c3d8 "IO::File"
IFP = 0x0
OFP = 0x0
DIRP = 0x7a7330
LINES = 0
PAGE = 0
PAGE_LEN = 60
LINES_LEFT = 0
TOP_GV = 0x0
FMT_GV = 0x0
BOTTOM_GV = 0x0
TYPE = '\0'
FLAGS = 0x0
| [reply] [d/l] |
|
|
|
|
Thanks again!
I'm kinda laughing at myself, and you might enjoy the laugh as well, so I
might as well share... I spent a few minutes staring at the output of
those two commands you posted trying to spot "the difference." ;)
(sigh) sometimes I make myself wonder.
| [reply] |
|
|
A scalar cannot contain both of the following at a time: a string of 8 bit chars and a string of 32/64 bit chars
32bit chars? 64bit chars? UTF 16? UTF 32? UTF 64 jkjk?
| [reply] |
|
|
32bit chars? 64bit chars?
32 on 32 bit builds. 64 on 64 bit builds. The format actually allows for 72 bit numbers, but Perl doesn't provide a means of storing and fetching values that large.
UTF 16? UTF 32? UTF 64
Are you asking about the format? It's a variable width format based on UTF-8 confusingly called utf8, but it has nothing to do with Unicode. For starters, the highest possible Unicode character is only 0x10FFFF, far less than what utf8 allows. Unicode has a bunch of reserved and private use and whatnot code points, but not these strings. Unicode imposes certain semantics, but not these strings.
| [reply] |
|
|
| [reply] |
Re: Where to find info on low level perl internals names?
by Anonymous Monk on Oct 25, 2011 at 12:52 UTC
|
Many Thanks To All!
Perl Guts Illustrated was exactly what I was looking for and oddly enough, I had seen and visited a link to it, but it was 404'd.
| [reply] |
Re: Where to find info on low level perl internals names?
by Khen1950fx (Canon) on Oct 27, 2011 at 13:13 UTC
|
I've been using
Opcode and
Opcodes
to grok
B
and the opcodes. For example,
#!/usr/bin/perl
use strict;
use Opcodes;
use Opcode qw(opdump);
use Data::Dumper::Concise;
print Dumper
(opdump), "\n",
(scalar opcodes), "\n",
(opname2code('gv')), "\n",
(opdesc(7)), "\n",
(opclass(7)), "\n",
(opdesc(opclass(7))), "\n";
(opdump) lists all the opcodes.
(scalar opcodes) the number of opcodes for your version of perl
(opname2code('gv')) gives the number('code') of gv.
(opdesc(7)) the number for gv. Gives a short description
(opclass(7)) - classes such as OP, COP, UNOP, BINOP, etc.
- here, gv is a svop_or_padop which is 6
(opdesc(opclass(7))) - tells you that it's a scalar variable
| [reply] [d/l] |