1. aload
Loads all elements of an array or packed array onto the operand stack.
1.1. Syntax
array aload → array₀ ... arrayₙ₋₁ array packedarray aload → packedarray₀ ... packedarrayₙ₋₁ packedarray
1.2. Stack Effects
| Level | Object |
|---|---|
0 |
|
| Level | Object |
|---|---|
n |
|
n-1 |
|
… |
… |
0 |
|
1.3. Description
aload successively pushes all n elements of an array or packed array onto the operand stack (where n is the length of the operand), and finally pushes the array or packed array itself back onto the stack.
The elements are pushed in index order: element 0 first, element n-1 last.
1.5. Examples
[23 (ab) -6] aload
% Stack: 23 (ab) -6 [23 (ab) -6]
[1 2 3 4 5] aload pop % Pop the array itself
% Stack: 1 2 3 4 5
{ add } repeat % Sum all values
% Result: 15
[100 200 300] aload
% Stack: 100 200 300 [100 200 300]
pop exch pop
% Stack: 200 (middle element extracted)
1.6. Common Use Cases
1.7. Common Pitfalls
[1 2 3] aload % Stack: 1 2 3 [1 2 3]
% Don't forget the array is still there!
| Stack Overflow - Loading large arrays can overflow the operand stack. |
1000 array aload % Might cause stackoverflow
1.8. Error Conditions
| Error | Condition |
|---|---|
[ |
Array has no-access attribute |
[ |
Not enough room on stack for all elements plus array |
[ |
No operand on stack |
[ |
Operand is not an array or packed array |
1.9. Implementation Notes
-
Elements are shared between the array and stack (not copied)
-
Modifying a composite element affects both the array and the stack value
-
Works identically for arrays and packed arrays
-
The array reference on top of stack can be used to restore values with
astore