tlang-interperter-cs/tlanglib/MemberGetValueNode.cs

99 lines
2.5 KiB
C#

namespace tlang
{
public class MemberGetVariableValue : GetVariableValue
{
public Node Parent {get;set;}
public MemberGetVariableValue(Node parent,string text) : base(text)
{
Parent = parent;
}
public override void SetValue(IScopeEnvironment nodeEnv, TObject value)
{
var res=Parent.Execute(nodeEnv);
var dict = res as TDictionary;
if(dict != null)
{
if(dict.MemberExists($"set{Name}"))
{
var mbm= dict[$"set{Name}"] as ICallable;
if(mbm != null)
{
mbm.Call(value);
}
}else{
dict[Name] = value;
}
}
}
public override TObject Execute(IScopeEnvironment nodeEnv)
{
var res=Parent.Execute(nodeEnv);
var dict = res as TDictionary;
var integer = res as TNumber;
var array = res as TArray;
var str = res as TString;
if(array != null)
{
if(Name == "length" || Name == "count")
{
return new TNumber(array.Items.Count);
}
}
if(dict != null)
{
if(dict.MemberExists($"get{Name}"))
{
var mbm= dict[$"get{Name}"] as ICallable;
if(mbm != null)
return mbm.Call();
}
if(dict.MemberExists(Name))
{
return dict[Name];
}
}
if(integer != null)
{
if(Name == "abs")
{
return new TNumber(Math.Abs(integer.Value));
}
if(Name == "int")
{
return new TNumber(Math.Round(integer.Value));
}
}
if(str != null)
{
if(Name == "number")
{
}
if(Name == "ittr")
{
}
if(Name == "length" || Name == "count")
{
return new TNumber(str.Value.Length);
}
if(Name == "list")
{
}
}
return new TUninit();
}
}
}