How to understand the sentence which I distinguish with a red rectangle?
1 Answer
Locals and function parameters are accessed through the same index space. An index space is an abstract entity - the implementer is free to place the parameters and locals as they see fit, but the parameters and locals should be accessed through the same index.
This add2 function which take the parameters $px and $py will access $px at index 0 and $py at index 1:
(func $add2 (param $px i32) (param $py i32)
get_local 0
get_local 1
i32.add)
This add_local function which only contains one parameter will have $px at index 0 and the local $z at index 1.
(func $add_local (param $px i32) (local $z i32)
get_local 0
get_local 1
i32.add)
So the index space for a function consists of
- [0] = param0
- [1 ] = param1
- ...
- [N] = paramN
- [N+1] = local0
- [N+2] = local1
- ...
- [N+M] = localM
