-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(vm): Reimplement FunctionDeclarationInstantiation as part of function compilation #402
Merged
andreubotella
merged 3 commits into
trynova:main
from
andreubotella:bytecode-function-declaration-instantiation
Aug 25, 2024
Merged
feat(vm): Reimplement FunctionDeclarationInstantiation as part of function compilation #402
andreubotella
merged 3 commits into
trynova:main
from
andreubotella:bytecode-function-declaration-instantiation
Aug 25, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aapoalas
previously approved these changes
Aug 25, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One word: Awesome!
nova_vm/src/engine/bytecode/executable/function_declaration_instantiation.rs
Show resolved
Hide resolved
nova_vm/src/engine/bytecode/executable/function_declaration_instantiation.rs
Show resolved
Hide resolved
nova_vm/src/engine/bytecode/executable/function_declaration_instantiation.rs
Show resolved
Hide resolved
nova_vm/src/engine/bytecode/executable/function_declaration_instantiation.rs
Show resolved
Hide resolved
…ction compilation FunctionDeclarationInstantiation is an abstract operation in the spec which runs at the start of a function call and sets up the parameters, lexical environments and variables for the function. Until now, we implemented it as a Rust function called before the function body was executed. Since this operation is not implemented using bytecode, and it binds the function arguments, it couldn't support complex bindings (such as default values or object/array bindings) without reimplementing them. This patch therefore instead implements this operation as bytecode instructions emitted before the function body. That way the binding of arguments can be compiled into a regular array binding pattern. Doing this requires some way to pass the arguments into the VM, and have them stored in its state until they are evaluated. We do this by having `Vm::execute` take an optional arguments slice, which it stores on the iterator stack. For generators, currently FunctionDeclarationInstantiation happens when the generator function is called, and this patch moves it to when the generator object is first resumed, which is correct. However, this means that the arguments must be stored until that first time the generator is resumed. To do this, the `Option<Vm>` field in `GeneratorState::Suspended` is made into an enum which can store either a `Vm` or a boxed slice of arguments.
andreubotella
force-pushed
the
bytecode-function-declaration-instantiation
branch
from
August 25, 2024 18:44
b94dc2e
to
83e89ac
Compare
aapoalas
previously approved these changes
Aug 25, 2024
aapoalas
approved these changes
Aug 25, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
FunctionDeclarationInstantiation is an abstract operation in the spec which runs at the start of a function call and sets up the parameters, lexical environments and variables for the function. Until now, we implemented it as a Rust function called before the function body was executed.
Since this operation is not implemented using bytecode, and it binds the function arguments, it couldn't support complex bindings (such as default values or object/array bindings) without reimplementing them.
This patch therefore instead implements this operation as bytecode instructions emitted before the function body. That way the binding of arguments can be compiled into a regular array binding pattern.
Doing this requires some way to pass the arguments into the VM, and have them stored in its state until they are evaluated. We do this by having
Vm::execute
take an optional arguments slice, which it stores on the iterator stack.For generators, currently FunctionDeclarationInstantiation happens when the generator function is called, and this patch moves it to when the generator object is first resumed, which is correct. However, this means that the arguments must be stored until that first time the generator is resumed. To do this, the
Option<Vm>
field inGeneratorState::Suspended
is made into an enum which can store either aVm
or a boxed slice of arguments.This PR builds on top of #398, #399, #400 and #401, do not merge before those.