executeBlock method
Implementation
Object? executeBlock(
List<SAstNode> statements,
Environment blockEnvironment,
) {
final previousEnvironment = environment;
Object? lastValue;
try {
environment = blockEnvironment;
for (final statement in statements) {
// Explicitly handle declarations within blocks
if (statement is SFunctionDeclaration ||
statement is SClassDeclaration ||
statement is SMixinDeclaration ||
statement
is STopLevelVariableDeclaration || // Technically not a statement, but might appear?
statement is SVariableDeclarationStatement) {
// This is a proper statement
lastValue = statement.accept<Object?>(this);
// Check for suspension after declaration execution
if (lastValue is AsyncSuspensionRequest) {
return lastValue; // Propagate suspension
}
lastValue = null; // Declarations don't produce a carry value
} else {
lastValue = statement.accept<Object?>(this);
// if the execution of the statement returns an async suspension request,
// we propagate it immediately upwards.
if (lastValue is AsyncSuspensionRequest) {
return lastValue;
}
}
// Handle ReturnException, BreakException, ContinueException if needed (propagate or consume)
// This simple version just propagates them implicitly by not catching them here.
}
} finally {
environment = previousEnvironment;
}
return lastValue;
}