Renamed Boolean to differentiate from system boolean type
This commit is contained in:
parent
deefe43d9f
commit
d34e5c85c7
|
@ -1,8 +1,8 @@
|
||||||
namespace Upsilon.BaseTypes
|
namespace Upsilon.BaseTypes
|
||||||
{
|
{
|
||||||
public class Boolean : LuaType
|
public class LuaBoolean : LuaType
|
||||||
{
|
{
|
||||||
public Boolean(bool value)
|
public LuaBoolean(bool value)
|
||||||
{
|
{
|
||||||
Value = value;
|
Value = value;
|
||||||
}
|
}
|
||||||
|
@ -10,19 +10,19 @@ namespace Upsilon.BaseTypes
|
||||||
public override Type Type => Type.Boolean;
|
public override Type Type => Type.Boolean;
|
||||||
public bool Value { get; }
|
public bool Value { get; }
|
||||||
|
|
||||||
public static implicit operator bool(Boolean b)
|
public static implicit operator bool(LuaBoolean b)
|
||||||
{
|
{
|
||||||
return b.Value;
|
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()
|
public override string ToString()
|
|
@ -3,7 +3,6 @@ using System.Collections.Immutable;
|
||||||
using Upsilon.BaseTypes;
|
using Upsilon.BaseTypes;
|
||||||
using Upsilon.BaseTypes.Number;
|
using Upsilon.BaseTypes.Number;
|
||||||
using Upsilon.Parser;
|
using Upsilon.Parser;
|
||||||
using Boolean = Upsilon.BaseTypes.Boolean;
|
|
||||||
using Type = Upsilon.BaseTypes.Type;
|
using Type = Upsilon.BaseTypes.Type;
|
||||||
|
|
||||||
namespace Upsilon.Binder
|
namespace Upsilon.Binder
|
||||||
|
@ -109,7 +108,7 @@ namespace Upsilon.Binder
|
||||||
break;
|
break;
|
||||||
case bool b:
|
case bool b:
|
||||||
type = Type.Boolean;
|
type = Type.Boolean;
|
||||||
outValue = new Boolean(b);
|
outValue = new LuaBoolean(b);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
_diagnostics.LogUnknownType(e.Span);
|
_diagnostics.LogUnknownType(e.Span);
|
||||||
|
|
|
@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||||
using Upsilon.BaseTypes;
|
using Upsilon.BaseTypes;
|
||||||
using Upsilon.BaseTypes.Number;
|
using Upsilon.BaseTypes.Number;
|
||||||
using Upsilon.Binder;
|
using Upsilon.Binder;
|
||||||
using Boolean = Upsilon.BaseTypes.Boolean;
|
|
||||||
|
|
||||||
namespace Upsilon.Evaluator
|
namespace Upsilon.Evaluator
|
||||||
{
|
{
|
||||||
|
@ -84,7 +83,7 @@ namespace Upsilon.Evaluator
|
||||||
case BoundUnaryOperator.OperatorKind.Negation:
|
case BoundUnaryOperator.OperatorKind.Negation:
|
||||||
return -((Number)operand);
|
return -((Number)operand);
|
||||||
case BoundUnaryOperator.OperatorKind.LogicalNegation:
|
case BoundUnaryOperator.OperatorKind.LogicalNegation:
|
||||||
return !(Boolean) operand;
|
return !(LuaBoolean) operand;
|
||||||
default:
|
default:
|
||||||
throw new Exception("Invalid Unary Operator: " + e.Operator.Kind);
|
throw new Exception("Invalid Unary Operator: " + e.Operator.Kind);
|
||||||
}
|
}
|
||||||
|
@ -105,9 +104,9 @@ namespace Upsilon.Evaluator
|
||||||
case BoundBinaryOperator.OperatorKind.Division:
|
case BoundBinaryOperator.OperatorKind.Division:
|
||||||
return ((Number)left) / ((Number)right);
|
return ((Number)left) / ((Number)right);
|
||||||
case BoundBinaryOperator.OperatorKind.Equality:
|
case BoundBinaryOperator.OperatorKind.Equality:
|
||||||
return new Boolean(Equals(left, right));
|
return new LuaBoolean(Equals(left, right));
|
||||||
case BoundBinaryOperator.OperatorKind.Inequality:
|
case BoundBinaryOperator.OperatorKind.Inequality:
|
||||||
return new Boolean(!Equals(left, right));
|
return new LuaBoolean(!Equals(left, right));
|
||||||
default:
|
default:
|
||||||
throw new Exception("Invalid Binary Operator: " + e.Operator);
|
throw new Exception("Invalid Binary Operator: " + e.Operator);
|
||||||
}
|
}
|
||||||
|
@ -136,7 +135,7 @@ namespace Upsilon.Evaluator
|
||||||
private void EvaluateBoundIfStatement(BoundIfStatement boundBlockStatement)
|
private void EvaluateBoundIfStatement(BoundIfStatement boundBlockStatement)
|
||||||
{
|
{
|
||||||
var condition = EvaluateExpression(boundBlockStatement.Condition.Expression);
|
var condition = EvaluateExpression(boundBlockStatement.Condition.Expression);
|
||||||
if ((Boolean) condition)
|
if ((LuaBoolean) condition)
|
||||||
{
|
{
|
||||||
EvaluateBoundBlockStatement(boundBlockStatement.Block);
|
EvaluateBoundBlockStatement(boundBlockStatement.Block);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using Upsilon.BaseTypes;
|
||||||
using Upsilon.BaseTypes.Number;
|
using Upsilon.BaseTypes.Number;
|
||||||
using Upsilon.Binder;
|
using Upsilon.Binder;
|
||||||
using Boolean = Upsilon.BaseTypes.Boolean;
|
|
||||||
using Type = Upsilon.BaseTypes.Type;
|
using Type = Upsilon.BaseTypes.Type;
|
||||||
|
|
||||||
namespace UpsilonCompiler
|
namespace UpsilonCompiler
|
||||||
|
@ -60,7 +60,7 @@ namespace UpsilonCompiler
|
||||||
case Type.Nil:
|
case Type.Nil:
|
||||||
return "null";
|
return "null";
|
||||||
case Type.Boolean:
|
case Type.Boolean:
|
||||||
return ((Boolean)e.Value) ? "true" : "false";
|
return ((LuaBoolean)e.Value) ? "true" : "false";
|
||||||
case Type.Number:
|
case Type.Number:
|
||||||
return ((Number) e.Value).ToString();
|
return ((Number) e.Value).ToString();
|
||||||
case Type.String:
|
case Type.String:
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace UpsilonTests
|
||||||
var input = "if true then val = true end";
|
var input = "if true then val = true end";
|
||||||
var script = new Script(input);
|
var script = new Script(input);
|
||||||
Assert.Empty(script.Diagnostics.Messages);
|
Assert.Empty(script.Diagnostics.Messages);
|
||||||
var actual = script.Evaluate<Boolean>();
|
var actual = script.Evaluate<LuaBoolean>();
|
||||||
Assert.True(actual);
|
Assert.True(actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue