1 #ifndef INTERPRETER_LOCALOPCODES_H_INCLUDED
2 #define INTERPRETER_LOCALOPCODES_H_INCLUDED
3 
4 #include "opcodes.hpp"
5 #include "runtime.hpp"
6 #include "context.hpp"
7 
8 namespace Interpreter
9 {
10     class OpStoreLocalShort : public Opcode0
11     {
12         public:
13 
execute(Runtime & runtime)14             void execute (Runtime& runtime) override
15             {
16                 Type_Integer data = runtime[0].mInteger;
17                 int index = runtime[1].mInteger;
18 
19                 runtime.getContext().setLocalShort (index, data);
20 
21                 runtime.pop();
22                 runtime.pop();
23             }
24     };
25 
26     class OpStoreLocalLong : public Opcode0
27     {
28         public:
29 
execute(Runtime & runtime)30             void execute (Runtime& runtime) override
31             {
32                 Type_Integer data = runtime[0].mInteger;
33                 int index = runtime[1].mInteger;
34 
35                 runtime.getContext().setLocalLong (index, data);
36 
37                 runtime.pop();
38                 runtime.pop();
39             }
40     };
41 
42     class OpStoreLocalFloat : public Opcode0
43     {
44         public:
45 
execute(Runtime & runtime)46             void execute (Runtime& runtime) override
47             {
48                 Type_Float data = runtime[0].mFloat;
49                 int index = runtime[1].mInteger;
50 
51                 runtime.getContext().setLocalFloat (index, data);
52 
53                 runtime.pop();
54                 runtime.pop();
55             }
56     };
57 
58     class OpFetchIntLiteral : public Opcode0
59     {
60         public:
61 
execute(Runtime & runtime)62             void execute (Runtime& runtime) override
63             {
64                 Type_Integer intValue = runtime.getIntegerLiteral (runtime[0].mInteger);
65                 runtime[0].mInteger = intValue;
66             }
67     };
68 
69     class OpFetchFloatLiteral : public Opcode0
70     {
71         public:
72 
execute(Runtime & runtime)73             void execute (Runtime& runtime) override
74             {
75                 Type_Float floatValue = runtime.getFloatLiteral (runtime[0].mInteger);
76                 runtime[0].mFloat = floatValue;
77             }
78     };
79 
80     class OpFetchLocalShort : public Opcode0
81     {
82         public:
83 
execute(Runtime & runtime)84             void execute (Runtime& runtime) override
85             {
86                 int index = runtime[0].mInteger;
87                 int value = runtime.getContext().getLocalShort (index);
88                 runtime[0].mInteger = value;
89             }
90     };
91 
92     class OpFetchLocalLong : public Opcode0
93     {
94         public:
95 
execute(Runtime & runtime)96             void execute (Runtime& runtime) override
97             {
98                 int index = runtime[0].mInteger;
99                 int value = runtime.getContext().getLocalLong (index);
100                 runtime[0].mInteger = value;
101             }
102     };
103 
104     class OpFetchLocalFloat : public Opcode0
105     {
106         public:
107 
execute(Runtime & runtime)108             void execute (Runtime& runtime) override
109             {
110                 int index = runtime[0].mInteger;
111                 float value = runtime.getContext().getLocalFloat (index);
112                 runtime[0].mFloat = value;
113             }
114     };
115 
116     class OpStoreGlobalShort : public Opcode0
117     {
118         public:
119 
execute(Runtime & runtime)120             void execute (Runtime& runtime) override
121             {
122                 Type_Integer data = runtime[0].mInteger;
123                 int index = runtime[1].mInteger;
124 
125                 std::string name = runtime.getStringLiteral (index);
126 
127                 runtime.getContext().setGlobalShort (name, data);
128 
129                 runtime.pop();
130                 runtime.pop();
131             }
132     };
133 
134     class OpStoreGlobalLong : public Opcode0
135     {
136         public:
137 
execute(Runtime & runtime)138             void execute (Runtime& runtime) override
139             {
140                 Type_Integer data = runtime[0].mInteger;
141                 int index = runtime[1].mInteger;
142 
143                 std::string name = runtime.getStringLiteral (index);
144 
145                 runtime.getContext().setGlobalLong (name, data);
146 
147                 runtime.pop();
148                 runtime.pop();
149             }
150     };
151 
152     class OpStoreGlobalFloat : public Opcode0
153     {
154         public:
155 
execute(Runtime & runtime)156             void execute (Runtime& runtime) override
157             {
158                 Type_Float data = runtime[0].mFloat;
159                 int index = runtime[1].mInteger;
160 
161                 std::string name = runtime.getStringLiteral (index);
162 
163                 runtime.getContext().setGlobalFloat (name, data);
164 
165                 runtime.pop();
166                 runtime.pop();
167             }
168     };
169 
170     class OpFetchGlobalShort : public Opcode0
171     {
172         public:
173 
execute(Runtime & runtime)174             void execute (Runtime& runtime) override
175             {
176                 int index = runtime[0].mInteger;
177                 std::string name = runtime.getStringLiteral (index);
178                 Type_Integer value = runtime.getContext().getGlobalShort (name);
179                 runtime[0].mInteger = value;
180             }
181     };
182 
183     class OpFetchGlobalLong : public Opcode0
184     {
185         public:
186 
execute(Runtime & runtime)187             void execute (Runtime& runtime) override
188             {
189                 int index = runtime[0].mInteger;
190                 std::string name = runtime.getStringLiteral (index);
191                 Type_Integer value = runtime.getContext().getGlobalLong (name);
192                 runtime[0].mInteger = value;
193             }
194     };
195 
196     class OpFetchGlobalFloat : public Opcode0
197     {
198         public:
199 
execute(Runtime & runtime)200             void execute (Runtime& runtime) override
201             {
202                 int index = runtime[0].mInteger;
203                 std::string name = runtime.getStringLiteral (index);
204                 Type_Float value = runtime.getContext().getGlobalFloat (name);
205                 runtime[0].mFloat = value;
206             }
207     };
208 
209     class OpStoreMemberShort : public Opcode0
210     {
211             bool mGlobal;
212 
213         public:
214 
OpStoreMemberShort(bool global)215             OpStoreMemberShort (bool global) : mGlobal (global) {}
216 
execute(Runtime & runtime)217             void execute (Runtime& runtime) override
218             {
219                 Type_Integer data = runtime[0].mInteger;
220                 Type_Integer index = runtime[1].mInteger;
221                 std::string id = runtime.getStringLiteral (index);
222                 index = runtime[2].mInteger;
223                 std::string variable = runtime.getStringLiteral (index);
224 
225                 runtime.getContext().setMemberShort (id, variable, data, mGlobal);
226 
227                 runtime.pop();
228                 runtime.pop();
229                 runtime.pop();
230             }
231     };
232 
233     class OpStoreMemberLong : public Opcode0
234     {
235             bool mGlobal;
236 
237         public:
238 
OpStoreMemberLong(bool global)239             OpStoreMemberLong (bool global) : mGlobal (global) {}
240 
execute(Runtime & runtime)241             void execute (Runtime& runtime) override
242             {
243                 Type_Integer data = runtime[0].mInteger;
244                 Type_Integer index = runtime[1].mInteger;
245                 std::string id = runtime.getStringLiteral (index);
246                 index = runtime[2].mInteger;
247                 std::string variable = runtime.getStringLiteral (index);
248 
249                 runtime.getContext().setMemberLong (id, variable, data, mGlobal);
250 
251                 runtime.pop();
252                 runtime.pop();
253                 runtime.pop();
254             }
255     };
256 
257     class OpStoreMemberFloat : public Opcode0
258     {
259             bool mGlobal;
260 
261         public:
262 
OpStoreMemberFloat(bool global)263             OpStoreMemberFloat (bool global) : mGlobal (global) {}
264 
execute(Runtime & runtime)265             void execute (Runtime& runtime) override
266             {
267                 Type_Float data = runtime[0].mFloat;
268                 Type_Integer index = runtime[1].mInteger;
269                 std::string id = runtime.getStringLiteral (index);
270                 index = runtime[2].mInteger;
271                 std::string variable = runtime.getStringLiteral (index);
272 
273                 runtime.getContext().setMemberFloat (id, variable, data, mGlobal);
274 
275                 runtime.pop();
276                 runtime.pop();
277                 runtime.pop();
278             }
279     };
280 
281     class OpFetchMemberShort : public Opcode0
282     {
283             bool mGlobal;
284 
285         public:
286 
OpFetchMemberShort(bool global)287             OpFetchMemberShort (bool global) : mGlobal (global) {}
288 
execute(Runtime & runtime)289             void execute (Runtime& runtime) override
290             {
291                 Type_Integer index = runtime[0].mInteger;
292                 std::string id = runtime.getStringLiteral (index);
293                 index = runtime[1].mInteger;
294                 std::string variable = runtime.getStringLiteral (index);
295                 runtime.pop();
296 
297                 int value = runtime.getContext().getMemberShort (id, variable, mGlobal);
298                 runtime[0].mInteger = value;
299             }
300     };
301 
302     class OpFetchMemberLong : public Opcode0
303     {
304             bool mGlobal;
305 
306         public:
307 
OpFetchMemberLong(bool global)308             OpFetchMemberLong (bool global) : mGlobal (global) {}
309 
execute(Runtime & runtime)310             void execute (Runtime& runtime) override
311             {
312                 Type_Integer index = runtime[0].mInteger;
313                 std::string id = runtime.getStringLiteral (index);
314                 index = runtime[1].mInteger;
315                 std::string variable = runtime.getStringLiteral (index);
316                 runtime.pop();
317 
318                 int value = runtime.getContext().getMemberLong (id, variable, mGlobal);
319                 runtime[0].mInteger = value;
320             }
321     };
322 
323     class OpFetchMemberFloat : public Opcode0
324     {
325             bool mGlobal;
326 
327         public:
328 
OpFetchMemberFloat(bool global)329             OpFetchMemberFloat (bool global) : mGlobal (global) {}
330 
execute(Runtime & runtime)331             void execute (Runtime& runtime) override
332             {
333                 Type_Integer index = runtime[0].mInteger;
334                 std::string id = runtime.getStringLiteral (index);
335                 index = runtime[1].mInteger;
336                 std::string variable = runtime.getStringLiteral (index);
337                 runtime.pop();
338 
339                 float value = runtime.getContext().getMemberFloat (id, variable, mGlobal);
340                 runtime[0].mFloat = value;
341             }
342     };
343 }
344 
345 #endif
346