using System.Collections; using System.Collections.Generic; using Upsilon.Evaluator; using Upsilon.Text; namespace Upsilon.Binder { public class BoundReturnStatement : BoundStatement { public BoundReturnStatement(BoundExpression expression, TextSpan span) : base(span) { Expression = expression; } public BoundExpression Expression { get; } public override BoundKind Kind => BoundKind.BoundReturnStatement; public override IEnumerable GetChildren() { yield return Expression; } internal override void Evaluate(EvaluationScope scope, Diagnostics diagnostics, ref EvaluationState state) { state.ReturnValue = Expression?.Evaluate(scope, diagnostics, ref state); state.Returned = true; } internal override IEnumerator EvaluateCoroutine(EvaluationScope scope, Diagnostics diagnostics, EvaluationState state) { state.ReturnValue = Expression?.Evaluate(scope, diagnostics, ref state); state.Returned = true; yield break; } } }