@@ -14,6 +14,8 @@ namespace libscratchcpp
1414class IEngine ;
1515class Target ;
1616class ExecutableCode ;
17+ class CompilerValue ;
18+ class CompilerConstant ;
1719class Variable ;
1820class List ;
1921class Input ;
@@ -33,6 +35,9 @@ class LIBSCRATCHCPP_EXPORT Compiler
3335 Unknown
3436 };
3537
38+ using ArgTypes = std::vector<StaticType>;
39+ using Args = std::vector<CompilerValue *>;
40+
3641 Compiler (IEngine *engine, Target *target);
3742 Compiler (const Compiler &) = delete ;
3843
@@ -42,63 +47,63 @@ class LIBSCRATCHCPP_EXPORT Compiler
4247
4348 std::shared_ptr<ExecutableCode> compile (std::shared_ptr<Block> startBlock);
4449
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 );
8691
8792 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 );
9297
93- void beginIfStatement ();
98+ void beginIfStatement (CompilerValue *cond );
9499 void beginElseBranch ();
95100 void endIf ();
96101
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);
102107 void beginLoopCondition ();
103108 void warp ();
104109
@@ -108,7 +113,7 @@ class LIBSCRATCHCPP_EXPORT Compiler
108113 const std::unordered_set<std::string> &unsupportedBlocks () const ;
109114
110115 private:
111- void addInput (Input *input);
116+ CompilerValue * addInput (Input *input);
112117
113118 spimpl::unique_impl_ptr<CompilerPrivate> impl;
114119};
0 commit comments