mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:07:35 +00:00
LibJS: Introduce an accumulator register to Bytecode::Interpreter
This commit introduces the concept of an accumulator register to LibJS's bytecode interpreter. The accumulator register is always register 0, and most simple instructions use it for reading and writing. Not only does this slim down the AST, but it also simplifies a lot of the code. For example, the generate_bytecode methods no longer need to return an Optional<Register>, as any opcode which has a "return" value will always put it into the accumulator. This also renames the old Op::Load to Op::LoadImmediate, and uses Op::Load to load from a register into the accumulator. There is also an Op::Store to put the value in the accumulator into another register.
This commit is contained in:
parent
6c256bb400
commit
9bed2e4f4a
8 changed files with 377 additions and 432 deletions
|
@ -37,7 +37,7 @@ class ASTNode : public RefCounted<ASTNode> {
|
|||
public:
|
||||
virtual ~ASTNode() { }
|
||||
virtual Value execute(Interpreter&, GlobalObject&) const = 0;
|
||||
virtual Optional<Bytecode::Register> generate_bytecode(Bytecode::Generator&) const;
|
||||
virtual void generate_bytecode(Bytecode::Generator&) const;
|
||||
virtual void dump(int indent) const;
|
||||
|
||||
const SourceRange& source_range() const { return m_source_range; }
|
||||
|
@ -76,7 +76,7 @@ public:
|
|||
{
|
||||
}
|
||||
Value execute(Interpreter&, GlobalObject&) const override { return {}; }
|
||||
virtual Optional<Bytecode::Register> generate_bytecode(Bytecode::Generator&) const override;
|
||||
virtual void generate_bytecode(Bytecode::Generator&) const override;
|
||||
};
|
||||
|
||||
class ErrorStatement final : public Statement {
|
||||
|
@ -98,7 +98,7 @@ public:
|
|||
|
||||
virtual Value execute(Interpreter&, GlobalObject&) const override;
|
||||
virtual void dump(int indent) const override;
|
||||
virtual Optional<Bytecode::Register> generate_bytecode(Bytecode::Generator&) const override;
|
||||
virtual void generate_bytecode(Bytecode::Generator&) const override;
|
||||
|
||||
const Expression& expression() const { return m_expression; };
|
||||
|
||||
|
@ -123,7 +123,7 @@ public:
|
|||
const NonnullRefPtrVector<Statement>& children() const { return m_children; }
|
||||
virtual Value execute(Interpreter&, GlobalObject&) const override;
|
||||
virtual void dump(int indent) const override;
|
||||
virtual Optional<Bytecode::Register> generate_bytecode(Bytecode::Generator&) const override;
|
||||
virtual void generate_bytecode(Bytecode::Generator&) const override;
|
||||
|
||||
void add_variables(NonnullRefPtrVector<VariableDeclaration>);
|
||||
void add_functions(NonnullRefPtrVector<FunctionDeclaration>);
|
||||
|
@ -273,7 +273,7 @@ public:
|
|||
|
||||
virtual Value execute(Interpreter&, GlobalObject&) const override;
|
||||
virtual void dump(int indent) const override;
|
||||
virtual Optional<Bytecode::Register> generate_bytecode(Bytecode::Generator&) const override;
|
||||
virtual void generate_bytecode(Bytecode::Generator&) const override;
|
||||
};
|
||||
|
||||
class FunctionExpression final
|
||||
|
@ -330,7 +330,7 @@ public:
|
|||
|
||||
virtual Value execute(Interpreter&, GlobalObject&) const override;
|
||||
virtual void dump(int indent) const override;
|
||||
virtual Optional<Bytecode::Register> generate_bytecode(Bytecode::Generator&) const override;
|
||||
virtual void generate_bytecode(Bytecode::Generator&) const override;
|
||||
|
||||
private:
|
||||
RefPtr<Expression> m_argument;
|
||||
|
@ -352,7 +352,7 @@ public:
|
|||
|
||||
virtual Value execute(Interpreter&, GlobalObject&) const override;
|
||||
virtual void dump(int indent) const override;
|
||||
virtual Optional<Bytecode::Register> generate_bytecode(Bytecode::Generator&) const override;
|
||||
virtual void generate_bytecode(Bytecode::Generator&) const override;
|
||||
|
||||
private:
|
||||
NonnullRefPtr<Expression> m_predicate;
|
||||
|
@ -374,7 +374,7 @@ public:
|
|||
|
||||
virtual Value execute(Interpreter&, GlobalObject&) const override;
|
||||
virtual void dump(int indent) const override;
|
||||
virtual Optional<Bytecode::Register> generate_bytecode(Bytecode::Generator&) const override;
|
||||
virtual void generate_bytecode(Bytecode::Generator&) const override;
|
||||
|
||||
private:
|
||||
NonnullRefPtr<Expression> m_test;
|
||||
|
@ -395,7 +395,7 @@ public:
|
|||
|
||||
virtual Value execute(Interpreter&, GlobalObject&) const override;
|
||||
virtual void dump(int indent) const override;
|
||||
virtual Optional<Bytecode::Register> generate_bytecode(Bytecode::Generator&) const override;
|
||||
virtual void generate_bytecode(Bytecode::Generator&) const override;
|
||||
|
||||
private:
|
||||
NonnullRefPtr<Expression> m_test;
|
||||
|
@ -440,7 +440,7 @@ public:
|
|||
|
||||
virtual Value execute(Interpreter&, GlobalObject&) const override;
|
||||
virtual void dump(int indent) const override;
|
||||
virtual Optional<Bytecode::Register> generate_bytecode(Bytecode::Generator&) const override;
|
||||
virtual void generate_bytecode(Bytecode::Generator&) const override;
|
||||
|
||||
private:
|
||||
RefPtr<ASTNode> m_init;
|
||||
|
@ -532,7 +532,7 @@ public:
|
|||
|
||||
virtual Value execute(Interpreter&, GlobalObject&) const override;
|
||||
virtual void dump(int indent) const override;
|
||||
virtual Optional<Bytecode::Register> generate_bytecode(Bytecode::Generator&) const override;
|
||||
virtual void generate_bytecode(Bytecode::Generator&) const override;
|
||||
|
||||
private:
|
||||
BinaryOp m_op;
|
||||
|
@ -558,7 +558,7 @@ public:
|
|||
|
||||
virtual Value execute(Interpreter&, GlobalObject&) const override;
|
||||
virtual void dump(int indent) const override;
|
||||
virtual Optional<Bytecode::Register> generate_bytecode(Bytecode::Generator&) const override;
|
||||
virtual void generate_bytecode(Bytecode::Generator&) const override;
|
||||
|
||||
private:
|
||||
LogicalOp m_op;
|
||||
|
@ -587,7 +587,7 @@ public:
|
|||
|
||||
virtual Value execute(Interpreter&, GlobalObject&) const override;
|
||||
virtual void dump(int indent) const override;
|
||||
virtual Optional<Bytecode::Register> generate_bytecode(Bytecode::Generator&) const override;
|
||||
virtual void generate_bytecode(Bytecode::Generator&) const override;
|
||||
|
||||
private:
|
||||
UnaryOp m_op;
|
||||
|
@ -605,7 +605,7 @@ public:
|
|||
|
||||
virtual void dump(int indent) const override;
|
||||
virtual Value execute(Interpreter&, GlobalObject&) const override;
|
||||
virtual Optional<Bytecode::Register> generate_bytecode(Bytecode::Generator&) const override;
|
||||
virtual void generate_bytecode(Bytecode::Generator&) const override;
|
||||
|
||||
private:
|
||||
NonnullRefPtrVector<Expression> m_expressions;
|
||||
|
@ -629,7 +629,7 @@ public:
|
|||
|
||||
virtual Value execute(Interpreter&, GlobalObject&) const override;
|
||||
virtual void dump(int indent) const override;
|
||||
virtual Optional<Bytecode::Register> generate_bytecode(Bytecode::Generator&) const override;
|
||||
virtual void generate_bytecode(Bytecode::Generator&) const override;
|
||||
|
||||
private:
|
||||
bool m_value { false };
|
||||
|
@ -645,7 +645,7 @@ public:
|
|||
|
||||
virtual Value execute(Interpreter&, GlobalObject&) const override;
|
||||
virtual void dump(int indent) const override;
|
||||
virtual Optional<Bytecode::Register> generate_bytecode(Bytecode::Generator&) const override;
|
||||
virtual void generate_bytecode(Bytecode::Generator&) const override;
|
||||
|
||||
private:
|
||||
Value m_value;
|
||||
|
@ -661,7 +661,7 @@ public:
|
|||
|
||||
virtual Value execute(Interpreter&, GlobalObject&) const override;
|
||||
virtual void dump(int indent) const override;
|
||||
virtual Optional<Bytecode::Register> generate_bytecode(Bytecode::Generator&) const override;
|
||||
virtual void generate_bytecode(Bytecode::Generator&) const override;
|
||||
|
||||
private:
|
||||
String m_value;
|
||||
|
@ -678,7 +678,7 @@ public:
|
|||
|
||||
virtual Value execute(Interpreter&, GlobalObject&) const override;
|
||||
virtual void dump(int indent) const override;
|
||||
virtual Optional<Bytecode::Register> generate_bytecode(Bytecode::Generator&) const override;
|
||||
virtual void generate_bytecode(Bytecode::Generator&) const override;
|
||||
|
||||
StringView value() const { return m_value; }
|
||||
bool is_use_strict_directive() const { return m_is_use_strict_directive; };
|
||||
|
@ -697,7 +697,7 @@ public:
|
|||
|
||||
virtual Value execute(Interpreter&, GlobalObject&) const override;
|
||||
virtual void dump(int indent) const override;
|
||||
virtual Optional<Bytecode::Register> generate_bytecode(Bytecode::Generator&) const override;
|
||||
virtual void generate_bytecode(Bytecode::Generator&) const override;
|
||||
};
|
||||
|
||||
class RegExpLiteral final : public Literal {
|
||||
|
@ -733,7 +733,7 @@ public:
|
|||
virtual Value execute(Interpreter&, GlobalObject&) const override;
|
||||
virtual void dump(int indent) const override;
|
||||
virtual Reference to_reference(Interpreter&, GlobalObject&) const override;
|
||||
virtual Optional<Bytecode::Register> generate_bytecode(Bytecode::Generator&) const override;
|
||||
virtual void generate_bytecode(Bytecode::Generator&) const override;
|
||||
|
||||
private:
|
||||
FlyString m_string;
|
||||
|
@ -860,7 +860,7 @@ public:
|
|||
|
||||
virtual Value execute(Interpreter&, GlobalObject&) const override;
|
||||
virtual void dump(int indent) const override;
|
||||
virtual Optional<Bytecode::Register> generate_bytecode(Bytecode::Generator&) const override;
|
||||
virtual void generate_bytecode(Bytecode::Generator&) const override;
|
||||
|
||||
private:
|
||||
struct ThisAndCallee {
|
||||
|
@ -912,7 +912,7 @@ public:
|
|||
|
||||
virtual Value execute(Interpreter&, GlobalObject&) const override;
|
||||
virtual void dump(int indent) const override;
|
||||
virtual Optional<Bytecode::Register> generate_bytecode(Bytecode::Generator&) const override;
|
||||
virtual void generate_bytecode(Bytecode::Generator&) const override;
|
||||
|
||||
private:
|
||||
AssignmentOp m_op;
|
||||
|
@ -1052,7 +1052,7 @@ public:
|
|||
|
||||
virtual Value execute(Interpreter&, GlobalObject&) const override;
|
||||
virtual void dump(int indent) const override;
|
||||
virtual Optional<Bytecode::Register> generate_bytecode(Bytecode::Generator&) const override;
|
||||
virtual void generate_bytecode(Bytecode::Generator&) const override;
|
||||
|
||||
private:
|
||||
NonnullRefPtrVector<ObjectProperty> m_properties;
|
||||
|
@ -1092,7 +1092,7 @@ public:
|
|||
|
||||
virtual Value execute(Interpreter&, GlobalObject&) const override;
|
||||
virtual void dump(int indent) const override;
|
||||
virtual Optional<Bytecode::Register> generate_bytecode(Bytecode::Generator&) const override;
|
||||
virtual void generate_bytecode(Bytecode::Generator&) const override;
|
||||
|
||||
const NonnullRefPtrVector<Expression>& expressions() const { return m_expressions; }
|
||||
const NonnullRefPtrVector<Expression>& raw_strings() const { return m_raw_strings; }
|
||||
|
@ -1132,7 +1132,7 @@ public:
|
|||
virtual Value execute(Interpreter&, GlobalObject&) const override;
|
||||
virtual void dump(int indent) const override;
|
||||
virtual Reference to_reference(Interpreter&, GlobalObject&) const override;
|
||||
virtual Optional<Bytecode::Register> generate_bytecode(Bytecode::Generator&) const override;
|
||||
virtual void generate_bytecode(Bytecode::Generator&) const override;
|
||||
|
||||
bool is_computed() const { return m_computed; }
|
||||
const Expression& object() const { return *m_object; }
|
||||
|
@ -1180,7 +1180,7 @@ public:
|
|||
|
||||
virtual void dump(int indent) const override;
|
||||
virtual Value execute(Interpreter&, GlobalObject&) const override;
|
||||
virtual Optional<Bytecode::Register> generate_bytecode(Bytecode::Generator&) const override;
|
||||
virtual void generate_bytecode(Bytecode::Generator&) const override;
|
||||
|
||||
private:
|
||||
NonnullRefPtr<Expression> m_test;
|
||||
|
@ -1310,7 +1310,7 @@ public:
|
|||
}
|
||||
|
||||
virtual Value execute(Interpreter&, GlobalObject&) const override;
|
||||
virtual Optional<Bytecode::Register> generate_bytecode(Bytecode::Generator&) const override;
|
||||
virtual void generate_bytecode(Bytecode::Generator&) const override;
|
||||
|
||||
const FlyString& target_label() const { return m_target_label; }
|
||||
|
||||
|
@ -1326,7 +1326,7 @@ public:
|
|||
}
|
||||
|
||||
virtual Value execute(Interpreter&, GlobalObject&) const override;
|
||||
virtual Optional<Bytecode::Register> generate_bytecode(Bytecode::Generator&) const override;
|
||||
virtual void generate_bytecode(Bytecode::Generator&) const override;
|
||||
};
|
||||
|
||||
template<typename C>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue