@@ -661,6 +661,28 @@ private static Mixed evalLoop(EvalStack stack, Mixed lastResult, boolean hasResu
661661 return pauseResult ;
662662 }
663663 }
664+ frame .setKeepIVariable (false );
665+ result = ((FlowFunction <Object >) frame .getFlowFunction ()).childCompleted (
666+ t , frame .getFunctionState (), lastResult , frame .getEnv ());
667+ hasResult = false ;
668+ } else {
669+ throw ConfigRuntimeException .CreateUncatchableException (
670+ "Flow function in invalid state for " + data .val (), data .getTarget ());
671+ }
672+
673+ frame .setFunctionState (result .getState ());
674+ StepAction action = result .getAction ();
675+ if (action instanceof StepAction .Evaluate e ) {
676+ frame .setKeepIVariable (e .keepIVariable ());
677+ Environment evalEnv = e .getEnv () != null ? e .getEnv () : frame .getEnv ();
678+ stack .push (new StackFrame (e .getNode (), evalEnv , null , null ));
679+ } else if (action instanceof StepAction .Complete c ) {
680+ lastResult = c .getResult ();
681+ hasResult = true ;
682+ cleanupAndPop (stack , frame );
683+ } else if (action instanceof StepAction .FlowControl fc ) {
684+ pendingFlowControl = fc ;
685+ cleanupAndPop (stack , frame );
664686 }
665687 continue ;
666688 }
@@ -771,6 +793,33 @@ private static Mixed debugPause(DebugContext debugCtx, EvalStack stack,
771793 debugCtx .getListener ().onPaused (snapshot );
772794 return DEBUGGER_PAUSED ;
773795 }
796+
797+ return lastResult ;
798+ }
799+
800+ /**
801+ * Calls {@link FlowFunction#cleanup} if the frame has a FlowFunction that has begun,
802+ * then pops the frame from the stack.
803+ */
804+ @ SuppressWarnings ("unchecked" )
805+ private static void cleanupAndPop (EvalStack stack , StackFrame frame ) {
806+ if (frame .hasFlowFunction () && frame .hasBegun ()) {
807+ ((FlowFunction <Object >) frame .getFlowFunction ()).cleanup (
808+ frame .getNode ().getTarget (), frame .getFunctionState (), frame .getEnv ());
809+ }
810+ stack .pop ();
811+ }
812+
813+ /**
814+ * Given the parse tree and environment, executes the tree.
815+ *
816+ * @param c
817+ * @param env
818+ * @return
819+ * @throws CancelCommandException
820+ */
821+ public Mixed eval (ParseTree c , final Environment env ) throws CancelCommandException {
822+ return iterativeEval (c , env );
774823 }
775824
776825 /**
0 commit comments