Renamed Boolean to differentiate from system boolean type

This commit is contained in:
Deukhoofd 2018-11-14 13:10:24 +01:00
parent deefe43d9f
commit d34e5c85c7
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
5 changed files with 15 additions and 17 deletions

View File

@ -1,8 +1,8 @@
namespace Upsilon.BaseTypes
{
public class Boolean : LuaType
public class LuaBoolean : LuaType
{
public Boolean(bool value)
public LuaBoolean(bool value)
{
Value = value;
}
@ -10,19 +10,19 @@ namespace Upsilon.BaseTypes
public override Type Type => Type.Boolean;
public bool Value { get; }
public static implicit operator bool(Boolean b)
public static implicit operator bool(LuaBoolean b)
{
return b.Value;
}
public static implicit operator Boolean(bool b)
public static implicit operator LuaBoolean(bool b)
{
return new Boolean(b);
return new LuaBoolean(b);
}
public static Boolean operator ! (Boolean n)
public static LuaBoolean operator ! (LuaBoolean n)
{
return new Boolean(!n.Value);
return new LuaBoolean(!n.Value);
}
public override string ToString()

View File

@ -3,7 +3,6 @@ using System.Collections.Immutable;
using Upsilon.BaseTypes;
using Upsilon.BaseTypes.Number;
using Upsilon.Parser;
using Boolean = Upsilon.BaseTypes.Boolean;
using Type = Upsilon.BaseTypes.Type;
namespace Upsilon.Binder
@ -109,7 +108,7 @@ namespace Upsilon.Binder
break;
case bool b:
type = Type.Boolean;
outValue = new Boolean(b);
outValue = new LuaBoolean(b);
break;
default:
_diagnostics.LogUnknownType(e.Span);

View File

@ -3,7 +3,6 @@ using System.Collections.Generic;
using Upsilon.BaseTypes;
using Upsilon.BaseTypes.Number;
using Upsilon.Binder;
using Boolean = Upsilon.BaseTypes.Boolean;
namespace Upsilon.Evaluator
{
@ -84,7 +83,7 @@ namespace Upsilon.Evaluator
case BoundUnaryOperator.OperatorKind.Negation:
return -((Number)operand);
case BoundUnaryOperator.OperatorKind.LogicalNegation:
return !(Boolean) operand;
return !(LuaBoolean) operand;
default:
throw new Exception("Invalid Unary Operator: " + e.Operator.Kind);
}
@ -105,9 +104,9 @@ namespace Upsilon.Evaluator
case BoundBinaryOperator.OperatorKind.Division:
return ((Number)left) / ((Number)right);
case BoundBinaryOperator.OperatorKind.Equality:
return new Boolean(Equals(left, right));
return new LuaBoolean(Equals(left, right));
case BoundBinaryOperator.OperatorKind.Inequality:
return new Boolean(!Equals(left, right));
return new LuaBoolean(!Equals(left, right));
default:
throw new Exception("Invalid Binary Operator: " + e.Operator);
}
@ -136,7 +135,7 @@ namespace Upsilon.Evaluator
private void EvaluateBoundIfStatement(BoundIfStatement boundBlockStatement)
{
var condition = EvaluateExpression(boundBlockStatement.Condition.Expression);
if ((Boolean) condition)
if ((LuaBoolean) condition)
{
EvaluateBoundBlockStatement(boundBlockStatement.Block);
}

View File

@ -1,8 +1,8 @@
using System;
using System.Text;
using Upsilon.BaseTypes;
using Upsilon.BaseTypes.Number;
using Upsilon.Binder;
using Boolean = Upsilon.BaseTypes.Boolean;
using Type = Upsilon.BaseTypes.Type;
namespace UpsilonCompiler
@ -60,7 +60,7 @@ namespace UpsilonCompiler
case Type.Nil:
return "null";
case Type.Boolean:
return ((Boolean)e.Value) ? "true" : "false";
return ((LuaBoolean)e.Value) ? "true" : "false";
case Type.Number:
return ((Number) e.Value).ToString();
case Type.String:

View File

@ -13,7 +13,7 @@ namespace UpsilonTests
var input = "if true then val = true end";
var script = new Script(input);
Assert.Empty(script.Diagnostics.Messages);
var actual = script.Evaluate<Boolean>();
var actual = script.Evaluate<LuaBoolean>();
Assert.True(actual);
}