Variable length procedure locals #999
Replies: 1 comment
-
This could be interesting, though we should think through the mechanics of how this can be implemented in the VM, and also consider what other alternatives (e.g., proper heap memory) could be used instead. For context, the current approach is modeled after WASM where a function can have a fixed number of locals and all dynamic memory management is left to the user code. Assuming we want to support a new instruction which allows to dynamically increase the number of locals (e.g.,
Both of these approaches have tradeoffs and we'll need to think through them. |
Beta Was this translation helpful? Give feedback.
-
Currently the number of locals of a procedure is static, and defined during the procedure declaration. This does enable one use-case: It allows procedures to use more than 16 elements of state by spilling data to memory, without cloberring state from the rest of the VM.
I think that is useful for procedures generated by an optimizing compiler, were multiple procedures are inlined and a larger number of registers are necessary. However this is limited to a predetermined size, defined at assembly time, meaning that variable length data, which could be provided by non-deterministic inputs, or from some recursive algorithms over variable length data, don't fit neatly on this model.
Since the opcodes are implements by a pointer register, if we can make a few modifications to the features I think it would be useful on more situations. Here are the changes I propose:
Beta Was this translation helpful? Give feedback.
All reactions