tlang-interperter-cs/tlanglib/NotEqualsNode.cs

63 lines
2.0 KiB
C#
Raw Normal View History

2023-03-10 10:12:51 +00:00
namespace tlang
{
internal class NotEqualsNode : Node
{
public Node Left {get;set;}
public Node Right {get;set;}
public NotEqualsNode(Node left, Node right)
{
this.Left = left;
this.Right = right;
}
public override TObject Execute(IScopeEnvironment nodeEnv)
{
var l = Left.Execute(nodeEnv);
var r = Right.Execute(nodeEnv);
2023-06-08 18:14:35 +00:00
var lnum = l as TNumber;
2023-03-10 10:12:51 +00:00
var rnum = r as TNumber;
2023-06-08 18:14:35 +00:00
var lstr = l as TString;
var rstr = r as TString;
var lbool = l as TBoolean;
var rbool = r as TBoolean;
var lchar = l as TChar;
var rchar = r as TChar;
2023-03-10 10:12:51 +00:00
var dleft = l as TDictionary;
if(dleft != null)
{
if(dleft.MemberExists("neq"))
{
var mbm = dleft["neq"] as ICallable;
if(mbm != null)
{
return mbm.Call(r);
2023-06-08 18:14:35 +00:00
}else {
var dright = r as TDictionary;
if(dright != null)
{
return TObject.Boolean(dleft != dright);
}
}
} else {
var dright = r as TDictionary;
if(dright != null)
{
return TObject.Boolean(dleft != dright);
}
2023-03-10 10:12:51 +00:00
}
}
if(lnum != null && rnum != null)
2023-06-08 18:14:35 +00:00
return TObject.Boolean(lnum.Value != rnum.Value);
if(lbool != null && rbool != null)
return TObject.Boolean(lbool.Value != rbool.Value);
if(lstr != null && rstr != null)
return TObject.Boolean(lstr.Value != rstr.Value);
if(lchar != null && rchar != null)
return TObject.Boolean(lchar.Value != rchar.Value);
return TObject.Null;
2023-03-10 10:12:51 +00:00
}
}
}