47 lines
1.2 KiB
C#
47 lines
1.2 KiB
C#
|
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");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|