Split script tables in numerically keyed and generically keyed
This commit is contained in:
parent
2d6e3335aa
commit
6e960e38ff
|
@ -1,9 +1,8 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Upsilon.BaseTypes.Number
|
||||
{
|
||||
internal class ScriptNumberLong : ScriptNumber
|
||||
public class ScriptNumberLong : ScriptNumber
|
||||
{
|
||||
public long Value { get; set; }
|
||||
protected internal override bool IsFloat { get; } = false;
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
using Upsilon.Evaluator;
|
||||
|
||||
namespace Upsilon.BaseTypes.ScriptTable
|
||||
{
|
||||
public class GenericKeyedScriptTable : ScriptTable
|
||||
{
|
||||
public GenericKeyedScriptTable(EvaluationScope scope) : base(scope)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Upsilon.Evaluator;
|
||||
|
||||
namespace Upsilon.BaseTypes.ScriptTable
|
||||
{
|
||||
public class NumeratedScriptTable : ScriptTable, IEnumerable<ScriptType>
|
||||
{
|
||||
public NumeratedScriptTable(EvaluationScope scope) : base(scope)
|
||||
{
|
||||
}
|
||||
|
||||
public new IEnumerator GetEnumerator()
|
||||
{
|
||||
return Enumerator();
|
||||
}
|
||||
|
||||
protected override IEnumerator<ScriptType> Enumerator()
|
||||
{
|
||||
foreach (var variable in EvaluationScope.Variables)
|
||||
{
|
||||
yield return variable.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,14 +3,13 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using Upsilon.BaseTypes.Number;
|
||||
using Upsilon.BaseTypes.ScriptTypeInterfaces;
|
||||
using Upsilon.Binder;
|
||||
using Upsilon.Binder.VariableSymbols;
|
||||
using Upsilon.Evaluator;
|
||||
using Upsilon.Text;
|
||||
|
||||
namespace Upsilon.BaseTypes
|
||||
namespace Upsilon.BaseTypes.ScriptTable
|
||||
{
|
||||
internal class ScriptTable : ScriptType, IIndexable, IScopeOwner, IIterable, ILengthType
|
||||
public abstract class ScriptTable : ScriptType, IIndexable, IScopeOwner, IIterable, ILengthType
|
||||
{
|
||||
public EvaluationScope EvaluationScope { get; }
|
||||
|
||||
|
@ -61,7 +60,7 @@ namespace Upsilon.BaseTypes
|
|||
return Enumerator();
|
||||
}
|
||||
|
||||
private IEnumerator<ScriptType> Enumerator()
|
||||
protected virtual IEnumerator<ScriptType> Enumerator()
|
||||
{
|
||||
foreach (var variable in EvaluationScope.Variables)
|
||||
{
|
|
@ -125,7 +125,7 @@ namespace Upsilon.BaseTypes
|
|||
return Type.Number;
|
||||
if (typeof(ScriptFunction.ScriptFunction).IsAssignableFrom(t))
|
||||
return Type.Function;
|
||||
if (typeof(ScriptTable).IsAssignableFrom(t))
|
||||
if (typeof(ScriptTable.ScriptTable).IsAssignableFrom(t))
|
||||
return Type.Table;
|
||||
if (t == typeof(IIterable))
|
||||
return Type.Nil;
|
||||
|
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using Upsilon.BaseTypes;
|
||||
using Upsilon.BaseTypes.Number;
|
||||
using Upsilon.BaseTypes.ScriptFunction;
|
||||
using Upsilon.BaseTypes.ScriptTable;
|
||||
using Upsilon.BaseTypes.ScriptTypeInterfaces;
|
||||
using Upsilon.BaseTypes.UserData;
|
||||
using Upsilon.Binder;
|
||||
|
@ -554,6 +555,7 @@ namespace Upsilon.Evaluator
|
|||
var tableScope = EvaluationScope.CreateWithGetOnlyParent(Scope);
|
||||
var innerEvaluator = new Evaluator(_diagnostics, tableScope, _script);
|
||||
var currentPos = 1;
|
||||
var isNumerated = true;
|
||||
foreach (var boundStatement in e.Statements)
|
||||
{
|
||||
switch (boundStatement.Kind)
|
||||
|
@ -562,6 +564,7 @@ namespace Upsilon.Evaluator
|
|||
case BoundKind.BoundFunctionExpression:
|
||||
case BoundKind.BoundFunctionAssignmentStatement:
|
||||
innerEvaluator.EvaluateNode(boundStatement);
|
||||
isNumerated = false;
|
||||
break;
|
||||
default:
|
||||
{
|
||||
|
@ -576,7 +579,12 @@ namespace Upsilon.Evaluator
|
|||
|
||||
currentPos++;
|
||||
}
|
||||
return new ScriptTable(tableScope);
|
||||
|
||||
if (isNumerated)
|
||||
{
|
||||
return new NumeratedScriptTable(tableScope);
|
||||
}
|
||||
return new GenericKeyedScriptTable(tableScope);
|
||||
}
|
||||
|
||||
private ScriptType EvaluateIndexExpression(BoundIndexExpression e)
|
||||
|
|
|
@ -5,6 +5,7 @@ using System.Collections.Immutable;
|
|||
using System.Linq;
|
||||
using Upsilon.BaseTypes;
|
||||
using Upsilon.BaseTypes.Number;
|
||||
using Upsilon.BaseTypes.ScriptTable;
|
||||
using Upsilon.BaseTypes.ScriptTypeInterfaces;
|
||||
using Upsilon.BaseTypes.UserData;
|
||||
using Upsilon.Binder;
|
||||
|
|
Loading…
Reference in New Issue