mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 15:08:12 +00:00
LibJS: Update bytecode generator to use local variables
- Update ECMAScriptFunctionObject::function_declaration_instantiation to initialize local variables - Introduce GetLocal, SetLocal, TypeofLocal that will be used to operate on local variables. - Update bytecode generator to emit instructions for local variables
This commit is contained in:
parent
0daff637e2
commit
ae3a7fd4b8
8 changed files with 170 additions and 37 deletions
|
@ -141,7 +141,7 @@ CodeGenerationErrorOr<void> Generator::emit_load_from_reference(JS::ASTNode cons
|
|||
{
|
||||
if (is<Identifier>(node)) {
|
||||
auto& identifier = static_cast<Identifier const&>(node);
|
||||
emit<Bytecode::Op::GetVariable>(intern_identifier(identifier.string()));
|
||||
TRY(identifier.generate_bytecode(*this));
|
||||
return {};
|
||||
}
|
||||
if (is<MemberExpression>(node)) {
|
||||
|
@ -217,7 +217,7 @@ CodeGenerationErrorOr<void> Generator::emit_store_to_reference(JS::ASTNode const
|
|||
{
|
||||
if (is<Identifier>(node)) {
|
||||
auto& identifier = static_cast<Identifier const&>(node);
|
||||
emit<Bytecode::Op::SetVariable>(intern_identifier(identifier.string()));
|
||||
emit_set_variable(identifier);
|
||||
return {};
|
||||
}
|
||||
if (is<MemberExpression>(node)) {
|
||||
|
@ -306,6 +306,15 @@ CodeGenerationErrorOr<void> Generator::emit_delete_reference(JS::ASTNode const&
|
|||
return {};
|
||||
}
|
||||
|
||||
void Generator::emit_set_variable(JS::Identifier const& identifier, Bytecode::Op::SetVariable::InitializationMode initialization_mode, Bytecode::Op::EnvironmentMode mode)
|
||||
{
|
||||
if (identifier.is_local()) {
|
||||
emit<Bytecode::Op::SetLocal>(identifier.local_variable_index());
|
||||
} else {
|
||||
emit<Bytecode::Op::SetVariable>(intern_identifier(identifier.string()), initialization_mode, mode);
|
||||
}
|
||||
}
|
||||
|
||||
void Generator::generate_break()
|
||||
{
|
||||
bool last_was_finally = false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue