|
2 | 2 |
|
3 | 3 | #pragma once |
4 | 4 |
|
5 | | -#include <scratchcpp/compiler.h> |
| 5 | +#include "instructionbase.h" |
6 | 6 |
|
7 | 7 | namespace libscratchcpp |
8 | 8 | { |
9 | 9 |
|
10 | | -class BlockPrototype; |
11 | | - |
12 | 10 | template<typename TInstruction, typename TRegister> |
13 | | -struct Instruction |
| 11 | +struct Instruction : public InstructionBase |
14 | 12 | { |
15 | | - enum class Type |
16 | | - { |
17 | | - FunctionCall, |
18 | | - Add, |
19 | | - Sub, |
20 | | - Mul, |
21 | | - Div, |
22 | | - Random, |
23 | | - RandomInt, |
24 | | - CmpEQ, |
25 | | - CmpGT, |
26 | | - CmpLT, |
27 | | - StrCmpEQCS, // case sensitive |
28 | | - StrCmpEQCI, // case insensitive |
29 | | - And, |
30 | | - Or, |
31 | | - Not, |
32 | | - Mod, |
33 | | - Round, |
34 | | - Abs, |
35 | | - Floor, |
36 | | - Ceil, |
37 | | - Sqrt, |
38 | | - Sin, |
39 | | - Cos, |
40 | | - Tan, |
41 | | - Asin, |
42 | | - Acos, |
43 | | - Atan, |
44 | | - Ln, |
45 | | - Log10, |
46 | | - Exp, |
47 | | - Exp10, |
48 | | - StringConcat, |
49 | | - StringChar, |
50 | | - StringLength, |
51 | | - Select, |
52 | | - CreateLocalVariable, |
53 | | - WriteLocalVariable, |
54 | | - ReadLocalVariable, |
55 | | - WriteVariable, |
56 | | - ReadVariable, |
57 | | - ClearList, |
58 | | - RemoveListItem, |
59 | | - AppendToList, |
60 | | - InsertToList, |
61 | | - ListReplace, |
62 | | - GetListContents, |
63 | | - GetListItem, |
64 | | - GetListSize, |
65 | | - GetListItemIndex, |
66 | | - ListContainsItem, |
67 | | - Yield, |
68 | | - BeginIf, |
69 | | - BeginElse, |
70 | | - EndIf, |
71 | | - BeginRepeatLoop, |
72 | | - LoopIndex, |
73 | | - BeginWhileLoop, |
74 | | - BeginRepeatUntilLoop, |
75 | | - BeginLoopCondition, |
76 | | - EndLoop, |
77 | | - Stop, |
78 | | - ThreadStop, |
79 | | - InvalidateTarget, |
80 | | - CallProcedure, |
81 | | - ProcedureArg, |
82 | | - Print |
83 | | - }; |
| 13 | + using Type = InstructionBase::Type; |
| 14 | + using InstructionBase::InstructionBase; // inherit constructor |
| 15 | + |
| 16 | + inline TInstruction *getPrevious() { return static_cast<TInstruction *>(previous); } |
84 | 17 |
|
85 | | - Instruction(Type type, bool loopCondition) : |
86 | | - type(type), |
87 | | - loopCondition(loopCondition) |
88 | | - { |
89 | | - } |
| 18 | + inline TInstruction *getNext() { return static_cast<TInstruction *>(next); } |
90 | 19 |
|
91 | | - Type type; |
92 | | - std::string functionName; |
93 | 20 | std::vector<std::pair<Compiler::StaticType, TRegister *>> args; // target type, register |
94 | 21 | TRegister *functionReturnReg = nullptr; |
95 | | - bool functionTargetArg = false; // whether to add target ptr to function parameters |
96 | | - bool functionCtxArg = false; // whether to add execution context ptr to function parameters |
97 | | - Variable *targetVariable = nullptr; // for variables |
98 | | - List *targetList = nullptr; // for lists |
99 | | - Compiler::StaticType targetType = Compiler::StaticType::Unknown; // variable or list type (before read/write operation) |
100 | | - BlockPrototype *procedurePrototype = nullptr; |
101 | | - size_t procedureArgIndex = 0; |
102 | | - bool loopCondition = false; // whether the instruction is part of a loop condition |
103 | | - |
104 | | - // Linked list |
105 | | - TInstruction *previous = nullptr; |
106 | | - TInstruction *next = nullptr; |
107 | | - std::shared_ptr<TInstruction> _next; // ensure items are not deleted |
108 | 22 | }; |
109 | 23 |
|
110 | 24 | } // namespace libscratchcpp |
0 commit comments