mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:27:35 +00:00
LibJS: More properly implement scoping rules in bytecode codegen
Now we emit CreateVariable and SetVariable with the appropriate initialization/environment modes, much closer to the spec. This makes a whole lot of things like let/const variables, function and variable hoisting and some other things work :^)
This commit is contained in:
parent
c7e6b65fd2
commit
1bbfaf8627
12 changed files with 503 additions and 38 deletions
|
@ -18,7 +18,11 @@
|
|||
|
||||
namespace JS::Bytecode {
|
||||
|
||||
using RegisterWindow = Vector<Value>;
|
||||
struct RegisterWindow {
|
||||
MarkedVector<Value> registers;
|
||||
MarkedVector<Environment*> saved_lexical_environments;
|
||||
MarkedVector<Environment*> saved_variable_environments;
|
||||
};
|
||||
|
||||
class Interpreter {
|
||||
public:
|
||||
|
@ -48,6 +52,9 @@ public:
|
|||
Value& reg(Register const& r) { return registers()[r.index()]; }
|
||||
[[nodiscard]] RegisterWindow snapshot_frame() const { return m_register_windows.last(); }
|
||||
|
||||
auto& saved_lexical_environment_stack() { return m_register_windows.last().saved_lexical_environments; }
|
||||
auto& saved_variable_environment_stack() { return m_register_windows.last().saved_variable_environments; }
|
||||
|
||||
void enter_frame(RegisterWindow const& frame)
|
||||
{
|
||||
m_manually_entered_frames.append(true);
|
||||
|
@ -82,7 +89,7 @@ public:
|
|||
VM::InterpreterExecutionScope ast_interpreter_scope();
|
||||
|
||||
private:
|
||||
RegisterWindow& registers() { return m_register_windows.last(); }
|
||||
MarkedVector<Value>& registers() { return m_register_windows.last().registers; }
|
||||
|
||||
static AK::Array<OwnPtr<PassManager>, static_cast<UnderlyingType<Interpreter::OptimizationLevel>>(Interpreter::OptimizationLevel::__Count)> s_optimization_pipelines;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue