@@ -45,9 +45,15 @@ std::shared_ptr<ExecutableCode> Compiler::compile(std::shared_ptr<Block> startBl
4545 impl->block = startBlock;
4646
4747 while (impl->block ) {
48- if (impl->block ->compileFunction ())
48+ if (impl->block ->compileFunction ()) {
49+ assert (impl->customIfStatementCount == 0 );
4950 impl->block ->compile (this );
50- else {
51+
52+ if (impl->customIfStatementCount > 0 ) {
53+ std::cerr << " error: if statement created by block '" << impl->block ->opcode () << " ' not terminated" << std::endl;
54+ assert (false );
55+ }
56+ } else {
5157 std::cout << " warning: unsupported block: " << impl->block ->opcode () << std::endl;
5258 impl->unsupportedBlocks .insert (impl->block ->opcode ());
5359 }
@@ -94,6 +100,30 @@ void Compiler::addListContents(List *list)
94100 impl->builder ->addListContents (list);
95101}
96102
103+ /* ! Adds the item with index from the last value of the given list to the code. */
104+ void Compiler::addListItem (List *list)
105+ {
106+ impl->builder ->addListItem (list);
107+ }
108+
109+ /* ! Adds the index of the item from the last value of the given list to the code. */
110+ void Compiler::addListItemIndex (List *list)
111+ {
112+ impl->builder ->addListItemIndex (list);
113+ }
114+
115+ /* ! Adds the result of a list contains item from the check to the code. */
116+ void Compiler::addListContains (List *list)
117+ {
118+ impl->builder ->addListContains (list);
119+ }
120+
121+ /* ! Adds the length of the given list to the code. */
122+ void Compiler::addListSize (List *list)
123+ {
124+ impl->builder ->addListSize (list);
125+ }
126+
97127/* ! Compiles the given input (resolved by name) and adds it to the compiled code. */
98128void Compiler::addInput (const std::string &name)
99129{
@@ -262,6 +292,68 @@ void Compiler::createVariableWrite(Variable *variable)
262292 impl->builder ->createVariableWrite (variable);
263293}
264294
295+ /* ! Creates a clear list operation. */
296+ void Compiler::createListClear (List *list)
297+ {
298+ impl->builder ->createListClear (list);
299+ }
300+
301+ /* !
302+ * Creates a remove item from list operation.
303+ * \note The index starts with 0 and is cast to number, special strings like "last" are not handled.
304+ */
305+ void Compiler::createListRemove (List *list)
306+ {
307+ impl->builder ->createListRemove (list);
308+ }
309+
310+ /* ! Creates a list append operation using the last value. */
311+ void Compiler::createListAppend (List *list)
312+ {
313+ impl->builder ->createListAppend (list);
314+ }
315+
316+ /* ! Creates a list insert operation using the last 2 values (index, value). */
317+ void Compiler::createListInsert (List *list)
318+ {
319+ impl->builder ->createListInsert (list);
320+ }
321+
322+ /* ! Creates a list replace operation using the last 2 values (index, value). */
323+ void Compiler::createListReplace (List *list)
324+ {
325+ impl->builder ->createListReplace (list);
326+ }
327+
328+ /* !
329+ * Starts a custom if statement.
330+ * \note The if statement must be terminated using endIf() after compiling your block.
331+ */
332+ void Compiler::beginIfStatement ()
333+ {
334+ impl->builder ->beginIfStatement ();
335+ impl->customIfStatementCount ++;
336+ }
337+
338+ /* ! Starts the else branch of custom if statement. */
339+ void Compiler::beginElseBranch ()
340+ {
341+ impl->builder ->beginElseBranch ();
342+ }
343+
344+ /* ! Ends custom if statement. */
345+ void Compiler::endIf ()
346+ {
347+ if (impl->customIfStatementCount == 0 ) {
348+ std::cerr << " error: called Compiler::endIf() without an if statement" ;
349+ assert (false );
350+ return ;
351+ }
352+
353+ impl->builder ->endIf ();
354+ impl->customIfStatementCount --;
355+ }
356+
265357/* ! Jumps to the given if substack. */
266358void Compiler::moveToIf (std::shared_ptr<Block> substack)
267359{
0 commit comments