I'd thought about arrays when I was first designing ZScript and postponed working on them because they are complicated. Very rudimentary, static, fixed size arrays, such as
Code:
ffc script foo {void run() {
int anarray[3];
anarray[someMethodReturningInt()]=42;
}
}
would not be terribly difficult to implement.
One thing to keep in mind is that the arrays will have to be stack-allocated, and the stack is currently capped at 256 elements. The stack is used as follows:
-Each local variable in the current method and all methods in the call hierarchy takes one slot.
-Each parameter of the current method and all methods in the call hierarchy takes one slot.
-For each method in the call hierarchy, two additional slots are taken up - one for the return value, and one for the old value of the stack frame pointer. This adds up when recursively calling functions.
-Evaluation of expressions requires up to two temporary slots for storing intermediate values.
Thus to ensure the script doesn't crash due to stack overflow the total space reserved for arrays will have to be kept small. Alternatively, we could add a free store common to all scripts and talk about dynamic allocation or even garbage collection