ShintenScript/ASTNodeLiteral.cs

47 lines
1.2 KiB
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 ASTNodeLiteral : IASTNode
{
public readonly object value;
public ASTNodeLiteral(object value)
{
this.value = value;
}
public bool Const() => true;
public object CreateFunction()
{
SSType type = Type();
if (type == SSType.none) return (Action<ExecutionContext>)(ctx => { });
if (type == SSType.boolean) return (bool)value ? (Func<ExecutionContext, bool>)(ctx => true) : ctx => false;
if (type == SSType.real)
{
float real = (float)value;
return (Func<ExecutionContext, float>)(ctx => real);
}
throw new Exception("This should be unreachable");
}
public SSType Type()
{
if (value == null) return SSType.none;
if (value is bool) return SSType.boolean;
if (value is float) return SSType.real;
throw new Exception("This should be unreachable");
}
}
}