tlang-interperter-cs/tlanglib/BitwiseNot.cs

37 lines
867 B
C#
Raw Normal View History

2023-06-08 18:14:35 +00:00
namespace tlang
{
public class BitwiseNot : Node
{
public Node Node {get;set;}
public BitwiseNot(Node node)
{
this.Node = node;
}
public override TObject Execute(IScopeEnvironment nodeEnv)
{
var l = Node.Execute(nodeEnv);
var lnum = l as TNumber;
var dleft = l as TDictionary;
if(dleft != null)
{
if(dleft.MemberExists("bnot"))
{
var mbm = dleft["bnot"] as ICallable;
if(mbm != null)
{
return mbm.Call();
}
}
}
if(lnum != null)
return TObject.Number(~(long)lnum.Value);
return TObject.Null;
}
}
}