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 namespace Upsilon.BaseTypes.Number
{ {
internal class ScriptNumberDouble : ScriptNumber public class ScriptNumberDouble : ScriptNumber
{ {
public double Value { get; } public double Value { get; }
protected internal override bool IsFloat { get; } = true; protected internal override bool IsFloat { get; } = true;

View File

@ -6,7 +6,7 @@ namespace Upsilon.BaseTypes
{ {
public class TypeContainer public class TypeContainer
{ {
public Type Type { get; } public Type Type { get; protected set; }
public virtual string UserData { get; } public virtual string UserData { get; }
protected TypeContainer(Type t) 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 public class UndefinedUserDataTypeContainer : TypeContainer
{ {
private System.Type RealType { get; set; } private System.Type RealType { get; set; }

View File

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

View File

@ -14,6 +14,7 @@ namespace Upsilon.BaseTypes.UserData
Subtraction, Subtraction,
Multiplication, Multiplication,
Division, Division,
Modulo
} }
public class UserDataTypeOperators public class UserDataTypeOperators
@ -64,6 +65,9 @@ namespace Upsilon.BaseTypes.UserData
case "op_Division": case "op_Division":
LoadMethod(OperatorType.Division, methodInfo); LoadMethod(OperatorType.Division, methodInfo);
break; 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) 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) public static void LoadUserDataTypeDefinition(UserDataBoundTypeDefinition def)

View File

@ -352,6 +352,13 @@ namespace Upsilon.Evaluator
{ {
return ((ScriptNumber)left) % ((ScriptNumber)right); 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; goto default;
case BoundBinaryOperator.OperatorKind.Equality: case BoundBinaryOperator.OperatorKind.Equality:
return new ScriptBoolean(left.Equals(right)); return new ScriptBoolean(left.Equals(right));