It is important to understand how the GOOL system stores parameters in memory and how they are passed.
The GOOL system passes parameters by pushing them onto the callee's stack (for subroutines, the callee and the caller are the same). That is, the following subroutine call:
sub MySub (a, b, c) {
x = a
y = b
z = c
}
MySub(10, 25, 50)
Will first push these three parameters to the stack like so:
..., 10, 25, 50
And afterwards, fill it in with a ..., 10, 25, 50, stack frame
GOOL accesses parameters (either for an object state or a subroutine) by going backwards starting from the stack frame. This means that the "first" parameter is described as being in ..., 10, 25, 50, stack frame
^ ^ ^
| | |
3rd 2nd 1st
MySub(10, 25)
..., 10, 25, stack frame
Since only two parameters were passed, only the last two parameters of the
On the other hand, passing in too many parameters to the left will have this effect:
MySub(100, 200, 300, 10, 25, 50)
..., 100, 200, 300, 10, 25, 50, stack frame
Now, the last three paramaters have defined values, while the extra parameters we passed are inoffensively just taking up stack space. However, since their memory location is based on a predictable pattern, you can actually use pointers to access these parameters. Here is an example of how the sub MySub (count, a, b, c) {
x = a
y = b
z = c
var va_start = &count - count*4
if (count > 0) {
do (var i = 0) {
x += va_start[i]
} while ({i += 1.0}; i < count)
}
}
...
MySub(20.0, 30.0, 40.0, 3, 10.0, 25.0, 50.0)
...
The variable