Upsilon/Upsilon/Binder/BoundStatements/BoundReturnStatement.cs

37 lines
1.1 KiB
C#
Raw Normal View History

2019-02-13 17:10:39 +00:00
using System.Collections;
using System.Collections.Generic;
using Upsilon.Evaluator;
using Upsilon.Text;
2018-11-16 12:45:03 +00:00
namespace Upsilon.Binder
{
public class BoundReturnStatement : BoundStatement
2018-11-16 12:45:03 +00:00
{
public BoundReturnStatement(BoundExpression expression, TextSpan span) : base(span)
2018-11-16 12:45:03 +00:00
{
Expression = expression;
}
public BoundExpression Expression { get; }
public override BoundKind Kind => BoundKind.BoundReturnStatement;
2019-01-17 12:56:53 +00:00
public override IEnumerable<BoundNode> 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;
}
2019-02-13 17:10:39 +00:00
internal override IEnumerator EvaluateCoroutine(EvaluationScope scope, Diagnostics diagnostics, EvaluationState state)
{
state.ReturnValue = Expression?.Evaluate(scope, diagnostics, ref state);
state.Returned = true;
yield break;
}
2018-11-16 12:45:03 +00:00
}
}