tlang-interperter-cs/tlanglib/NegativeNode.cs

38 lines
861 B
C#
Raw Normal View History

2023-06-08 18:14:35 +00:00
namespace tlang
{
public class NegativeNode : Node
{
public Node Node {get;set;}
public NegativeNode(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("neg"))
{
var mbm = dleft["neg"] as ICallable;
if(mbm != null)
{
return mbm.Call();
}
}
}
if(lnum != null)
return TObject.Number(-lnum.Value);
return TObject.Null;
}
}
}