mirror of
https://github.com/RGBCube/serenity
synced 2025-06-30 19:32:11 +00:00
LibJS: Some more opcodes for the bytecode VM
- NewString (allocates a new PrimitiveString from the GC heap) - GetVariable (retrieves a variable in the current scope) - SetVariable (assigns a variable in the current scope)
This commit is contained in:
parent
6da5d17416
commit
37cb70836b
4 changed files with 113 additions and 0 deletions
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <LibJS/Bytecode/Interpreter.h>
|
||||
#include <LibJS/Bytecode/Op.h>
|
||||
#include <LibJS/Runtime/GlobalObject.h>
|
||||
#include <LibJS/Runtime/Value.h>
|
||||
|
||||
namespace JS::Bytecode::Op {
|
||||
|
@ -20,6 +21,21 @@ void Add::execute(Bytecode::Interpreter& interpreter) const
|
|||
interpreter.reg(m_dst) = add(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2));
|
||||
}
|
||||
|
||||
void NewString::execute(Bytecode::Interpreter& interpreter) const
|
||||
{
|
||||
interpreter.reg(m_dst) = js_string(interpreter.vm(), m_string);
|
||||
}
|
||||
|
||||
void GetVariable::execute(Bytecode::Interpreter& interpreter) const
|
||||
{
|
||||
interpreter.reg(m_dst) = interpreter.vm().get_variable(m_identifier, interpreter.global_object());
|
||||
}
|
||||
|
||||
void SetVariable::execute(Bytecode::Interpreter& interpreter) const
|
||||
{
|
||||
interpreter.vm().set_variable(m_identifier, interpreter.reg(m_src), interpreter.global_object());
|
||||
}
|
||||
|
||||
String Load::to_string() const
|
||||
{
|
||||
return String::formatted("Load dst:r{}, value:{}", m_dst.index(), m_value.to_string_without_side_effects());
|
||||
|
@ -30,4 +46,19 @@ String Add::to_string() const
|
|||
return String::formatted("Add dst:r{}, src1:r{}, src2:r{}", m_dst.index(), m_src1.index(), m_src2.index());
|
||||
}
|
||||
|
||||
String NewString::to_string() const
|
||||
{
|
||||
return String::formatted("NewString dst:r{}, string:\"{}\"", m_dst.index(), m_string);
|
||||
}
|
||||
|
||||
String GetVariable::to_string() const
|
||||
{
|
||||
return String::formatted("GetVariable dst:r{}, identifier:{}", m_dst.index(), m_identifier);
|
||||
}
|
||||
|
||||
String SetVariable::to_string() const
|
||||
{
|
||||
return String::formatted("SetVariable identifier:{}, src:r{}", m_identifier, m_src.index());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue