@@ -14,6 +14,8 @@ namespace libscratchcpp
14
14
class IEngine ;
15
15
class Target ;
16
16
class ExecutableCode ;
17
+ class CompilerValue ;
18
+ class CompilerConstant ;
17
19
class Variable ;
18
20
class List ;
19
21
class Input ;
@@ -33,6 +35,9 @@ class LIBSCRATCHCPP_EXPORT Compiler
33
35
Unknown
34
36
};
35
37
38
+ using ArgTypes = std::vector<StaticType>;
39
+ using Args = std::vector<CompilerValue *>;
40
+
36
41
Compiler (IEngine *engine, Target *target);
37
42
Compiler (const Compiler &) = delete ;
38
43
@@ -42,63 +47,63 @@ class LIBSCRATCHCPP_EXPORT Compiler
42
47
43
48
std::shared_ptr<ExecutableCode> compile (std::shared_ptr<Block> startBlock);
44
49
45
- void addFunctionCall (const std::string &functionName, StaticType returnType = StaticType::Void, const std::vector<StaticType> &argTypes = {});
46
- void addConstValue (const Value &value);
47
- void addVariableValue (Variable *variable);
48
- void addListContents (List *list);
49
- void addListItem (List *list);
50
- void addListItemIndex (List *list);
51
- void addListContains (List *list);
52
- void addListSize (List *list);
53
- void addInput (const std::string &name);
54
-
55
- void createAdd ();
56
- void createSub ();
57
- void createMul ();
58
- void createDiv ();
59
-
60
- void createCmpEQ ();
61
- void createCmpGT ();
62
- void createCmpLT ();
63
-
64
- void createAnd ();
65
- void createOr ();
66
- void createNot ();
67
-
68
- void createMod ();
69
- void createRound ();
70
- void createAbs ();
71
- void createFloor ();
72
- void createCeil ();
73
- void createSqrt ();
74
- void createSin ();
75
- void createCos ();
76
- void createTan ();
77
- void createAsin ();
78
- void createAcos ();
79
- void createAtan ();
80
- void createLn ();
81
- void createLog10 ();
82
- void createExp ();
83
- void createExp10 ();
84
-
85
- void createVariableWrite (Variable *variable);
50
+ CompilerValue * addFunctionCall (const std::string &functionName, StaticType returnType = StaticType::Void, const ArgTypes &argTypes = {}, const Args &args = {});
51
+ CompilerConstant * addConstValue (const Value &value);
52
+ CompilerValue * addVariableValue (Variable *variable);
53
+ CompilerValue * addListContents (List *list);
54
+ CompilerValue * addListItem (List *list, CompilerValue *index );
55
+ CompilerValue * addListItemIndex (List *list, CompilerValue *item );
56
+ CompilerValue * addListContains (List *list, CompilerValue *item );
57
+ CompilerValue * addListSize (List *list);
58
+ CompilerValue * addInput (const std::string &name);
59
+
60
+ CompilerValue * createAdd (CompilerValue *operand1, CompilerValue *operand2 );
61
+ CompilerValue * createSub (CompilerValue *operand1, CompilerValue *operand2 );
62
+ CompilerValue * createMul (CompilerValue *operand1, CompilerValue *operand2 );
63
+ CompilerValue * createDiv (CompilerValue *operand1, CompilerValue *operand2 );
64
+
65
+ CompilerValue * createCmpEQ (CompilerValue *operand1, CompilerValue *operand2 );
66
+ CompilerValue * createCmpGT (CompilerValue *operand1, CompilerValue *operand2 );
67
+ CompilerValue * createCmpLT (CompilerValue *operand1, CompilerValue *operand2 );
68
+
69
+ CompilerValue * createAnd (CompilerValue *operand1, CompilerValue *operand2 );
70
+ CompilerValue * createOr (CompilerValue *operand1, CompilerValue *operand2 );
71
+ CompilerValue * createNot (CompilerValue *operand );
72
+
73
+ CompilerValue * createMod (CompilerValue *num1, CompilerValue *num2 );
74
+ CompilerValue * createRound (CompilerValue *num );
75
+ CompilerValue * createAbs (CompilerValue *num );
76
+ CompilerValue * createFloor (CompilerValue *num );
77
+ CompilerValue * createCeil (CompilerValue *num );
78
+ CompilerValue * createSqrt (CompilerValue *num );
79
+ CompilerValue * createSin (CompilerValue *num );
80
+ CompilerValue * createCos (CompilerValue *num );
81
+ CompilerValue * createTan (CompilerValue *num );
82
+ CompilerValue * createAsin (CompilerValue *num );
83
+ CompilerValue * createAcos (CompilerValue *num );
84
+ CompilerValue * createAtan (CompilerValue *num );
85
+ CompilerValue * createLn (CompilerValue *num );
86
+ CompilerValue * createLog10 (CompilerValue *num );
87
+ CompilerValue * createExp (CompilerValue *num );
88
+ CompilerValue * createExp10 (CompilerValue *num );
89
+
90
+ void createVariableWrite (Variable *variable, CompilerValue *value );
86
91
87
92
void createListClear (List *list);
88
- void createListRemove (List *list);
89
- void createListAppend (List *list);
90
- void createListInsert (List *list);
91
- void createListReplace (List *list);
93
+ void createListRemove (List *list, CompilerValue *index );
94
+ void createListAppend (List *list, CompilerValue *item );
95
+ void createListInsert (List *list, CompilerValue *index, CompilerValue *item );
96
+ void createListReplace (List *list, CompilerValue *index, CompilerValue *item );
92
97
93
- void beginIfStatement ();
98
+ void beginIfStatement (CompilerValue *cond );
94
99
void beginElseBranch ();
95
100
void endIf ();
96
101
97
- void moveToIf (std::shared_ptr<Block> substack);
98
- void moveToIfElse (std::shared_ptr<Block> substack1, std::shared_ptr<Block> substack2);
99
- void moveToRepeatLoop (std::shared_ptr<Block> substack);
100
- void moveToWhileLoop (std::shared_ptr<Block> substack);
101
- void moveToRepeatUntilLoop (std::shared_ptr<Block> substack);
102
+ void moveToIf (CompilerValue *cond, std::shared_ptr<Block> substack);
103
+ void moveToIfElse (CompilerValue *cond, std::shared_ptr<Block> substack1, std::shared_ptr<Block> substack2);
104
+ void moveToRepeatLoop (CompilerValue *count, std::shared_ptr<Block> substack);
105
+ void moveToWhileLoop (CompilerValue *cond, std::shared_ptr<Block> substack);
106
+ void moveToRepeatUntilLoop (CompilerValue *cond, std::shared_ptr<Block> substack);
102
107
void beginLoopCondition ();
103
108
void warp ();
104
109
@@ -108,7 +113,7 @@ class LIBSCRATCHCPP_EXPORT Compiler
108
113
const std::unordered_set<std::string> &unsupportedBlocks () const ;
109
114
110
115
private:
111
- void addInput (Input *input);
116
+ CompilerValue * addInput (Input *input);
112
117
113
118
spimpl::unique_impl_ptr<CompilerPrivate> impl;
114
119
};
0 commit comments