52 lines
1.8 KiB
C#
52 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Immutable;
|
|
using Upsilon.BaseTypes;
|
|
using Upsilon.BaseTypes.ScriptFunction;
|
|
using Upsilon.Evaluator;
|
|
using Upsilon.Text;
|
|
using Type = Upsilon.BaseTypes.Type;
|
|
|
|
namespace Upsilon.Binder
|
|
{
|
|
public class BoundFunctionExpression : BoundExpression, IBoundNodeScopeOwner
|
|
{
|
|
public ImmutableArray<BoundVariableSymbol> Parameters { get; }
|
|
public BoundBlockStatement Block { get; set; }
|
|
public bool IsCoroutine { get; }
|
|
|
|
public BoundFunctionExpression(ImmutableArray<BoundVariableSymbol> parameters, BoundBlockStatement block,
|
|
TextSpan span, BoundScope scope, TypeContainer returnType, bool isCoroutine) : base(span)
|
|
{
|
|
Parameters = parameters;
|
|
Block = block;
|
|
Scope = scope;
|
|
ReturnType = returnType;
|
|
IsCoroutine = isCoroutine;
|
|
}
|
|
|
|
public override BoundKind Kind => BoundKind.BoundFunctionExpression;
|
|
|
|
public override IEnumerable<BoundNode> GetChildren()
|
|
{
|
|
foreach (var parameter in Parameters)
|
|
{
|
|
yield return parameter;
|
|
}
|
|
yield return Block;
|
|
}
|
|
|
|
public override TypeContainer ValueType => Type.Function;
|
|
internal override ScriptType Evaluate(EvaluationScope scope, Diagnostics diagnostics, ref EvaluationState state)
|
|
{
|
|
var option = new ScriptRuntimeFunction.ScriptRuntimeFunctionOption(Parameters, Block, scope);
|
|
var func = new ScriptRuntimeFunction("<anonymous>", new List<ScriptRuntimeFunction.ScriptRuntimeFunctionOption>() {option},
|
|
IsCoroutine);
|
|
return func;
|
|
|
|
}
|
|
|
|
public BoundScope Scope { get; set; }
|
|
public TypeContainer ReturnType { get; }
|
|
}
|
|
} |