@@ -54,6 +54,11 @@ std::shared_ptr<ExecutableCode> Compiler::compile(std::shared_ptr<Block> startBl
5454 std::cerr << " error: if statement created by block '" << impl->block ->opcode () << " ' not terminated" << std::endl;
5555 assert (false );
5656 }
57+
58+ if (impl->customLoopCount > 0 ) {
59+ std::cerr << " error: loop created by block '" << impl->block ->opcode () << " ' not terminated" << std::endl;
60+ assert (false );
61+ }
5762 } else {
5863 std::cout << " warning: unsupported block: " << impl->block ->opcode () << std::endl;
5964 impl->unsupportedBlocks .insert (impl->block ->opcode ());
@@ -76,14 +81,34 @@ std::shared_ptr<ExecutableCode> Compiler::compile(std::shared_ptr<Block> startBl
7681
7782/* !
7883 * Adds a call to the given function.\n
79- * For example: extern "C" bool some_block(Target *target, double arg1, const char *arg2)
84+ * For example: extern "C" bool some_block(double arg1, const char *arg2)
8085 */
8186CompilerValue *Compiler::addFunctionCall (const std::string &functionName, StaticType returnType, const ArgTypes &argTypes, const Args &args)
8287{
8388 assert (argTypes.size () == args.size ());
8489 return impl->builder ->addFunctionCall (functionName, returnType, argTypes, args);
8590}
8691
92+ /* !
93+ * Adds a call to the given function with a target parameter.\n
94+ * For example: extern "C" bool some_block(Target *target, double arg1, const char *arg2)
95+ */
96+ CompilerValue *Compiler::addTargetFunctionCall (const std::string &functionName, StaticType returnType, const ArgTypes &argTypes, const Args &args)
97+ {
98+ assert (argTypes.size () == args.size ());
99+ return impl->builder ->addTargetFunctionCall (functionName, returnType, argTypes, args);
100+ }
101+
102+ /* !
103+ * Adds a call to the given function with an execution context parameter.\n
104+ * For example: extern "C" bool some_block(ExecutionContext *ctx, double arg1, const char *arg2)
105+ */
106+ CompilerValue *Compiler::addFunctionCallWithCtx (const std::string &functionName, StaticType returnType, const ArgTypes &argTypes, const Args &args)
107+ {
108+ assert (argTypes.size () == args.size ());
109+ return impl->builder ->addFunctionCallWithCtx (functionName, returnType, argTypes, args);
110+ }
111+
87112/* ! Adds the given constant to the compiled code. */
88113CompilerConstant *Compiler::addConstValue (const Value &value)
89114{
@@ -362,6 +387,45 @@ void Compiler::endIf()
362387 impl->customIfStatementCount --;
363388}
364389
390+ /* !
391+ * Begins a custom while loop.
392+ * \note The loop must be terminated with endLoop() after compiling your block.
393+ */
394+ void Compiler::beginWhileLoop (CompilerValue *cond)
395+ {
396+ impl->builder ->beginWhileLoop (cond);
397+ impl->customLoopCount ++;
398+ }
399+
400+ /* !
401+ * Begins a custom repeat until loop.
402+ * \note The loop must be terminated with endLoop() after compiling your block.
403+ */
404+ void Compiler::beginRepeatUntilLoop (CompilerValue *cond)
405+ {
406+ impl->builder ->beginRepeatUntilLoop (cond);
407+ impl->customLoopCount ++;
408+ }
409+
410+ /* ! Begins a while/until loop condition. */
411+ void Compiler::beginLoopCondition ()
412+ {
413+ impl->builder ->beginLoopCondition ();
414+ }
415+
416+ /* ! Ends custom loop. */
417+ void Compiler::endLoop ()
418+ {
419+ if (impl->customLoopCount == 0 ) {
420+ std::cerr << " error: called Compiler::endLoop() without a loop" ;
421+ assert (false );
422+ return ;
423+ }
424+
425+ impl->builder ->endLoop ();
426+ impl->customLoopCount --;
427+ }
428+
365429/* ! Jumps to the given if substack. */
366430void Compiler::moveToIf (CompilerValue *cond, std::shared_ptr<Block> substack)
367431{
@@ -425,12 +489,6 @@ void Compiler::moveToRepeatUntilLoop(CompilerValue *cond, std::shared_ptr<Block>
425489 impl->substackEnd ();
426490}
427491
428- /* ! Begins a while/until loop condition. */
429- void Compiler::beginLoopCondition ()
430- {
431- impl->builder ->beginLoopCondition ();
432- }
433-
434492/* ! Makes current script run without screen refresh. */
435493void Compiler::warp ()
436494{
0 commit comments