Move ScriptFunctions to own namespace

This commit is contained in:
Deukhoofd 2018-11-30 11:15:52 +01:00
parent 9455b753a0
commit 3a3ed071d2
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
7 changed files with 63 additions and 55 deletions

View File

@ -0,0 +1,18 @@
namespace Upsilon.BaseTypes.ScriptFunction
{
internal abstract class ScriptFunction : ScriptType
{
public override Type Type => Type.Function;
public override object ToCSharpObject()
{
return this;
}
public override System.Type GetCSharpType()
{
return null;
}
public abstract ScriptType Run(Diagnostics diagnostics, ScriptType[] variables);
}
}

View File

@ -1,71 +1,24 @@
using System;
using System.Collections.Immutable;
using System.Linq;
using System.Reflection;
using Upsilon.BaseTypes.ScriptTypeInterfaces;
using Upsilon.BaseTypes.UserData;
using Upsilon.Binder;
using Upsilon.Evaluator;
namespace Upsilon.BaseTypes
namespace Upsilon.BaseTypes.ScriptFunction
{
internal abstract class ScriptFunction : ScriptType
{
public override Type Type => Type.Function;
public override object ToCSharpObject()
{
return this;
}
public override System.Type GetCSharpType()
{
return null;
}
public abstract ScriptType Run(Diagnostics diagnostics, ScriptType[] variables);
}
internal class ScriptRuntimeFunction : ScriptFunction, IScopeOwner
{
public BoundBlockStatement Block { get; }
public ImmutableArray<BoundVariableSymbol> Parameters { get; }
public EvaluationScope EvaluationScope { get; }
public ScriptRuntimeFunction(ImmutableArray<BoundVariableSymbol> parameters, BoundBlockStatement block,
EvaluationScope evaluationScope)
{
Parameters = parameters;
Block = block;
EvaluationScope = evaluationScope;
}
public override ScriptType Run(Diagnostics diagnostics, ScriptType[] variables)
{
var innerEvaluator = new Evaluator.Evaluator(diagnostics, EvaluationScope);
for (var i = 0; i < Parameters.Length; i++)
{
var parameterVariable = Parameters[i];
var parameterValue = variables[i];
innerEvaluator.Scope.CreateLocal(parameterVariable.VariableSymbol, parameterValue);
}
return innerEvaluator.EvaluateNode(Block);
}
}
internal class ScriptMethodInfoFunction : ScriptFunction
{
public ScriptMethodInfoFunction(UserDataMethod method, object o, bool directTypeManipulation)
{
_method = method;
_object = o;
_method = method;
_object = o;
_directTypeManipulation = directTypeManipulation;
ReturnType = _method.ReturnType;
ReturnType = _method.ReturnType;
}
private readonly UserDataMethod _method;
private readonly object _object;
private readonly bool _directTypeManipulation;
public System.Type ReturnType { get; }
private readonly object _object;
private readonly bool _directTypeManipulation;
public System.Type ReturnType { get; }
public override ScriptType Run(Diagnostics diagnostics, ScriptType[] variables)
{

View File

@ -0,0 +1,34 @@
using System.Collections.Immutable;
using Upsilon.BaseTypes.ScriptTypeInterfaces;
using Upsilon.Binder;
using Upsilon.Evaluator;
namespace Upsilon.BaseTypes.ScriptFunction
{
internal class ScriptRuntimeFunction : ScriptFunction, IScopeOwner
{
public BoundBlockStatement Block { get; }
public ImmutableArray<BoundVariableSymbol> Parameters { get; }
public EvaluationScope EvaluationScope { get; }
public ScriptRuntimeFunction(ImmutableArray<BoundVariableSymbol> parameters, BoundBlockStatement block,
EvaluationScope evaluationScope)
{
Parameters = parameters;
Block = block;
EvaluationScope = evaluationScope;
}
public override ScriptType Run(Diagnostics diagnostics, ScriptType[] variables)
{
var innerEvaluator = new Evaluator.Evaluator(diagnostics, EvaluationScope);
for (var i = 0; i < Parameters.Length; i++)
{
var parameterVariable = Parameters[i];
var parameterValue = variables[i];
innerEvaluator.Scope.CreateLocal(parameterVariable.VariableSymbol, parameterValue);
}
return innerEvaluator.EvaluateNode(Block);
}
}
}

View File

@ -94,7 +94,7 @@ namespace Upsilon.BaseTypes
return Type.String;
if (typeof(ScriptNumber).IsAssignableFrom(t))
return Type.Number;
if (typeof(ScriptFunction).IsAssignableFrom(t))
if (typeof(ScriptFunction.ScriptFunction).IsAssignableFrom(t))
return Type.Function;
if (typeof(ScriptTable).IsAssignableFrom(t))
return Type.Table;

View File

@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Upsilon.BaseTypes.ScriptFunction;
namespace Upsilon.BaseTypes.UserData
{

View File

@ -4,6 +4,7 @@ using System.Collections.Immutable;
using System.Net.Http.Headers;
using Upsilon.BaseTypes;
using Upsilon.BaseTypes.Number;
using Upsilon.BaseTypes.ScriptFunction;
using Upsilon.BaseTypes.ScriptTypeInterfaces;
using Upsilon.BaseTypes.UserData;
using Upsilon.Binder;

View File

@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Reflection;
using Upsilon.BaseTypes;
using Upsilon.BaseTypes.ScriptFunction;
using Upsilon.BaseTypes.UserData;
namespace Upsilon.StandardLibraries