49 lines
1.5 KiB
C#
49 lines
1.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Upsilon.Evaluator;
|
|
using Upsilon.Text;
|
|
|
|
namespace Upsilon.Binder
|
|
{
|
|
public class BoundVariableAssignment : BoundStatement
|
|
{
|
|
public BoundVariableSymbol Variable { get; }
|
|
public BoundExpression BoundExpression { get; }
|
|
public bool IsLocalDefinition { get; }
|
|
|
|
public BoundVariableAssignment(BoundVariableSymbol variable, BoundExpression boundExpression, bool isLocalDefinition,
|
|
TextSpan span) : base(span)
|
|
{
|
|
Variable = variable;
|
|
BoundExpression = boundExpression;
|
|
IsLocalDefinition = isLocalDefinition;
|
|
}
|
|
|
|
public override BoundKind Kind => BoundKind.BoundAssignmentStatement;
|
|
|
|
public override IEnumerable<BoundNode> GetChildren()
|
|
{
|
|
yield return BoundExpression;
|
|
}
|
|
|
|
internal override void Evaluate(EvaluationScope scope, Diagnostics diagnostics, ref EvaluationState state)
|
|
{
|
|
var val = BoundExpression.Evaluate(scope, diagnostics, ref state);
|
|
if (IsLocalDefinition)
|
|
{
|
|
scope.CreateLocal(Variable.VariableSymbol, val);
|
|
}
|
|
else
|
|
{
|
|
scope.AssignToNearest(Variable.VariableSymbol, val);
|
|
}
|
|
|
|
}
|
|
|
|
internal override IEnumerator EvaluateCoroutine(EvaluationScope scope, Diagnostics diagnostics, EvaluationState state)
|
|
{
|
|
Evaluate(scope, diagnostics, ref state);
|
|
yield break;
|
|
}
|
|
}
|
|
} |