58 lines
1.8 KiB
C#
58 lines
1.8 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Immutable;
|
|
using Upsilon.Evaluator;
|
|
using Upsilon.Text;
|
|
|
|
namespace Upsilon.Binder
|
|
{
|
|
public class BoundBlockStatement : BoundStatement
|
|
{
|
|
public BoundBlockStatement(ImmutableArray<BoundStatement> statements, TextSpan span) : base(span)
|
|
{
|
|
Statements = statements;
|
|
}
|
|
|
|
public override BoundKind Kind => BoundKind.BoundBlockStatement;
|
|
|
|
public override IEnumerable<BoundNode> GetChildren()
|
|
{
|
|
return Statements;
|
|
}
|
|
|
|
public ImmutableArray<BoundStatement> Statements { get; }
|
|
|
|
internal override void Evaluate(EvaluationScope scope, Diagnostics diagnostics, ref EvaluationState state)
|
|
{
|
|
foreach (var statement in Statements)
|
|
{
|
|
statement.Evaluate(scope, diagnostics, ref state);
|
|
if (state.Returned)
|
|
return;
|
|
if (state.HasBroken)
|
|
return;
|
|
}
|
|
}
|
|
|
|
internal override IEnumerator EvaluateCoroutine(EvaluationScope scope, Diagnostics diagnostics, EvaluationState state)
|
|
{
|
|
foreach (var statement in Statements)
|
|
{
|
|
var coroutine = statement.EvaluateCoroutine(scope, diagnostics, state);
|
|
if (coroutine == null)
|
|
{
|
|
diagnostics.LogError("Can't evaluate a statement, it returned nil.", statement.Span);
|
|
continue;
|
|
}
|
|
while (coroutine.MoveNext())
|
|
{
|
|
yield return coroutine.Current;
|
|
}
|
|
if (state.Returned)
|
|
yield break;
|
|
if (state.HasBroken)
|
|
yield break;
|
|
}
|
|
}
|
|
}
|
|
} |