KumiScript/interpreter/expression/ProcedureExpression.cs

51 lines
1.2 KiB
C#
Raw Normal View History

2024-01-26 05:37:51 +00:00
namespace KumiScript.Interpreter
{
public class ProcedureExpression : Expression
{
readonly Procedure _proc;
readonly bool _branching;
public ProcedureExpression(Procedure p)
{
_proc = p;
_branching = false;
}
public ProcedureExpression(Procedure p, bool branching)
{
_proc = p;
_branching = branching;
}
public override Expression Eval(Environment env)
{
return this;
}
public Expression Apply(ListExpression args, Environment env)
{
return _proc.ApplyWithArgs(args, env);
}
public override string ToString()
{
if (_proc.IsPrimitive())
return string.Format("#Primitive<{0}>", _proc.ToString());
return string.Format("#Procedure<{0}>", _proc.ToString());
}
public override bool Equals(Expression expr)
{
ProcedureExpression? pe = expr as ProcedureExpression;
if (pe is null)
return false;
return _proc.Equals(pe._proc);
}
public Procedure GetProcedure()
{
return _proc;
}
}
}