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) \
|
2021-06-08 03:58:36 +00:00
|
|
|
O(LoadImmediate) \
|
|
|
|
O(Store) \
|
2021-06-07 13:12:43 +00:00
|
|
|
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) \
|
2021-06-07 18:39:47 +00:00
|
|
|
O(TypedInequals) \
|
|
|
|
O(TypedEquals) \
|
2021-06-08 05:59:25 +00:00
|
|
|
O(NewBigInt) \
|
2021-06-08 21:06:52 +00:00
|
|
|
O(NewArray) \
|
2021-06-07 13:12:43 +00:00
|
|
|
O(NewString) \
|
|
|
|
O(NewObject) \
|
|
|
|
O(GetVariable) \
|
|
|
|
O(SetVariable) \
|
|
|
|
O(PutById) \
|
|
|
|
O(GetById) \
|
2021-06-10 22:35:25 +00:00
|
|
|
O(PutByValue) \
|
|
|
|
O(GetByValue) \
|
2021-06-07 13:12:43 +00:00
|
|
|
O(Jump) \
|
2021-06-09 02:19:58 +00:00
|
|
|
O(JumpConditional) \
|
|
|
|
O(JumpNullish) \
|
2021-06-07 13:12:43 +00:00
|
|
|
O(Call) \
|
2021-06-09 22:49:23 +00:00
|
|
|
O(NewFunction) \
|
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) \
|
2021-06-07 19:14:12 +00:00
|
|
|
O(Typeof) \
|
|
|
|
O(LeftShift) \
|
|
|
|
O(RightShift) \
|
2021-06-07 20:13:37 +00:00
|
|
|
O(UnsignedRightShift) \
|
2021-06-07 20:18:19 +00:00
|
|
|
O(In) \
|
2021-06-08 03:58:36 +00:00
|
|
|
O(InstanceOf) \
|
2021-06-09 09:40:38 +00:00
|
|
|
O(ConcatString) \
|
|
|
|
O(Increment) \
|
2021-06-09 16:18:56 +00:00
|
|
|
O(Decrement) \
|
2021-06-10 13:04:38 +00:00
|
|
|
O(Throw) \
|
2021-06-10 20:12:21 +00:00
|
|
|
O(PushLexicalEnvironment) \
|
2021-06-14 07:37:35 +00:00
|
|
|
O(LoadArgument) \
|
2021-06-10 13:04:38 +00:00
|
|
|
O(EnterUnwindContext) \
|
|
|
|
O(LeaveUnwindContext) \
|
2021-06-10 21:08:30 +00:00
|
|
|
O(ContinuePendingUnwind) \
|
|
|
|
O(Yield)
|
2021-06-07 13:12:43 +00:00
|
|
|
|
2021-06-03 08:46:30 +00:00
|
|
|
namespace JS::Bytecode {
|
|
|
|
|
|
|
|
class Instruction {
|
|
|
|
public:
|
2021-06-09 02:19:58 +00:00
|
|
|
constexpr static bool IsTerminator = false;
|
|
|
|
|
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;
|
2021-06-09 08:02:01 +00:00
|
|
|
String to_string(Bytecode::Executable const&) const;
|
2021-06-07 13:12:43 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
}
|