summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Bytecode/Op.h
blob: a7fe80d306ccd81c39b9af29fad9b0811cc725fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/*
 * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/FlyString.h>
#include <LibJS/Bytecode/Instruction.h>
#include <LibJS/Bytecode/Label.h>
#include <LibJS/Bytecode/Register.h>
#include <LibJS/Heap/Cell.h>
#include <LibJS/Runtime/Value.h>

namespace JS::Bytecode::Op {

class Load final : public Instruction {
public:
    Load(Register dst, Value value)
        : m_dst(dst)
        , m_value(value)
    {
    }

    virtual ~Load() override { }
    virtual void execute(Bytecode::Interpreter&) const override;
    virtual String to_string() const override;

private:
    Register m_dst;
    Value m_value;
};

class Add final : public Instruction {
public:
    Add(Register dst, Register src1, Register src2)
        : m_dst(dst)
        , m_src1(src1)
        , m_src2(src2)
    {
    }

    virtual ~Add() override { }
    virtual void execute(Bytecode::Interpreter&) const override;
    virtual String to_string() const override;

private:
    Register m_dst;
    Register m_src1;
    Register m_src2;
};

class Sub final : public Instruction {
public:
    Sub(Register dst, Register src1, Register src2)
        : m_dst(dst)
        , m_src1(src1)
        , m_src2(src2)
    {
    }

    virtual ~Sub() override { }
    virtual void execute(Bytecode::Interpreter&) const override;
    virtual String to_string() const override;

private:
    Register m_dst;
    Register m_src1;
    Register m_src2;
};

class LessThan final : public Instruction {
public:
    LessThan(Register dst, Register src1, Register src2)
        : m_dst(dst)
        , m_src1(src1)
        , m_src2(src2)
    {
    }

    virtual ~LessThan() override { }
    virtual void execute(Bytecode::Interpreter&) const override;
    virtual String to_string() const override;

private:
    Register m_dst;
    Register m_src1;
    Register m_src2;
};

class AbstractInequals final : public Instruction {
public:
    AbstractInequals(Register dst, Register src1, Register src2)
        : m_dst(dst)
        , m_src1(src1)
        , m_src2(src2)
    {
    }

    virtual ~AbstractInequals() override { }
    virtual void execute(Bytecode::Interpreter&) const override;
    virtual String to_string() const override;

private:
    Register m_dst;
    Register m_src1;
    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 NewObject final : public Instruction {
public:
    explicit NewObject(Register dst)
        : m_dst(dst)
    {
    }

    virtual ~NewObject() override { }
    virtual void execute(Bytecode::Interpreter&) const override;
    virtual String to_string() const override;

private:
    Register m_dst;
};

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;
};

class Jump final : public Instruction {
public:
    explicit Jump(Label target)
        : m_target(target)
    {
    }

    virtual ~Jump() override { }
    virtual void execute(Bytecode::Interpreter&) const override;
    virtual String to_string() const override;

private:
    Label m_target;
};

class JumpIfFalse final : public Instruction {
public:
    explicit JumpIfFalse(Register result, Optional<Label> target = {})
        : m_result(result)
        , m_target(move(target))
    {
    }

    void set_target(Optional<Label> target) { m_target = move(target); }

    virtual ~JumpIfFalse() override { }
    virtual void execute(Bytecode::Interpreter&) const override;
    virtual String to_string() const override;

private:
    Register m_result;
    Optional<Label> m_target;
};

class JumpIfTrue final : public Instruction {
public:
    explicit JumpIfTrue(Register result, Optional<Label> target = {})
        : m_result(result)
        , m_target(move(target))
    {
    }

    void set_target(Optional<Label> target) { m_target = move(target); }

    virtual ~JumpIfTrue() override { }
    virtual void execute(Bytecode::Interpreter&) const override;
    virtual String to_string() const override;

private:
    Register m_result;
    Optional<Label> m_target;
};

}