2019-02-13 15:29:58 +00:00
|
|
|
using System;
|
2019-02-13 17:10:39 +00:00
|
|
|
using System.Collections;
|
2018-11-27 17:38:28 +00:00
|
|
|
using System.Collections.Generic;
|
2019-02-13 15:29:58 +00:00
|
|
|
using Upsilon.BaseTypes;
|
|
|
|
using Upsilon.BaseTypes.ScriptTypeInterfaces;
|
|
|
|
using Upsilon.Evaluator;
|
2018-11-25 18:30:18 +00:00
|
|
|
using Upsilon.Text;
|
|
|
|
|
2018-11-19 15:22:13 +00:00
|
|
|
namespace Upsilon.Binder
|
|
|
|
{
|
|
|
|
public class BoundTableAssigmentStatement : BoundStatement
|
|
|
|
{
|
2018-11-20 13:05:34 +00:00
|
|
|
public BoundExpression TableIndexExpression { get; }
|
2018-11-19 15:22:13 +00:00
|
|
|
public BoundExpression Value { get; }
|
|
|
|
|
2018-11-25 18:30:18 +00:00
|
|
|
public BoundTableAssigmentStatement(BoundExpression tableIndexExpression, BoundExpression value,
|
|
|
|
TextSpan span) : base(span)
|
2018-11-19 15:22:13 +00:00
|
|
|
{
|
|
|
|
TableIndexExpression = tableIndexExpression;
|
|
|
|
Value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override BoundKind Kind => BoundKind.BoundTableAssigmentStatement;
|
2019-01-17 12:56:53 +00:00
|
|
|
|
|
|
|
public override IEnumerable<BoundNode> GetChildren()
|
|
|
|
{
|
|
|
|
yield return TableIndexExpression;
|
|
|
|
yield return Value;
|
|
|
|
}
|
2019-02-13 15:29:58 +00:00
|
|
|
|
|
|
|
internal override void Evaluate(EvaluationScope scope, Diagnostics diagnostics, ref EvaluationState state)
|
|
|
|
{
|
|
|
|
ScriptType table;
|
|
|
|
ScriptType index;
|
|
|
|
if (TableIndexExpression.Kind == BoundKind.BoundIndexExpression)
|
|
|
|
{
|
|
|
|
var indexExpression = (BoundIndexExpression)TableIndexExpression;
|
|
|
|
table = indexExpression.Identifier.Evaluate(scope, diagnostics, ref state);
|
|
|
|
index = indexExpression.Index.Evaluate(scope, diagnostics, ref state);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var fullStopIndexExpression = (BoundFullStopIndexExpression) TableIndexExpression;
|
|
|
|
table = fullStopIndexExpression.Expression.Evaluate(scope, diagnostics, ref state);
|
|
|
|
index = fullStopIndexExpression.Index.ToScriptType();
|
|
|
|
}
|
|
|
|
|
|
|
|
var value = Value.Evaluate(scope, diagnostics, ref state);
|
|
|
|
if (!(table is IIndexable indexable))
|
|
|
|
{
|
|
|
|
throw new Exception("Cant assign to that");
|
|
|
|
}
|
|
|
|
indexable.Set(diagnostics, Span, index.ToString().ToScriptType(), value);
|
|
|
|
}
|
2019-02-13 17:10:39 +00:00
|
|
|
|
|
|
|
internal override IEnumerator EvaluateCoroutine(EvaluationScope scope, Diagnostics diagnostics, EvaluationState state)
|
|
|
|
{
|
|
|
|
Evaluate(scope, diagnostics, ref state);
|
|
|
|
yield break;
|
|
|
|
}
|
2018-11-19 15:22:13 +00:00
|
|
|
}
|
|
|
|
}
|