In most of the examples we’ve shown so far, PMCs just duplicate the functionality of integers, numbers, and strings. They wouldn’t be terribly useful if that’s all they did, though. PMCs offer several advanced features, each with its own set of operations.
PMCs can define complex types that hold multiple values. These are commonly called " aggregates.” The most important feature added for aggregates is keyed access. Elements within an aggregate PMC can be stored and retrieved by a numeric or string key. PASM also offers a full set of operations for manipulating aggregate data types.
Since PASM is intended to implement Perl, the two most fully featured aggregates already in operation are arrays and hashes. Any aggregate defined for any language could take advantage of the features described here.
PMC is an ordered aggregate with integer
keys. The syntax for keyed access to a PMC puts the key in
square brackets after the register name:
new P0, .PerlArray # obtain a new array object set P0, 2 # set its length set P0, 10 # set first element to 10 set P0, I31 # set second element to I31 set I0, P0 # get the first element set I1, P0 # get array length
A key on the destination register of a
operation sets a value for that key in the aggregate. A key on the
source register of a
set returns the value for
that key. If you set
P0 without a key, you set the
length of the array, not one of its values. And if you set an integer to ...