Fixed issue with userdata type on evaluation
This commit is contained in:
		| @@ -6,7 +6,7 @@ namespace Upsilon.BaseTypes.Number | |||||||
|     { |     { | ||||||
|         protected internal abstract bool IsFloat { get; } |         protected internal abstract bool IsFloat { get; } | ||||||
|  |  | ||||||
|         public override Type Type => Type.Number; |         public override TypeContainer Type => BaseTypes.Type.Number; | ||||||
|  |  | ||||||
|         #region Binary Operators |         #region Binary Operators | ||||||
|  |  | ||||||
|   | |||||||
| @@ -7,7 +7,7 @@ namespace Upsilon.BaseTypes | |||||||
|             Value = value; |             Value = value; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         public override Type Type => Type.Boolean; |         public override TypeContainer Type => BaseTypes.Type.Boolean; | ||||||
|         public override object ToCSharpObject() |         public override object ToCSharpObject() | ||||||
|         { |         { | ||||||
|             return Value; |             return Value; | ||||||
|   | |||||||
| @@ -5,7 +5,7 @@ namespace Upsilon.BaseTypes.ScriptFunction | |||||||
| { | { | ||||||
|     public abstract class ScriptFunction : ScriptType |     public abstract class ScriptFunction : ScriptType | ||||||
|     { |     { | ||||||
|         public override Type Type => Type.Function; |         public override TypeContainer Type => BaseTypes.Type.Function; | ||||||
|         public override object ToCSharpObject() |         public override object ToCSharpObject() | ||||||
|         { |         { | ||||||
|             return this; |             return this; | ||||||
|   | |||||||
| @@ -7,7 +7,7 @@ namespace Upsilon.BaseTypes | |||||||
|     internal abstract class ScriptIterator : ScriptType, IIterable |     internal abstract class ScriptIterator : ScriptType, IIterable | ||||||
|     { |     { | ||||||
|         public IIterable BaseIterator { get; } |         public IIterable BaseIterator { get; } | ||||||
|         public override Type Type => Type.Table; |         public override TypeContainer Type => BaseTypes.Type.Table; | ||||||
|  |  | ||||||
|         public ScriptIterator(IIterable baseIterator) |         public ScriptIterator(IIterable baseIterator) | ||||||
|         { |         { | ||||||
| @@ -46,10 +46,10 @@ namespace Upsilon.BaseTypes | |||||||
|                 while (baseEnumerator.MoveNext()) |                 while (baseEnumerator.MoveNext()) | ||||||
|                 { |                 { | ||||||
|                     var key = baseEnumerator.Current; |                     var key = baseEnumerator.Current; | ||||||
|                     if (key == null || key.Type == Type.Nil) |                     if (key == null || key.Type == BaseTypes.Type.Nil) | ||||||
|                         break; |                         break; | ||||||
|                     var value = BaseIterator.GetValueFromIndex(key); |                     var value = BaseIterator.GetValueFromIndex(key); | ||||||
|                     if (value.Type == Type.Nil) |                     if (value.Type == BaseTypes.Type.Nil) | ||||||
|                         break; |                         break; | ||||||
|                     yield return new SimpleScriptTable(new List<ScriptType>(){key, value}); |                     yield return new SimpleScriptTable(new List<ScriptType>(){key, value}); | ||||||
|                 } |                 } | ||||||
| @@ -72,7 +72,7 @@ namespace Upsilon.BaseTypes | |||||||
|                 { |                 { | ||||||
|                     var key   = baseEnumerator.Current; |                     var key   = baseEnumerator.Current; | ||||||
|                     var value = BaseIterator.GetValueFromIndex(key); |                     var value = BaseIterator.GetValueFromIndex(key); | ||||||
|                     if (value.Type != Type.Nil) |                     if (value.Type != BaseTypes.Type.Nil) | ||||||
|                         yield return new SimpleScriptTable(new List<ScriptType>(){key, value}); |                         yield return new SimpleScriptTable(new List<ScriptType>(){key, value}); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|   | |||||||
| @@ -3,7 +3,7 @@ namespace Upsilon.BaseTypes | |||||||
|     internal class ScriptNull : ScriptType |     internal class ScriptNull : ScriptType | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         public override Type Type => Type.Nil; |         public override TypeContainer Type => BaseTypes.Type.Nil; | ||||||
|         public override object ToCSharpObject() |         public override object ToCSharpObject() | ||||||
|         { |         { | ||||||
|             return null; |             return null; | ||||||
|   | |||||||
| @@ -14,7 +14,7 @@ namespace Upsilon.BaseTypes | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         public string Value { get; } |         public string Value { get; } | ||||||
|         public override Type Type => Type.String; |         public override TypeContainer Type => BaseTypes.Type.String; | ||||||
|         public override object ToCSharpObject() |         public override object ToCSharpObject() | ||||||
|         { |         { | ||||||
|             return Value; |             return Value; | ||||||
| @@ -102,12 +102,12 @@ namespace Upsilon.BaseTypes | |||||||
|         public ScriptType Get(Diagnostics diagnostics, TextSpan span, ScriptType index, EvaluationScope scope) |         public ScriptType Get(Diagnostics diagnostics, TextSpan span, ScriptType index, EvaluationScope scope) | ||||||
|         { |         { | ||||||
|             int i; |             int i; | ||||||
|             if (index.Type == Type.String) |             if (index.Type == BaseTypes.Type.String) | ||||||
|             { |             { | ||||||
|                 var str = (ScriptString)index; |                 var str = (ScriptString)index; | ||||||
|                 i = int.Parse(str.Value); |                 i = int.Parse(str.Value); | ||||||
|             } |             } | ||||||
|             else if (index.Type == Type.Number) |             else if (index.Type == BaseTypes.Type.Number) | ||||||
|             { |             { | ||||||
|                 var ind = (Number.ScriptNumberLong) index; |                 var ind = (Number.ScriptNumberLong) index; | ||||||
|                 i = (int) ind.Value; |                 i = (int) ind.Value; | ||||||
|   | |||||||
| @@ -18,7 +18,7 @@ namespace Upsilon.BaseTypes.ScriptTable | |||||||
|             EvaluationScope = scope; |             EvaluationScope = scope; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         public override Type Type => Type.Table; |         public override TypeContainer Type => BaseTypes.Type.Table; | ||||||
|  |  | ||||||
|         public ScriptType Get(Diagnostics diagnostics, TextSpan span, ScriptType index, EvaluationScope scope) |         public ScriptType Get(Diagnostics diagnostics, TextSpan span, ScriptType index, EvaluationScope scope) | ||||||
|         { |         { | ||||||
| @@ -33,7 +33,7 @@ namespace Upsilon.BaseTypes.ScriptTable | |||||||
|         public void Set(Diagnostics diagnostics, TextSpan span, ScriptType index, ScriptType value) |         public void Set(Diagnostics diagnostics, TextSpan span, ScriptType index, ScriptType value) | ||||||
|         { |         { | ||||||
|             var s = index.ToString(); |             var s = index.ToString(); | ||||||
|             if (value.Type == Type.Nil) |             if (value.Type == BaseTypes.Type.Nil) | ||||||
|             { |             { | ||||||
|                 EvaluationScope.Delete(s); |                 EvaluationScope.Delete(s); | ||||||
|                 return; |                 return; | ||||||
|   | |||||||
| @@ -2,7 +2,7 @@ namespace Upsilon.BaseTypes | |||||||
| { | { | ||||||
|     public abstract class ScriptType |     public abstract class ScriptType | ||||||
|     { |     { | ||||||
|         public abstract Type Type { get; } |         public abstract TypeContainer Type { get; } | ||||||
|         public abstract object ToCSharpObject(); |         public abstract object ToCSharpObject(); | ||||||
|         public abstract System.Type GetCSharpType(); |         public abstract System.Type GetCSharpType(); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -18,15 +18,15 @@ namespace Upsilon.BaseTypes | |||||||
|         public ScriptType Get(Diagnostics diagnostics, TextSpan span, ScriptType index, EvaluationScope scope) |         public ScriptType Get(Diagnostics diagnostics, TextSpan span, ScriptType index, EvaluationScope scope) | ||||||
|         { |         { | ||||||
|             int i; |             int i; | ||||||
|             switch (index.Type) |             switch (index.Type.Type) | ||||||
|             { |             { | ||||||
|                 case Type.String: |                 case BaseTypes.Type.String: | ||||||
|                 { |                 { | ||||||
|                     var str = (ScriptString)index; |                     var str = (ScriptString)index; | ||||||
|                     i = int.Parse(str.Value) - 1; |                     i = int.Parse(str.Value) - 1; | ||||||
|                     break; |                     break; | ||||||
|                 } |                 } | ||||||
|                 case Type.Number: |                 case BaseTypes.Type.Number: | ||||||
|                 { |                 { | ||||||
|                     var ind = (Number.ScriptNumberLong) index; |                     var ind = (Number.ScriptNumberLong) index; | ||||||
|                     i = (int) ind.Value - 1; |                     i = (int) ind.Value - 1; | ||||||
| @@ -46,7 +46,7 @@ namespace Upsilon.BaseTypes | |||||||
|             throw new System.NotImplementedException(); |             throw new System.NotImplementedException(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         public override Type Type => Type.Table; |         public override TypeContainer Type => BaseTypes.Type.Table; | ||||||
|         public override object ToCSharpObject() |         public override object ToCSharpObject() | ||||||
|         { |         { | ||||||
|             return _objects; |             return _objects; | ||||||
|   | |||||||
| @@ -3,6 +3,7 @@ using System.Collections.Generic; | |||||||
| using System.Linq; | using System.Linq; | ||||||
| using Upsilon.BaseTypes.Number; | using Upsilon.BaseTypes.Number; | ||||||
| using Upsilon.BaseTypes.ScriptTypeInterfaces; | using Upsilon.BaseTypes.ScriptTypeInterfaces; | ||||||
|  | using Upsilon.BoundTypes; | ||||||
| using Upsilon.Evaluator; | using Upsilon.Evaluator; | ||||||
| using Upsilon.Text; | using Upsilon.Text; | ||||||
|  |  | ||||||
| @@ -11,10 +12,12 @@ namespace Upsilon.BaseTypes.UserData | |||||||
|     internal class DictionaryUserData : ScriptType, IUserData, ILengthType, IIterable |     internal class DictionaryUserData : ScriptType, IUserData, ILengthType, IIterable | ||||||
|     { |     { | ||||||
|         public IDictionary Dictionary { get; } |         public IDictionary Dictionary { get; } | ||||||
|  |         private string BoundTypeName { get; } | ||||||
|  |  | ||||||
|         public DictionaryUserData(IDictionary dictionary) |         public DictionaryUserData(IDictionary dictionary) | ||||||
|         { |         { | ||||||
|             Dictionary = dictionary; |             Dictionary = dictionary; | ||||||
|  |             BoundTypeName = BoundTypeHandler.GetTypeName(dictionary.GetType()); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         public ScriptType Get(Diagnostics diagnostics, TextSpan span, ScriptType index, EvaluationScope scope) |         public ScriptType Get(Diagnostics diagnostics, TextSpan span, ScriptType index, EvaluationScope scope) | ||||||
| @@ -41,7 +44,7 @@ namespace Upsilon.BaseTypes.UserData | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         public override Type Type => Type.UserData; |         public override TypeContainer Type => new TypeContainer(BoundTypeName); | ||||||
|         public override object ToCSharpObject() |         public override object ToCSharpObject() | ||||||
|         { |         { | ||||||
|             return Dictionary; |             return Dictionary; | ||||||
|   | |||||||
| @@ -10,7 +10,7 @@ namespace Upsilon.BaseTypes.UserData | |||||||
|             Value = obj; |             Value = obj; | ||||||
|             _typeInfo = UserDataTypeHandler.GetTypeInfo(obj.GetType()); |             _typeInfo = UserDataTypeHandler.GetTypeInfo(obj.GetType()); | ||||||
|         } |         } | ||||||
|         public override Type Type => Type.UserData; |         public override TypeContainer Type => new TypeContainer(_typeInfo.BoundTypeName); | ||||||
|  |  | ||||||
|         private object Value { get; } |         private object Value { get; } | ||||||
|         private readonly UserDataType _typeInfo; |         private readonly UserDataType _typeInfo; | ||||||
|   | |||||||
| @@ -3,6 +3,7 @@ using System.Collections; | |||||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||||
| using Upsilon.BaseTypes.Number; | using Upsilon.BaseTypes.Number; | ||||||
| using Upsilon.BaseTypes.ScriptTypeInterfaces; | using Upsilon.BaseTypes.ScriptTypeInterfaces; | ||||||
|  | using Upsilon.BoundTypes; | ||||||
| using Upsilon.Evaluator; | using Upsilon.Evaluator; | ||||||
| using Upsilon.Exceptions; | using Upsilon.Exceptions; | ||||||
| using Upsilon.Text; | using Upsilon.Text; | ||||||
| @@ -12,21 +13,23 @@ namespace Upsilon.BaseTypes.UserData | |||||||
|     internal class ListUserData : ScriptType, IUserData, IIterable, ILengthType |     internal class ListUserData : ScriptType, IUserData, IIterable, ILengthType | ||||||
|     { |     { | ||||||
|         public IList List { get; } |         public IList List { get; } | ||||||
|  |         public string TypeName { get; } | ||||||
|  |  | ||||||
|         public ListUserData(IList list) |         public ListUserData(IList list) | ||||||
|         { |         { | ||||||
|             List = list; |             List = list; | ||||||
|  |             TypeName = BoundTypeHandler.GetTypeName(list.GetType()); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         public ScriptType Get(Diagnostics diagnostics, TextSpan span, ScriptType index, EvaluationScope scope) |         public ScriptType Get(Diagnostics diagnostics, TextSpan span, ScriptType index, EvaluationScope scope) | ||||||
|         { |         { | ||||||
|             int i; |             int i; | ||||||
|             if (index.Type == Type.String) |             if (index.Type == BaseTypes.Type.String) | ||||||
|             { |             { | ||||||
|                 var str = (ScriptString)index; |                 var str = (ScriptString)index; | ||||||
|                 i = int.Parse(str.Value) - 1; |                 i = int.Parse(str.Value) - 1; | ||||||
|             } |             } | ||||||
|             else if (index.Type == Type.Number) |             else if (index.Type == BaseTypes.Type.Number) | ||||||
|             { |             { | ||||||
|                 var ind = (Number.ScriptNumberLong) index; |                 var ind = (Number.ScriptNumberLong) index; | ||||||
|                 i = (int) ind.Value - 1; |                 i = (int) ind.Value - 1; | ||||||
| @@ -41,11 +44,11 @@ namespace Upsilon.BaseTypes.UserData | |||||||
|         public void Set(Diagnostics diagnostics, TextSpan span, ScriptType scriptIndex, ScriptType value) |         public void Set(Diagnostics diagnostics, TextSpan span, ScriptType scriptIndex, ScriptType value) | ||||||
|         { |         { | ||||||
|             var index = -1; |             var index = -1; | ||||||
|             if (scriptIndex.Type == Type.Number || scriptIndex.Type == Type.Unknown) |             if (scriptIndex.Type == BaseTypes.Type.Number || scriptIndex.Type == BaseTypes.Type.Unknown) | ||||||
|             { |             { | ||||||
|                 index = Convert.ToInt32(scriptIndex.ToCSharpObject()); |                 index = Convert.ToInt32(scriptIndex.ToCSharpObject()); | ||||||
|             } |             } | ||||||
|             else if (scriptIndex.Type == Type.String) |             else if (scriptIndex.Type == BaseTypes.Type.String) | ||||||
|             { |             { | ||||||
|                 index = int.Parse(((ScriptString) scriptIndex).Value); |                 index = int.Parse(((ScriptString) scriptIndex).Value); | ||||||
|             } |             } | ||||||
| @@ -75,7 +78,7 @@ namespace Upsilon.BaseTypes.UserData | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         public override Type Type => Type.UserData; |         public override TypeContainer Type => new TypeContainer(TypeName); | ||||||
|         public override object ToCSharpObject() |         public override object ToCSharpObject() | ||||||
|         { |         { | ||||||
|             return List; |             return List; | ||||||
|   | |||||||
| @@ -3,6 +3,7 @@ using System.Globalization; | |||||||
| using System.Linq; | using System.Linq; | ||||||
| using System.Reflection; | using System.Reflection; | ||||||
| using Upsilon.BaseTypes.ScriptFunction; | using Upsilon.BaseTypes.ScriptFunction; | ||||||
|  | using Upsilon.BoundTypes; | ||||||
| using Upsilon.StandardLibraries; | using Upsilon.StandardLibraries; | ||||||
|  |  | ||||||
| namespace Upsilon.BaseTypes.UserData | namespace Upsilon.BaseTypes.UserData | ||||||
| @@ -16,6 +17,7 @@ namespace Upsilon.BaseTypes.UserData | |||||||
|                 type = type.GetGenericTypeDefinition(); |                 type = type.GetGenericTypeDefinition(); | ||||||
|             } |             } | ||||||
|             Type = type; |             Type = type; | ||||||
|  |             BoundTypeName = BoundTypeHandler.GetTypeName(type); | ||||||
|             Variables = type.GetFields().ToDictionary(x => x.Name.ToLowerInvariant(), x => x); |             Variables = type.GetFields().ToDictionary(x => x.Name.ToLowerInvariant(), x => x); | ||||||
|             Properties = type.GetProperties().ToDictionary(x => x.Name.ToLowerInvariant(), x => x); |             Properties = type.GetProperties().ToDictionary(x => x.Name.ToLowerInvariant(), x => x); | ||||||
|             Methods = new Dictionary<string, UserDataMethod>(); |             Methods = new Dictionary<string, UserDataMethod>(); | ||||||
| @@ -44,6 +46,7 @@ namespace Upsilon.BaseTypes.UserData | |||||||
|             OperatorHandler = new UserDataTypeOperators(type); |             OperatorHandler = new UserDataTypeOperators(type); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         public string BoundTypeName { get; } | ||||||
|         private System.Type Type { get; } |         private System.Type Type { get; } | ||||||
|         private Dictionary<string, FieldInfo> Variables { get; } |         private Dictionary<string, FieldInfo> Variables { get; } | ||||||
|         private Dictionary<string, PropertyInfo> Properties { get; } |         private Dictionary<string, PropertyInfo> Properties { get; } | ||||||
|   | |||||||
| @@ -603,8 +603,10 @@ namespace Upsilon.Evaluator | |||||||
|                     { |                     { | ||||||
|                         innerEvaluator.EvaluateStatement(boundStatement); |                         innerEvaluator.EvaluateStatement(boundStatement); | ||||||
|                         if (innerEvaluator._lastValue != null) |                         if (innerEvaluator._lastValue != null) | ||||||
|  |                         { | ||||||
|                             tableScope.CreateLocal(new VariableSymbol(currentPos.ToString(), innerEvaluator._lastValue.Type, false), |                             tableScope.CreateLocal(new VariableSymbol(currentPos.ToString(), innerEvaluator._lastValue.Type, false), | ||||||
|                                 innerEvaluator._lastValue); |                                 innerEvaluator._lastValue); | ||||||
|  |                         } | ||||||
|                         innerEvaluator._lastValue = null; |                         innerEvaluator._lastValue = null; | ||||||
|                         break; |                         break; | ||||||
|                     } |                     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user