You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 3, 2021. It is now read-only.
Instead of providing "pick" or "let" instructions, I propose providing a "frame" block instruction (effectively providing frame-pointer like access to the wasm stack, similar to what happens for the "call" instruction), eg:
instead of:
i32.const 100 ;; push some values onto stack
i32.const 200
i32.const 300
pick 2 ;; result is 100
you would have:
i32.const 100 ;; push some values onto stack like an inline function call
i32.const 200
i32.const 300
frame param(i32 i32 i32) result(i32)
;; above 3 stack values are now locals 0,1,2 (equivalent to a call into an inlined function)
getlocal 0 ;; result is 100
end
;; stack frame is torn down, and all associated param values (100,200,300) are dropped from stack
;; (equivalent to return from an inline function)
Advantages over "pick" and "let":
consistent with wasm semantics of call/getlocal (whereas "pick" provides a parallel system of random access to local data, which overlaps with getlocal, but is not consistent with it)
can be used to inline functions - can just copy inlined function bytecode into a function call site
easier for humans to follow when reading/writing assembly code, as frame offsets are fixed (eg. getlocal 0 is always 1st param), whereas the index used with pick varies with each subsequent stack manipulation instruction
Disadvantages:
potentially increases instruction count by 2 compared to "pick", due to need enter a "frame" block before accessing local data, and then "end" block afterwards
(however, no additional instruction count, if "frame"/"end" is replacing a "block"/"end" instruction pair that needs to be there anyway)
(also, if used after a multi-value return, "pick" does not remove the returned values and hence needs multiple "drop" instructions after processing of return values is completed - whereas "frame"/"end" will tear down the stack values supplied as input into "frame", without any additional instructions)
inside the "frame" block, can't access locals which were defined outside the block, unless these are passed in as parameters
Instead of providing "pick" or "let" instructions, I propose providing a "frame" block instruction (effectively providing frame-pointer like access to the wasm stack, similar to what happens for the "call" instruction), eg:
instead of:
i32.const 100 ;; push some values onto stack
i32.const 200
i32.const 300
pick 2 ;; result is 100
you would have:
i32.const 100 ;; push some values onto stack like an inline function call
i32.const 200
i32.const 300
frame param(i32 i32 i32) result(i32)
;; above 3 stack values are now locals 0,1,2 (equivalent to a call into an inlined function)
getlocal 0 ;; result is 100
end
;; stack frame is torn down, and all associated param values (100,200,300) are dropped from stack
;; (equivalent to return from an inline function)
Advantages over "pick" and "let":
Disadvantages:
(however, no additional instruction count, if "frame"/"end" is replacing a "block"/"end" instruction pair that needs to be there anyway)
(also, if used after a multi-value return, "pick" does not remove the returned values and hence needs multiple "drop" instructions after processing of return values is completed - whereas "frame"/"end" will tear down the stack values supplied as input into "frame", without any additional instructions)