2021-06-03 08:46:30 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Forward.h>
|
|
|
|
#include <LibJS/Forward.h>
|
|
|
|
|
2021-06-07 13:12:43 +00:00
|
|
|
#define ENUMERATE_BYTECODE_OPS(O) \
|
|
|
|
O(Load) \
|
|
|
|
O(Add) \
|
|
|
|
O(Sub) \
|
2021-06-07 17:17:20 +00:00
|
|
|
O(Mul) \
|
|
|
|
O(Div) \
|
2021-06-07 17:37:23 +00:00
|
|
|
O(Mod) \
|
|
|
|
O(Exp) \
|
2021-06-07 17:57:38 +00:00
|
|
|
O(GreaterThan) \
|
|
|
|
O(GreaterThanEquals) \
|
2021-06-07 13:12:43 +00:00
|
|
|
O(LessThan) \
|
2021-06-07 17:57:38 +00:00
|
|
|
O(LessThanEquals) \
|
2021-06-07 13:12:43 +00:00
|
|
|
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) \
|
2021-06-07 18:16:04 +00:00
|
|
|
O(Return) \
|
|
|
|
O(BitwiseAnd) \
|
|
|
|
O(BitwiseOr) \
|
2021-06-07 18:53:47 +00:00
|
|
|
O(BitwiseXor) \
|
|
|
|
O(BitwiseNot) \
|
|
|
|
O(Not) \
|
|
|
|
O(UnaryPlus) \
|
|
|
|
O(UnaryMinus) \
|
|
|
|
O(Typeof)
|
2021-06-07 13:12:43 +00:00
|
|
|
|
2021-06-03 08:46:30 +00:00
|
|
|
namespace JS::Bytecode {
|
|
|
|
|
|
|
|
class Instruction {
|
|
|
|
public:
|
2021-06-07 13:12:43 +00:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
}
|
2021-06-03 08:46:30 +00:00
|
|
|
|
2021-06-07 13:12:43 +00:00
|
|
|
private:
|
|
|
|
Type m_type {};
|
2021-06-03 08:46:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|