parrotcode: Untitled | |
Contents | Language Implementations | .Net |
This document discusses .NET arrays and how they can be supported in Parrot.
Arrays are created using a "newarr" instruction which takes the type that the array will contain. As the notion of .NET value types isn't really handled so gracefully in the translation, there is a need to special-case them, mapping any type of array that stores integers to be a FixedIntegerArray and any array that stores floating point numbers to be a FixedFloatArray. All other types get stored in a FixedPMCArray.
Array loads and stores can be translated trivially to the PIR keyed syntax.
$I1 = $P1[$I0] # load
$P1[$I0] = $I1 # store
There $P1 is the array PMC, $I0 is the array index and $I1 is the register the value is loaded in to or the value to be stored.
The only remaining array instruction is ldlen, which loads the element count of the array onto the stack. This maps to the elements v-table call in Parrot.
$I0 = elements $P0
Where $P0 is the array PMC and $I0 will hold the number of elements.
|