diff --git a/AstSemantics.md b/AstSemantics.md index aff8b63e..1145bc65 100644 --- a/AstSemantics.md +++ b/AstSemantics.md @@ -213,10 +213,11 @@ instead expected release unused physical pages from the working set using the Each function has a fixed, pre-declared number of local variables which occupy a single index space local to the function. Parameters are addressed as local variables. Local -variables do not have addresses and are not aliased by linear memory. Local -variables have value types and are initialized to the appropriate zero value for their -type at the beginning of the function, except parameters which are initialized to the values -of the arguments passed to the function. +variables do not have addresses and are not aliased by linear memory. By doing so, local +variables become in essence virtual registers that may or not require a stack slot when +lowering to machine code. Local variables have value types and are initialized to the +appropriate zero value for their type at the beginning of the function, except parameters +which are initialized to the values of the arguments passed to the function. * `get_local`: read the current value of a local variable * `set_local`: set the current value of a local variable @@ -225,6 +226,9 @@ The details of index space for local variables and their types will be further c e.g. whether locals with type `i32` and `i64` must be contiguous and separate from others, etc. +Finally, because local variables can be seen as virtual registers, `get_local` and +`set_local` are not automatically going to be translated into load/store instructions. + ## Control flow structures WebAssembly offers basic structured control flow with the following constructs. diff --git a/Rationale.md b/Rationale.md index c73f8993..36b8ce13 100644 --- a/Rationale.md +++ b/Rationale.md @@ -173,6 +173,12 @@ producers can use to pre-color variables and give hints to a WebAssembly VM's register allocation algorithms, offloading some of the optimization work from the WebAssembly VM. +Finally, because it is not possible to take the address of the local variables, +one can see local variables as virtual registers that do not automatically +have a designated memory location for storing the temporary calculations. +WebAssembly locals therefore become whatever the code generator requires to generate +the code. In some cases, they might become a physical register. In other cases, +they might become a stack slot. ## Variable-Length Argument Lists