Common vtable format for all variables
Maintainer: Dan Sugalski <dan@sidhe.org> Class: Internals PDD Number: 2 Version: 1.2 Status: Developing Last Modified: 22 June 2002 PDD Format: 1 Language: English
22 June 2002
13 May 2002
None. First version
Many cleanups and clarifications. Much detail added. Many missing methods added.
Cleaned up the definition. It was a mess.
This RFC presents the vtable entries, and their order, that all variables MUST provide.
All perl variables hide their guts behind a magic perl structure generally referred to as a PMC, or Perl Magic Cookie. Nothing outside the core of perl (in fact, nothing outside the data type's vtable routines) should infer anything about a PMC. (hence the Magic part)
The first parameter to all of these should be the current interpreter. The second parameter should be the PMC itself.
vtables are neat because they decouple the interface and implementation of various object functions. This does mean, though, that you need to either know what functions are available and what they do, or have some method of finding out. It's faster if you know which vtable entry does what, so that's the method perl's using.
The actual vtable structure contains pointers to functions that implement the methods for that particular vtable. All pointers must point to valid functions with appropriate prototypes.
This is a list of each of the vtable methods, their prototypes, and a description of the method.
The following functions are singleton functions. (There are no keyed versions of these)
The init vtable method takes an unused PMC as a parameter, and turns it into a PMC appropriate for the class owning the vtable. Called as a class method. There is also a form that accepts a PMC initializer as a third argument.
This form of the init method takes a single initializer parameter. XXX - What is the initializer used for?
turns the PMC into a PMC of type type. If the morphing can't be reasonably done, for example if an integer is asked to turn into a PerlArray, then the PMC is first destroyed, then recreated as an empty PMC of the new type.
type
This method is primarily used when the interpreter has need of coercing a PMC to a particular type, and isn't meant as a general purpose casting tool. Compilers should only emit valid transformations.
Called by the DOD when its sweeping through the PMCs and has detected that this PMC is both alive and has a custom mark routine. The second parameter is the PMC at the tail of the free PMC list, as passed to mark_used. This should return the new tail of the free PMC list.
mark_used
If a PMC has this set, its responsible for marking all buffers and PMCs under its control as alive. If it does not, those PMCs or buffers may be collected later. This method does not have to call the mark method on any PMCs it marks--the DOD system takes care of that. (So no need to recurse into aggregate PMCs or anything of the sort)
mark
This method may allocate no memory from Parrot, nor may it alter Parrot's internal structures. It should have no side-effects from the C level either.
This routine may not throw an exception.
This method is called by the DOD when it determines that a PMC is dead, and that PMC has marked itself as having a destroy method.
When this method finishes, the PMC will be marked as dead. As such you should make sure that you do not leave any references to it in any parrot structure by the end of the method.
This method may not throw an exception. It will be ignored if it does.
The following functions have a plain form, a _keyed form, and a _keyed_int form. The keyed forms take a KEY* or INTVAL* for each PMC parameter. The KEY*/INTVAL* parameter for each PMC is NULL if there is no key for that PMC; this means that that arguement is unkeyed.
In some cases, the caller must provide a non-NULL key. Those cases are explicitly stated below. In the other cases, you may have to implement the keyed vtable methods and check for a NULL self key even if you are implementing a non-aggregate type. If the self key is non- NULL and the PMC class is a non-aggregate type, the _keyed_* methods should throw an exception.
If you do not implement the _keyed_int methods, the default will convert the INTVAL into a KEY and call the corresponding _keyed method.
The keyed methods should NOT assume that the key pointer will be valid after the method exits. The pointer may be to a stack variable in the calling function.
Return the type of the PMC. Type is a unique tag associated with the PMC when the PMC's class is loaded. Negative numbers are considered interpreter-specific, non-public types.
Return the type of the PMC indexed by key. The key parameter is guaranteed not to be NULL for this method.
Returns the subtype of a PMC. (Note that this may be unimplemented, and may go away) This is intended to return information about the PMC--what type of number or string it is, whether it's a scalar, hash, array, or list, and suchlike things.
Return the subtype of the PMC indexed by key. The key parameter is guaranteed not to be NULL for this method.
Return the name of the class for the PMC.
Return the name of the class of the PMC indexed by key. The key parameter is guaranteed not to be NULL for this method.
Return a clone of yourself.
Return a clone of the PMC indexed by key. If the PMC is fake, for example we're asking for a clone of an element of an integer array, this must return an appropriate real PMC that holds the fake information. The key parameter is guaranteed not to be NULL for this method.
Returns a subroutine PMC for the passed method name. This subroutine PMC may be cached, so the method must return an equivalent sub PMC each time, or be capable of dealing with the returned sub PMCs being reused.
Returns a subroutine PMC for the passed method name. This subroutine PMC may be cached, so the method must return an equivalent sub PMC each time, or be capable of dealing with the returned sub PMCs being reused. The key parameter is guaranteed not to be NULL for this method.
Returns the native integer value of the PMC.
Returns the native integer value of the PMC indexed by key. The key parameter is guaranteed not to be NULL for this method.
Returns the native floating-point value of the PMC.
Returns the native floating-point value of the PMC indexed by key. The key parameter is guaranteed not to be NULL for this method.
Returns the value of the PMC as a bignum.
Returns the bignum value of the PMC indexed by key. The key parameter is guaranteed not to be NULL for this method.
Returns the native string value of the PMC. This may be in the encoding of the PMC's choice.
Returns the string value of the PMC indexed by key. The key parameter is guaranteed not to be NULL for this method.
Returns the constant TRUE if the PMC is true, or FALSE if the PMC is false.
Returns the constant TRUE if the PMC indexed by key is true, or FALSE if the PMC indexed by key is false. The key parameter is guaranteed not to be NULL for this method.
Returns the number of elements in the PMC.
Returns the number of elements in the PMC indexed by key. The key parameter is guaranteed not to be NULL for this method.
Returns the PMC for this PMC. While this may seem nonsensical, it's useful in several circumstances. If the thing being accessed may return something odd, for example a reference, it may return a value different than the PMC that get_pmc is being called on.
Returns the PMC indexed by key. The key parameter is guaranteed not to be NULL for this method.
Returns TRUE if the PMCs are the same, and FALSE if they're not. In this case, "the same" means identical at a low level. For plain equality, use the is_equal method.
Returns TRUE if the PMC keyed by key is the same as the PMC in value keyed by value_key. At least one of the two keys is guaranteed not to be NULL.
Sets the PMC to the integer value of the PMC in value. What the PMC does with the passed in integer depends on the class.
Sets the PMC to the integer value passed.
Sets the PMC to the integer value of the PMC in value. In this case, value is guaranteed to be of the same type as self so optimizations may be made.
Sets the PMC indexed by key to the integer value passed in value. The key parameter is guaranteed not to be NULL for this method.
Sets the PMC to the floating-point value of the PMC in value.
Sets the PMC to the floating-point value passed.
Sets the PMC to the floating-point value of the PMC in value. In this case, value is guaranteed to be of the same type as self so optimizations may be made.
Sets the PMC indexed by key to the floating-point value passed in value. The key parameter is guaranteed not to be NULL for this method.
Sets the PMC to the bignum value of value.
Sets the PMC to the passed in bignum value.
Sets the PMC to the bignum value of value. In this case, value is guaranteed to be of the same type as self so optimizations may be made.
Sets the PMC indexed by key to the bignum value passed in value. The key parameter is guaranteed not to be NULL for this method.
Sets the PMC to the string value of value.
Sets the PMC to the passed in string value.
Sets the PMC to the string value of value. In this case, value is guaranteed to be of the same type as self so optimizations may be made.
Sets the PMC indexed by key to the string value passed in value. The key parameter is guaranteed not to be NULL for this method.
Assigns the value of source PMC to the value of the PMC in value.
Sets the value of the PMC keyed by key to the value of the PMC in value keyed by value_key. At least one of the two keys is guaranteed not to be NULL.
A shortcut version of set_pmc in those cases where the interpreter knows the source and destination PMCs are of the same type.
set_pmc
Sets the value keyed by key to the value of value keyed by value_key. Both self and value are guaranteed to be of the same type so optimizations may be made.
At least one of the two keys is guaranteed not to be NULL.
Because the two PMCs are guaranteed to be of the same type, this method may throw an exception if the PMC class is a non-aggregate type.
Returns the integer value of the last item on the list, removing that item.
Returns the integer value of the last item of the list keyed by key, removing that item from the list. The key parameter is guaranteed not to be NULL for this method.
Returns the floating-point value of the last item on the list, removing that item.
Returns the floating-point value of the last item of the list keyed by key, removing that item from the list. The key parameter is guaranteed not to be NULL for this method.
Returns the bignum value of the last item on the list, removing that item.
Returns the bignum value of the last item of the list keyed by key, removing that item from the list. The key parameter is guaranteed not to be NULL for this method.
Returns the string value of the last item on the list, removing that item.
Returns the string value of the last item of the list keyed by key, removing that item from the list. The key parameter is guaranteed not to be NULL for this method.
Returns the PMC value of the last item on the list, removing that item.
Returns the PMC value of the last item of the list keyed by key, removing that item from the list. The key parameter is guaranteed not to be NULL for this method.
Add the passed in integer value to the end of the list.
Add the passed in integer value to the end of the list keyed by key. The key parameter is guaranteed not to be NULL for this method.
Add the passed in floating-point number to the end of the list.
Add the passed in floating-point value to the end of the list keyed by key. The key parameter is guaranteed not to be NULL for this method.
Add the passed in bignum to the end of the list.
Add the passed in bignum to the end of the list keyed by key. The key parameter is guaranteed not to be NULL for this method.
Add the passed in string to the end of the list.
Add the passed in PMC to the end of the list.
Add the passed in PMC to the end of the list keyed by key. At least one of the two keys is guaranteed not to be NULL. If key is NULL then the method will use self. If value_key is NULL then the method will use value.
Returns the integer value of the first item on the list, removing that item.
Returns the integer value of the fisrt item of the list keyed by key, removing that item from the list. The key parameter is guaranteed not to be NULL for this method.
Returns the floating-point value of the first item on the list, removing that item.
Returns the floating-point value of the first item of the list keyed by key, removing that item from the list. The key parameter is guaranteed not to be NULL for this method.
Returns the bignum value of the first item on the list, removing that item.
Returns the bignum value of the first item of the list keyed by key, removing that item from the list. The key parameter is guaranteed not to be NULL for this method.
Returns the string value of the first item on the list, removing that item.
Returns the string value of the first item of the list keyed by key, removing that item from the list. The key parameter is guaranteed not to be NULL for this method.
Returns the PMC value of the first item on the list, removing that item.
Returns the PMC value of the first item of the list keyed by key, removing that item from the list. The key parameter is guaranteed not to be NULL for this method.
Add the passed in integer value to the beginning of the list.
Add the passed in integer value to the beginning of the list keyed by key. The key parameter is guaranteed not to be NULL for this method.
Add the passed in floating-point number to the beginning of the list.
Add the passed in floating-point value to the beginning of the list keyed by key. The key parameter is guaranteed not to be NULL for this method.
Add the passed in bignum to the beginning of the list.
Add the passed in bignum to the beginning of the list keyed by key. The key parameter is guaranteed not to be NULL for this method.
Add the passed in string to the beginning of the list.
Add the passed in PMC to the beginning of the list.
Add the passed in PMC to the beginning of the list keyed by key. At least one of the two keys is guaranteed not to be NULL.
XXX - Interface undetermined
Add self to value and store the result in dest. Note that dest may be equal to self; in that case optimizations may be made.
Add self to value and store the result in dest. Note that dest may be equal to self; in that case optimizations may be made. In this case, it is guaranteed that self and value are of the same type.
Add the value in self keyed by key to the value in value keyed by value_key and store the result in dest keyed by dest_key.
At least one of the three keys is guaranteed to not be NULL.
Subtract self from value and store the result in dest. Note that dest may be equal to self; in that case optimizations may be made.
Subtract self from value and store the result in dest. Note that dest may be equal to self; in that case optimizations may be made. In this case, it is guaranteed that self and value are of the same type.
Subtract the value in self keyed by key from the value in value keyed by value_key and store the result in dest keyed by dest_key.
Multiply value by self and store the result in dest. Note that dest may be equal to self; in that case optimizations may be made.
Multiply value by self and store the result in dest. Note that dest may be equal to self; in that case optimizations may be made. In this case, it is guaranteed that self and value are of the same type.
Multiply the value in self keyed by key by the value in value keyed by value_key and store the result in dest keyed by dest_key.
Divide self by value and store the result in dest. Note that dest may be equal to self; in that case optimizations may be made.
Divide self by value and store the result in dest. Note that dest may be equal to self; in that case optimizations may be made. In this case, it is guaranteed that self and value are of the same type.
Divide the value in self keyed by key by the value in value keyed by value_key and store the result in dest keyed by dest_key.
Divide self by value and store the remainder in dest. Note that dest may be equal to self; in that case optimizations may be made.
Divide self by value and store the remainder in dest. Note that dest may be equal to self; in that case optimizations may be made. In this case, it is guaranteed that self and value are of the same type.
Divide the value in self keyed by key by the value in value keyed by value_key and store the remainder in dest keyed by dest_key.
Negate the sign of self and store the result in dest. Note that self and dest may refer to the same PMC, in which case optimizations may be made.
Calculate the bitwise-OR of self and value and store the result in dest. Note that dest may be equal to self; in that case optimizations may be made.
Calculate the bitwise-OR of self and value and store the result in dest. Note that dest may be equal to self; in that case optimizations may be made. In this case, it is guaranteed that self and value are of the same type.
Calculate the bitwise-OR of self keyed by key and value keyed by value_key, and store the result in dest_key.
At least one of the keys is guaranteed to be non-NULL.
Calculate the bitwise-AND of self and value and store the result in dest. Note that dest may be equal to self; in that case optimizations may be made.
Calculate the bitwise-AND of self and value and store the result in dest. Note that dest may be equal to self; in that case optimizations may be made. In this case, it is guaranteed that self and value are of the same type.
Calculate the bitwise-AND of self keyed by key and value keyed by value_key, and store the result in dest_key.
Calculate the bitwise-XOR of self and value and store the result in dest. Note that dest may be equal to self; in that case optimizations may be made.
Calculate the bitwise-XOR of self and value and store the result in dest. Note that dest may be equal to self; in that case optimizations may be made. In this case, it is guaranteed that self and value are of the same type.
Calculate the bitwise-XOR of self keyed by key and value keyed by value_key, and store the result in dest_key.
Applies a bitwise negation to self and stores the result in dest. Note that self and dest may refer to the same PMC; in that case optimizations may be made.
Applies a bitwise negation to self keyed by key and stores the result in dest keyed by dest_key.
At least one key is guaranteed to be non-NULL.
Concatenate the strings in self and value and store the result in dest. Note that self and dest may refer to the same PMC; in that case optimizations may be made.
Concatenate the strings in self and value and store the result in dest. Note that self and dest may refer to the same PMC; in that case optimizations may be made. In this case, self and value are guaranteed to be of the same type.
Concatentate the string in value keyed by value_key onto the string in self keyed by key and store the result in dest keyed by dest_key.
Returns TRUE if the two PMCs are generically equivalent, or FALSE if they aren't.
Returns TRUE if the PMC at self keyed by key is generally equivalent to the PMC at value keyed by value_key, or FALSE if they aren't.
Compares the two PMCs as PMCs (whatever that means for the class). Returns -1 if self is smaller, 0 if the two are equal, and 1 if value is smaller.
Compares the PMC at self keyed by key with the PMC at value keyed by value_key as PMCs (whatever that means for the class). Returns -1 if self is smaller, 0 if the two are equal, and 1 if value is smaller.
At least one key is guaranteed to be not NULL.
Compares the two PMCs numerically. Returns -1 if self is smaller, 0 if the two are equal, and 1 if value is smaller.
Compares the PMC at self keyed by key with the PMC at value keyed by value_key numerically. Returns -1 if self is smaller, 0 if the two are equal, and 1 if value is smaller.
Compares the two PMCs as strings. Returns -1 if self is smaller, 0 if the two are equal, and 1 if value is smaller.
Does a short-circuiting logical-OR of self and value, storing the winner in dest.
Does a short-circuiting logical-OR of self keyed by key and value keyed by value_key, storing the winner in dest keyed by dest_key.
Does a short-circuiting logical-AND of self and value, storing the winner in dest.
Does a short-circuiting logical-AND of self keyed by key and value keyed by value_key, storing the winner in dest keyed by dest_key.
If exactly one of self or value is true, store it in dest. Else set dest to be false.
If exactly one of self keyed by key or value keyed by value_key is true, store it in dest keyed by dest_key. Else set dest keyed by dest_key to be false.
Does a logical-NOT on self and stores the result in dest.
Does a logical-NOT on self keyed by key and stores the result in dest keyed by dest_key.
Repeat the string value of self value times and store the resultant string in dest.
Repeat the string in self keyed by key by the quantity of value keyed by value_key and store the result in dest keyed by dest_key.
Repeat the string in self keyed by key value times and store the result in dest keyed by dest_key.
Autoincrement the PMC.
Autoincrement the PMC keyed by key. The key is guaranteed to be non-NULL.
Autodecrement the PMC.
Autodecrement the PMC keyed by key. The key is guaranteed to be non-NULL.
This is only valid for keyed access. Returns TRUE or FALSE if the key exists or doesn't in the aggregate being queried.
The key is guaranteed to not be NULL.
Checks to see if the PMC is defined. Returns TRUE or FALSE.
Returns TRUE if the value of self keyed by key is defined, FALSE otherwise.
The key is guaranteed to be not NULL.
Delete the specified entry from the aggregate.
Given the passed in key for the PMC, return the next key.
Place the value of the substring of self into dest.
Place the value of the substring of self keyed by key into dest keyed by dest_key.
Return a substring of the passed in PMC.
Return a substring of self keyed by key.
To install Make, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Make
CPAN shell
perl -MCPAN -e shell install Make
For more information on module installation, please visit the detailed CPAN module installation guide.