1

enter image description here

How to understand the sentence which I distinguish with a red rectangle?

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.