ShintenScript/ASTNodeNegative.cs

38 lines
861 B
C#
Raw Normal View History

2023-02-02 14:05:53 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ShintenScript
{
public class ASTNodeNegative : IASTNode
{
public IASTNode node;
public ASTNodeNegative(IASTNode of)
{
node = of;
}
public bool Const()
{
return node.Const();
}
public object CreateFunction()
{
Func<ExecutionContext, float> func = (Func<ExecutionContext, float>)node.CreateFunction();
return (Func<ExecutionContext, float>)(ctx => -func(ctx));
}
public SSType Type()
{
if (node.Type() != SSType.real)
throw new TypeException($"Unary '-' operator not supported for {node.Type()}");
return SSType.real;
}
}
}