mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:28:12 +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 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/FlyString.h>
|
||||
#include <LibJS/Bytecode/Instruction.h>
|
||||
#include <LibJS/Bytecode/Register.h>
|
||||
#include <LibJS/Heap/Cell.h>
|
||||
|
@ -49,4 +50,55 @@ private:
|
|||
Register m_src2;
|
||||
};
|
||||
|
||||
class NewString final : public Instruction {
|
||||
public:
|
||||
NewString(Register dst, String string)
|
||||
: m_dst(dst)
|
||||
, m_string(move(string))
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~NewString() override { }
|
||||
virtual void execute(Bytecode::Interpreter&) const override;
|
||||
virtual String to_string() const override;
|
||||
|
||||
private:
|
||||
Register m_dst;
|
||||
String m_string;
|
||||
};
|
||||
|
||||
class SetVariable final : public Instruction {
|
||||
public:
|
||||
SetVariable(FlyString identifier, Register src)
|
||||
: m_identifier(move(identifier))
|
||||
, m_src(src)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~SetVariable() override { }
|
||||
virtual void execute(Bytecode::Interpreter&) const override;
|
||||
virtual String to_string() const override;
|
||||
|
||||
private:
|
||||
FlyString m_identifier;
|
||||
Register m_src;
|
||||
};
|
||||
|
||||
class GetVariable final : public Instruction {
|
||||
public:
|
||||
GetVariable(Register dst, FlyString identifier)
|
||||
: m_dst(dst)
|
||||
, m_identifier(move(identifier))
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~GetVariable() override { }
|
||||
virtual void execute(Bytecode::Interpreter&) const override;
|
||||
virtual String to_string() const override;
|
||||
|
||||
private:
|
||||
Register m_dst;
|
||||
FlyString m_identifier;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue