Fix binding issue on evaluation

This commit is contained in:
Deukhoofd 2019-01-21 12:57:30 +01:00
parent ca9361cd0f
commit 86f47ae002
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
6 changed files with 28 additions and 13 deletions

View File

@ -2,7 +2,7 @@ using System.Globalization;
namespace Upsilon.BaseTypes.Number
{
internal class ScriptNumberDouble : ScriptNumber
public class ScriptNumberDouble : ScriptNumber
{
public double Value { get; }
protected internal override bool IsFloat { get; } = true;

View File

@ -6,7 +6,7 @@ namespace Upsilon.BaseTypes
{
public class TypeContainer
{
public Type Type { get; }
public Type Type { get; protected set; }
public virtual string UserData { get; }
protected TypeContainer(Type t)
@ -77,6 +77,18 @@ namespace Upsilon.BaseTypes
}
}
internal class IgnoredUserDataTypeContainer : TypeContainer
{
public IgnoredUserDataTypeContainer() : base(BaseTypes.Type.Unknown)
{
Type = Type.UserData;
}
public IgnoredUserDataTypeContainer(string userData) : base(userData)
{
}
}
public class UndefinedUserDataTypeContainer : TypeContainer
{
private System.Type RealType { get; set; }

View File

@ -10,16 +10,7 @@ namespace Upsilon.BaseTypes.UserData
Value = obj;
_typeInfo = UserDataTypeHandler.GetTypeInfo(obj.GetType());
}
public override TypeContainer Type
{
get
{
var typeData = _typeInfo.BoundTypeName;
if (typeData != null)
return new TypeContainer(typeData);
return BaseTypes.Type.Unknown;
}
}
public override TypeContainer Type { get; } = new IgnoredUserDataTypeContainer();
private object Value { get; }
private readonly UserDataType _typeInfo;

View File

@ -14,6 +14,7 @@ namespace Upsilon.BaseTypes.UserData
Subtraction,
Multiplication,
Division,
Modulo
}
public class UserDataTypeOperators
@ -64,6 +65,9 @@ namespace Upsilon.BaseTypes.UserData
case "op_Division":
LoadMethod(OperatorType.Division, methodInfo);
break;
case "op_Modulus":
LoadMethod(OperatorType.Modulo, methodInfo);
break;
}
}
}

View File

@ -43,7 +43,8 @@ namespace Upsilon.BoundTypes
public static string GetTypeName(System.Type type)
{
return TypeDefinitions.FirstOrDefault(x => x.Value.ValidInternalTypes.Contains(type)).Key;
return TypeDefinitions.FirstOrDefault(x =>
x.Value.ValidInternalTypes.Any(validType => validType.IsAssignableFrom(type))).Key;
}
public static void LoadUserDataTypeDefinition(UserDataBoundTypeDefinition def)

View File

@ -352,6 +352,13 @@ namespace Upsilon.Evaluator
{
return ((ScriptNumber)left) % ((ScriptNumber)right);
}
else if (left.Type == Type.UserData)
{
var ud = (GenericUserData) left;
var (type, failed) = ud.BinaryOperator(left, OperatorType.Modulo, right);
if (failed) goto default;
return type;
}
goto default;
case BoundBinaryOperator.OperatorKind.Equality:
return new ScriptBoolean(left.Equals(right));