mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 18:25:07 +00:00

This patch changes the LibJS bytecode to be a stream of instructions packed one-after-the-other in contiguous memory, instead of a vector of OwnPtr<Instruction>. This should be a lot more cache-friendly. :^) Instructions are also devirtualized and instead have a type field using a new Instruction::Type enum. To iterate over a bytecode stream, one must now use Bytecode::InstructionStreamIterator.
59 lines
1.3 KiB
C++
59 lines
1.3 KiB
C++
/*
|
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Forward.h>
|
|
#include <LibJS/Forward.h>
|
|
|
|
#define ENUMERATE_BYTECODE_OPS(O) \
|
|
O(Load) \
|
|
O(Add) \
|
|
O(Sub) \
|
|
O(LessThan) \
|
|
O(AbstractInequals) \
|
|
O(AbstractEquals) \
|
|
O(NewString) \
|
|
O(NewObject) \
|
|
O(GetVariable) \
|
|
O(SetVariable) \
|
|
O(PutById) \
|
|
O(GetById) \
|
|
O(Jump) \
|
|
O(JumpIfFalse) \
|
|
O(JumpIfTrue) \
|
|
O(Call) \
|
|
O(EnterScope) \
|
|
O(Return)
|
|
|
|
namespace JS::Bytecode {
|
|
|
|
class Instruction {
|
|
public:
|
|
enum class Type {
|
|
#define __BYTECODE_OP(op) \
|
|
op,
|
|
ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
|
|
#undef __BYTECODE_OP
|
|
};
|
|
|
|
Type type() const { return m_type; }
|
|
size_t length() const;
|
|
String to_string() const;
|
|
void execute(Bytecode::Interpreter&) const;
|
|
static void destroy(Instruction&);
|
|
|
|
protected:
|
|
explicit Instruction(Type type)
|
|
: m_type(type)
|
|
{
|
|
}
|
|
|
|
private:
|
|
Type m_type {};
|
|
};
|
|
|
|
}
|