Move ScriptFunctions to own namespace
This commit is contained in:
parent
9455b753a0
commit
3a3ed071d2
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,71 +1,24 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Immutable;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Upsilon.BaseTypes.ScriptTypeInterfaces;
|
|
||||||
using Upsilon.BaseTypes.UserData;
|
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
|
internal class ScriptMethodInfoFunction : ScriptFunction
|
||||||
{
|
{
|
||||||
public ScriptMethodInfoFunction(UserDataMethod method, object o, bool directTypeManipulation)
|
public ScriptMethodInfoFunction(UserDataMethod method, object o, bool directTypeManipulation)
|
||||||
{
|
{
|
||||||
_method = method;
|
_method = method;
|
||||||
_object = o;
|
_object = o;
|
||||||
_directTypeManipulation = directTypeManipulation;
|
_directTypeManipulation = directTypeManipulation;
|
||||||
ReturnType = _method.ReturnType;
|
ReturnType = _method.ReturnType;
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly UserDataMethod _method;
|
private readonly UserDataMethod _method;
|
||||||
private readonly object _object;
|
private readonly object _object;
|
||||||
private readonly bool _directTypeManipulation;
|
private readonly bool _directTypeManipulation;
|
||||||
public System.Type ReturnType { get; }
|
public System.Type ReturnType { get; }
|
||||||
|
|
||||||
public override ScriptType Run(Diagnostics diagnostics, ScriptType[] variables)
|
public override ScriptType Run(Diagnostics diagnostics, ScriptType[] variables)
|
||||||
{
|
{
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -94,7 +94,7 @@ namespace Upsilon.BaseTypes
|
||||||
return Type.String;
|
return Type.String;
|
||||||
if (typeof(ScriptNumber).IsAssignableFrom(t))
|
if (typeof(ScriptNumber).IsAssignableFrom(t))
|
||||||
return Type.Number;
|
return Type.Number;
|
||||||
if (typeof(ScriptFunction).IsAssignableFrom(t))
|
if (typeof(ScriptFunction.ScriptFunction).IsAssignableFrom(t))
|
||||||
return Type.Function;
|
return Type.Function;
|
||||||
if (typeof(ScriptTable).IsAssignableFrom(t))
|
if (typeof(ScriptTable).IsAssignableFrom(t))
|
||||||
return Type.Table;
|
return Type.Table;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using Upsilon.BaseTypes.ScriptFunction;
|
||||||
|
|
||||||
namespace Upsilon.BaseTypes.UserData
|
namespace Upsilon.BaseTypes.UserData
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,6 +4,7 @@ using System.Collections.Immutable;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using Upsilon.BaseTypes;
|
using Upsilon.BaseTypes;
|
||||||
using Upsilon.BaseTypes.Number;
|
using Upsilon.BaseTypes.Number;
|
||||||
|
using Upsilon.BaseTypes.ScriptFunction;
|
||||||
using Upsilon.BaseTypes.ScriptTypeInterfaces;
|
using Upsilon.BaseTypes.ScriptTypeInterfaces;
|
||||||
using Upsilon.BaseTypes.UserData;
|
using Upsilon.BaseTypes.UserData;
|
||||||
using Upsilon.Binder;
|
using Upsilon.Binder;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Upsilon.BaseTypes;
|
using Upsilon.BaseTypes;
|
||||||
|
using Upsilon.BaseTypes.ScriptFunction;
|
||||||
using Upsilon.BaseTypes.UserData;
|
using Upsilon.BaseTypes.UserData;
|
||||||
|
|
||||||
namespace Upsilon.StandardLibraries
|
namespace Upsilon.StandardLibraries
|
||||||
|
|
Loading…
Reference in New Issue