|
@@ -129,7 +129,11 @@ class OpCode;
|
|
|
|
|
|
class ByteCode : public Vector<ByteCodeValueType> {
|
|
class ByteCode : public Vector<ByteCodeValueType> {
|
|
public:
|
|
public:
|
|
- ByteCode() = default;
|
|
|
|
|
|
+ ByteCode()
|
|
|
|
+ {
|
|
|
|
+ ensure_opcodes_initialized();
|
|
|
|
+ }
|
|
|
|
+
|
|
ByteCode(const ByteCode&) = default;
|
|
ByteCode(const ByteCode&) = default;
|
|
virtual ~ByteCode() = default;
|
|
virtual ~ByteCode() = default;
|
|
|
|
|
|
@@ -449,6 +453,7 @@ private:
|
|
empend((ByteCodeValueType)view[i]);
|
|
empend((ByteCodeValueType)view[i]);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ void ensure_opcodes_initialized();
|
|
ALWAYS_INLINE OpCode& get_opcode_by_id(OpCodeId id) const;
|
|
ALWAYS_INLINE OpCode& get_opcode_by_id(OpCodeId id) const;
|
|
static OwnPtr<OpCode> s_opcodes[(size_t)OpCodeId::Last + 1];
|
|
static OwnPtr<OpCode> s_opcodes[(size_t)OpCodeId::Last + 1];
|
|
static bool s_opcodes_initialized;
|
|
static bool s_opcodes_initialized;
|
|
@@ -476,11 +481,7 @@ const char* execution_result_name(ExecutionResult result);
|
|
|
|
|
|
class OpCode {
|
|
class OpCode {
|
|
public:
|
|
public:
|
|
- OpCode(ByteCode& bytecode)
|
|
|
|
- : m_bytecode(&bytecode)
|
|
|
|
- {
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ OpCode() = default;
|
|
virtual ~OpCode() = default;
|
|
virtual ~OpCode() = default;
|
|
|
|
|
|
virtual OpCodeId opcode_id() const = 0;
|
|
virtual OpCodeId opcode_id() const = 0;
|
|
@@ -518,16 +519,12 @@ public:
|
|
ALWAYS_INLINE const ByteCode& bytecode() const { return *m_bytecode; }
|
|
ALWAYS_INLINE const ByteCode& bytecode() const { return *m_bytecode; }
|
|
|
|
|
|
protected:
|
|
protected:
|
|
- ByteCode* m_bytecode;
|
|
|
|
|
|
+ ByteCode* m_bytecode { nullptr };
|
|
Optional<MatchState*> m_state;
|
|
Optional<MatchState*> m_state;
|
|
};
|
|
};
|
|
|
|
|
|
class OpCode_Exit final : public OpCode {
|
|
class OpCode_Exit final : public OpCode {
|
|
public:
|
|
public:
|
|
- OpCode_Exit(ByteCode& bytecode)
|
|
|
|
- : OpCode(bytecode)
|
|
|
|
- {
|
|
|
|
- }
|
|
|
|
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
|
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
|
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::Exit; }
|
|
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::Exit; }
|
|
ALWAYS_INLINE size_t size() const override { return 1; }
|
|
ALWAYS_INLINE size_t size() const override { return 1; }
|
|
@@ -536,10 +533,6 @@ public:
|
|
|
|
|
|
class OpCode_FailForks final : public OpCode {
|
|
class OpCode_FailForks final : public OpCode {
|
|
public:
|
|
public:
|
|
- OpCode_FailForks(ByteCode& bytecode)
|
|
|
|
- : OpCode(bytecode)
|
|
|
|
- {
|
|
|
|
- }
|
|
|
|
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
|
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
|
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::FailForks; }
|
|
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::FailForks; }
|
|
ALWAYS_INLINE size_t size() const override { return 2; }
|
|
ALWAYS_INLINE size_t size() const override { return 2; }
|
|
@@ -549,10 +542,6 @@ public:
|
|
|
|
|
|
class OpCode_Save final : public OpCode {
|
|
class OpCode_Save final : public OpCode {
|
|
public:
|
|
public:
|
|
- OpCode_Save(ByteCode& bytecode)
|
|
|
|
- : OpCode(bytecode)
|
|
|
|
- {
|
|
|
|
- }
|
|
|
|
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
|
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
|
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::Save; }
|
|
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::Save; }
|
|
ALWAYS_INLINE size_t size() const override { return 1; }
|
|
ALWAYS_INLINE size_t size() const override { return 1; }
|
|
@@ -561,10 +550,6 @@ public:
|
|
|
|
|
|
class OpCode_Restore final : public OpCode {
|
|
class OpCode_Restore final : public OpCode {
|
|
public:
|
|
public:
|
|
- OpCode_Restore(ByteCode& bytecode)
|
|
|
|
- : OpCode(bytecode)
|
|
|
|
- {
|
|
|
|
- }
|
|
|
|
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
|
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
|
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::Restore; }
|
|
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::Restore; }
|
|
ALWAYS_INLINE size_t size() const override { return 1; }
|
|
ALWAYS_INLINE size_t size() const override { return 1; }
|
|
@@ -573,10 +558,6 @@ public:
|
|
|
|
|
|
class OpCode_GoBack final : public OpCode {
|
|
class OpCode_GoBack final : public OpCode {
|
|
public:
|
|
public:
|
|
- OpCode_GoBack(ByteCode& bytecode)
|
|
|
|
- : OpCode(bytecode)
|
|
|
|
- {
|
|
|
|
- }
|
|
|
|
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
|
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
|
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::GoBack; }
|
|
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::GoBack; }
|
|
ALWAYS_INLINE size_t size() const override { return 2; }
|
|
ALWAYS_INLINE size_t size() const override { return 2; }
|
|
@@ -586,10 +567,6 @@ public:
|
|
|
|
|
|
class OpCode_Jump final : public OpCode {
|
|
class OpCode_Jump final : public OpCode {
|
|
public:
|
|
public:
|
|
- OpCode_Jump(ByteCode& bytecode)
|
|
|
|
- : OpCode(bytecode)
|
|
|
|
- {
|
|
|
|
- }
|
|
|
|
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
|
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
|
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::Jump; }
|
|
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::Jump; }
|
|
ALWAYS_INLINE size_t size() const override { return 2; }
|
|
ALWAYS_INLINE size_t size() const override { return 2; }
|
|
@@ -602,10 +579,6 @@ public:
|
|
|
|
|
|
class OpCode_ForkJump final : public OpCode {
|
|
class OpCode_ForkJump final : public OpCode {
|
|
public:
|
|
public:
|
|
- OpCode_ForkJump(ByteCode& bytecode)
|
|
|
|
- : OpCode(bytecode)
|
|
|
|
- {
|
|
|
|
- }
|
|
|
|
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
|
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
|
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::ForkJump; }
|
|
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::ForkJump; }
|
|
ALWAYS_INLINE size_t size() const override { return 2; }
|
|
ALWAYS_INLINE size_t size() const override { return 2; }
|
|
@@ -618,10 +591,6 @@ public:
|
|
|
|
|
|
class OpCode_ForkStay final : public OpCode {
|
|
class OpCode_ForkStay final : public OpCode {
|
|
public:
|
|
public:
|
|
- OpCode_ForkStay(ByteCode& bytecode)
|
|
|
|
- : OpCode(bytecode)
|
|
|
|
- {
|
|
|
|
- }
|
|
|
|
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
|
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
|
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::ForkStay; }
|
|
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::ForkStay; }
|
|
ALWAYS_INLINE size_t size() const override { return 2; }
|
|
ALWAYS_INLINE size_t size() const override { return 2; }
|
|
@@ -634,10 +603,6 @@ public:
|
|
|
|
|
|
class OpCode_CheckBegin final : public OpCode {
|
|
class OpCode_CheckBegin final : public OpCode {
|
|
public:
|
|
public:
|
|
- OpCode_CheckBegin(ByteCode& bytecode)
|
|
|
|
- : OpCode(bytecode)
|
|
|
|
- {
|
|
|
|
- }
|
|
|
|
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
|
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
|
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::CheckBegin; }
|
|
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::CheckBegin; }
|
|
ALWAYS_INLINE size_t size() const override { return 1; }
|
|
ALWAYS_INLINE size_t size() const override { return 1; }
|
|
@@ -646,10 +611,6 @@ public:
|
|
|
|
|
|
class OpCode_CheckEnd final : public OpCode {
|
|
class OpCode_CheckEnd final : public OpCode {
|
|
public:
|
|
public:
|
|
- OpCode_CheckEnd(ByteCode& bytecode)
|
|
|
|
- : OpCode(bytecode)
|
|
|
|
- {
|
|
|
|
- }
|
|
|
|
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
|
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
|
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::CheckEnd; }
|
|
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::CheckEnd; }
|
|
ALWAYS_INLINE size_t size() const override { return 1; }
|
|
ALWAYS_INLINE size_t size() const override { return 1; }
|
|
@@ -658,10 +619,6 @@ public:
|
|
|
|
|
|
class OpCode_CheckBoundary final : public OpCode {
|
|
class OpCode_CheckBoundary final : public OpCode {
|
|
public:
|
|
public:
|
|
- OpCode_CheckBoundary(ByteCode& bytecode)
|
|
|
|
- : OpCode(bytecode)
|
|
|
|
- {
|
|
|
|
- }
|
|
|
|
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
|
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
|
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::CheckBoundary; }
|
|
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::CheckBoundary; }
|
|
ALWAYS_INLINE size_t size() const override { return 2; }
|
|
ALWAYS_INLINE size_t size() const override { return 2; }
|
|
@@ -672,10 +629,6 @@ public:
|
|
|
|
|
|
class OpCode_SaveLeftCaptureGroup final : public OpCode {
|
|
class OpCode_SaveLeftCaptureGroup final : public OpCode {
|
|
public:
|
|
public:
|
|
- OpCode_SaveLeftCaptureGroup(ByteCode& bytecode)
|
|
|
|
- : OpCode(bytecode)
|
|
|
|
- {
|
|
|
|
- }
|
|
|
|
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
|
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
|
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::SaveLeftCaptureGroup; }
|
|
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::SaveLeftCaptureGroup; }
|
|
ALWAYS_INLINE size_t size() const override { return 2; }
|
|
ALWAYS_INLINE size_t size() const override { return 2; }
|
|
@@ -685,10 +638,6 @@ public:
|
|
|
|
|
|
class OpCode_SaveRightCaptureGroup final : public OpCode {
|
|
class OpCode_SaveRightCaptureGroup final : public OpCode {
|
|
public:
|
|
public:
|
|
- OpCode_SaveRightCaptureGroup(ByteCode& bytecode)
|
|
|
|
- : OpCode(bytecode)
|
|
|
|
- {
|
|
|
|
- }
|
|
|
|
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
|
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
|
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::SaveRightCaptureGroup; }
|
|
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::SaveRightCaptureGroup; }
|
|
ALWAYS_INLINE size_t size() const override { return 2; }
|
|
ALWAYS_INLINE size_t size() const override { return 2; }
|
|
@@ -698,10 +647,6 @@ public:
|
|
|
|
|
|
class OpCode_SaveLeftNamedCaptureGroup final : public OpCode {
|
|
class OpCode_SaveLeftNamedCaptureGroup final : public OpCode {
|
|
public:
|
|
public:
|
|
- OpCode_SaveLeftNamedCaptureGroup(ByteCode& bytecode)
|
|
|
|
- : OpCode(bytecode)
|
|
|
|
- {
|
|
|
|
- }
|
|
|
|
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
|
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
|
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::SaveLeftNamedCaptureGroup; }
|
|
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::SaveLeftNamedCaptureGroup; }
|
|
ALWAYS_INLINE size_t size() const override { return 3; }
|
|
ALWAYS_INLINE size_t size() const override { return 3; }
|
|
@@ -715,10 +660,6 @@ public:
|
|
|
|
|
|
class OpCode_SaveRightNamedCaptureGroup final : public OpCode {
|
|
class OpCode_SaveRightNamedCaptureGroup final : public OpCode {
|
|
public:
|
|
public:
|
|
- OpCode_SaveRightNamedCaptureGroup(ByteCode& bytecode)
|
|
|
|
- : OpCode(bytecode)
|
|
|
|
- {
|
|
|
|
- }
|
|
|
|
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
|
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
|
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::SaveRightNamedCaptureGroup; }
|
|
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::SaveRightNamedCaptureGroup; }
|
|
ALWAYS_INLINE size_t size() const override { return 3; }
|
|
ALWAYS_INLINE size_t size() const override { return 3; }
|
|
@@ -732,10 +673,6 @@ public:
|
|
|
|
|
|
class OpCode_Compare final : public OpCode {
|
|
class OpCode_Compare final : public OpCode {
|
|
public:
|
|
public:
|
|
- OpCode_Compare(ByteCode& bytecode)
|
|
|
|
- : OpCode(bytecode)
|
|
|
|
- {
|
|
|
|
- }
|
|
|
|
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
|
ExecutionResult execute(const MatchInput& input, MatchState& state, MatchOutput& output) const override;
|
|
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::Compare; }
|
|
ALWAYS_INLINE OpCodeId opcode_id() const override { return OpCodeId::Compare; }
|
|
ALWAYS_INLINE size_t size() const override { return arguments_size() + 3; }
|
|
ALWAYS_INLINE size_t size() const override { return arguments_size() + 3; }
|