parrotcode: Parrot's internal data types | |
Contents | Documentation |
docs/pdds/pdd04_datatypes.pod - Parrot's internal data types
This PDD describes Parrot's internal data types.
This PDD details the basic datatypes that the Parrot core knows how to deal with. Three of these (the integer, floating point and string datatypes) have no additional semantics. The fourth datatype, the Parrot Magic Cookie (PMC) acts as the basis for all high level languages running on top of Parrot; only the most basic aspects are described here.
Note that PMC and string internals are volatile and may be changed in the future (although this will become increasingly unlikely as we near v1.0). Access from external code to the internals of particular datatypes should be via the extension mechanism (see docs/pdds/pdd11_extending.pod, which has more explicit guarantees of stability.
Integer data types are generically referred to as INT
s.
These are whatever size native integer was chosen at Parrot configuration time.
The C-level typedefs INTVAL
and UINTVAL
get you a platform-native signed and unsigned integer respectively.
Floating point data types are generically referred to as NUM
s.
These are whatever size float was chosen when parrot was configured.
The C level typedef FLOATVAL
will get you one of these.
Parrot has a single internal string form:
struct parrot_string_t {
pobj_t obj;
UINTVAL bufused;
void *strstart;
UINTVAL strlen;
const ENCODING *encoding;
const CHARTYPE *type;
INTVAL language;
}
The fields are:
Parrot Magic Cookies, or PMCs, are the last of Parrot's basic datatypes, but are also potentially the most important. Their basic structure is as follows. All PMCs have the form:
struct PMC {
pobj_t obj;
VTABLE *vtable;
#if ! PMC_DATA_IN_EXT
DPOINTER *data;
#endif
struct PMC_EXT *pmc_ext;
};
where obj
is a pointer to an pobj_t
structure:
typedef struct pobj_t {
UnionVal u;
Parrot_UInt flags;
#if ! DISABLE_GC_DEBUG
UINTVAL _pobj_version;
#endif
} pobj_t;
and where:
typedef union UnionVal {
struct {
void * _bufstart;
size_t _buflen;
} _b;
struct {
DPOINTER* _struct_val;
PMC* _pmc_val;
} _ptrs;
INTVAL _int_val;
FLOATVAL _num_val;
struct parrot_string_t * _string_val;
} UnionVal;
u
holds data associated with the PMC. This can be in the form of an integer value, a floating point value, a string value, or a pointer to other data. u
may be empty, since the PMC structure also provides a more general data pointer, but is useful for PMCs which hold only a single piece of data (e.g. PerlInts
).
flags
holds a set of flags associated with the PMC; these are documented in include/parrot/pobj.h, and are generally only used within the Parrot internals.
_pobj_version
is only used for debugging Parrot's garbage collector. It is documented elsewhere (well, it will be once we get around to doing that...).
vtable
holds a pointer to the vtable associated with the PMC. This points to a set of functions, with interfaces described in docs/pdds/pdd02_vtables.pod that implement the basic behaviour of the PMC (i.e. how it behaves under addition, subtraction, cloning etc.)
data
(if present) holds a pointer to any additional data associated with the PMC. This may be NULL.
pmc_ext
points to an extended PMC structure. This has the form:
struct PMC_EXT {
#if PMC_DATA_IN_EXT
DPOINTER *data;
#endif
PMC *_metadata;
struct _Sync *_synchronize;
PMC *_next_for_GC;
};
data
is a generic data pointer, as described above.
_metadata
holds internal PMC metadata. The specification for this has not yet been finalized.
_synchronize
is for access synchronization between shared PMCs.
_next_for_GC
determines the next PMC in the 'used' list during dead object detection in the GC.
PMCs are not required to have a PMC_EXT
structure (i.e. pmc_ext
can be null).
PMCs are used to implement the basic data types of the high level languages running on top of Parrot. For instance, a Perl 5 SV
will map onto one (or more) types of PMC, while particular Python datatypes will map onto different types of PMC.
None.
The perl modules Math::BigInt and Math::BigFloat. Alex Gough's suggestions for bigint/bignum implementation, outlined in docs/pdds/pdd14_bignum.pod. The Unicode standard at http://www.unicode.org.
1.4
Maintainer: Dan Sugalski <dan@sidhe.org>
Class: Internals
PDD Number: 4
Version: 1.5
Status: Developing
Last Modified: 11 June 2005
PDD Format: 1
Language: English
Hey! The above document had some coding errors, which are explained below:
|