mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 16:07:35 +00:00
LibJS: NewClass bytecode instruction
This adds a the NewClass bytecode instruction, enough of it is implemented for it to show it in the bytecode (js -d).
This commit is contained in:
parent
3694b8b690
commit
f6028c2534
6 changed files with 37 additions and 1 deletions
|
@ -851,6 +851,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
StringView name() const { return m_name; }
|
StringView name() const { return m_name; }
|
||||||
|
RefPtr<FunctionExpression> constructor() const { return m_constructor; }
|
||||||
|
|
||||||
virtual Value execute(Interpreter&, GlobalObject&) const override;
|
virtual Value execute(Interpreter&, GlobalObject&) const override;
|
||||||
virtual void dump(int indent) const override;
|
virtual void dump(int indent) const override;
|
||||||
|
@ -872,6 +873,7 @@ public:
|
||||||
|
|
||||||
virtual Value execute(Interpreter&, GlobalObject&) const override;
|
virtual Value execute(Interpreter&, GlobalObject&) const override;
|
||||||
virtual void dump(int indent) const override;
|
virtual void dump(int indent) const override;
|
||||||
|
virtual void generate_bytecode(Bytecode::Generator&) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NonnullRefPtr<ClassExpression> m_class_expression;
|
NonnullRefPtr<ClassExpression> m_class_expression;
|
||||||
|
|
|
@ -1300,4 +1300,10 @@ void SwitchStatement::generate_bytecode(Bytecode::Generator& generator) const
|
||||||
generator.switch_to_basic_block(end_block);
|
generator.switch_to_basic_block(end_block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ClassDeclaration::generate_bytecode(Bytecode::Generator& generator) const
|
||||||
|
{
|
||||||
|
generator.emit<Bytecode::Op::NewClass>(m_class_expression);
|
||||||
|
generator.emit<Bytecode::Op::SetVariable>(generator.intern_string(m_class_expression.ptr()->name()));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,8 @@
|
||||||
O(GetIterator) \
|
O(GetIterator) \
|
||||||
O(IteratorNext) \
|
O(IteratorNext) \
|
||||||
O(IteratorResultDone) \
|
O(IteratorResultDone) \
|
||||||
O(IteratorResultValue)
|
O(IteratorResultValue) \
|
||||||
|
O(NewClass)
|
||||||
|
|
||||||
namespace JS::Bytecode {
|
namespace JS::Bytecode {
|
||||||
|
|
||||||
|
|
|
@ -452,6 +452,11 @@ void IteratorResultValue::execute_impl(Bytecode::Interpreter& interpreter) const
|
||||||
interpreter.accumulator() = iterator_value(interpreter.global_object(), *iterator_result);
|
interpreter.accumulator() = iterator_value(interpreter.global_object(), *iterator_result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NewClass::execute_impl(Bytecode::Interpreter&) const
|
||||||
|
{
|
||||||
|
TODO();
|
||||||
|
}
|
||||||
|
|
||||||
String Load::to_string_impl(Bytecode::Executable const&) const
|
String Load::to_string_impl(Bytecode::Executable const&) const
|
||||||
{
|
{
|
||||||
return String::formatted("Load {}", m_src);
|
return String::formatted("Load {}", m_src);
|
||||||
|
@ -598,6 +603,11 @@ String NewFunction::to_string_impl(Bytecode::Executable const&) const
|
||||||
return "NewFunction";
|
return "NewFunction";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String NewClass::to_string_impl(Bytecode::Executable const&) const
|
||||||
|
{
|
||||||
|
return "NewClass";
|
||||||
|
}
|
||||||
|
|
||||||
String Return::to_string_impl(Bytecode::Executable const&) const
|
String Return::to_string_impl(Bytecode::Executable const&) const
|
||||||
{
|
{
|
||||||
return "Return";
|
return "Return";
|
||||||
|
|
|
@ -484,6 +484,22 @@ private:
|
||||||
Register m_arguments[];
|
Register m_arguments[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class NewClass final : public Instruction {
|
||||||
|
public:
|
||||||
|
explicit NewClass(ClassExpression const& class_expression)
|
||||||
|
: Instruction(Type::NewClass)
|
||||||
|
, m_class_expression(class_expression)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void execute_impl(Bytecode::Interpreter&) const;
|
||||||
|
String to_string_impl(Bytecode::Executable const&) const;
|
||||||
|
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
||||||
|
|
||||||
|
private:
|
||||||
|
ClassExpression const& m_class_expression;
|
||||||
|
};
|
||||||
|
|
||||||
class NewFunction final : public Instruction {
|
class NewFunction final : public Instruction {
|
||||||
public:
|
public:
|
||||||
explicit NewFunction(FunctionNode const& function_node)
|
explicit NewFunction(FunctionNode const& function_node)
|
||||||
|
|
|
@ -119,6 +119,7 @@ class BigInt;
|
||||||
class BoundFunction;
|
class BoundFunction;
|
||||||
class Cell;
|
class Cell;
|
||||||
class CellAllocator;
|
class CellAllocator;
|
||||||
|
class ClassExpression;
|
||||||
class Console;
|
class Console;
|
||||||
class DeclarativeEnvironment;
|
class DeclarativeEnvironment;
|
||||||
class DeferGC;
|
class DeferGC;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue