tlang-interperter-cs/MemberFunctionCallNode.cs

47 lines
1.2 KiB
C#

namespace tlang
{
internal class MemberFunctionCallNode : FunctionCallNode
{
public Node Parent {get;set;}
public MemberFunctionCallNode(Node parent, string name, List<Node> args) : base(name,args)
{
Parent = parent;
}
public override TObject Execute(IScopeEnvironment nodeEnv)
{
var res=Parent.Execute(nodeEnv);
var dict = res as TDictionary;
var integer = res as TNumber;
if(dict != null)
{
var n = dict[Text] as ICallable;
if(n != null)
{
return n.Call(Args.Select<Node,TObject>(e=>e.Execute(nodeEnv)).ToArray());
}
}
else if(integer != null)
{
if(Text == "toString")
{
return new TString(integer.Value.ToString());
}
if(Text == "abs")
{
return new TNumber(Math.Abs(integer.Value));
}
}
if(Text == "toString") return new TString("");
return new TUninit();
}
}
}