2using System.Collections.Generic;
3using System.Threading.Tasks;
129 private readonly
bool allNormal;
130 private readonly
int nrArguments;
131 private bool isAsync;
145 throw new ArgumentException(
"Size of ArgumentTypes must match the size of Arguments.", nameof(
ArgumentTypes));
151 this.nrArguments = this.arguments.Length;
153 this.allNormal =
true;
158 this.allNormal =
false;
166 private void CalcIsAsync()
168 this.isAsync =
false;
170 for (
int i = 0; i < this.nrArguments; i++)
207 for (i = 0; i < this.nrArguments; i++)
209 Node = this.arguments[i];
219 return this.EvaluateCanonicalExtension(Arg,
Variables);
229 if (!this.IsAsynchronous)
236 for (i = 0; i < this.nrArguments; i++)
238 Node = this.arguments[i];
248 return await this.EvaluateCanonicalExtensionAsync(Arg,
Variables);
259 LinkedList<IElement> Result =
new LinkedList<IElement>();
262 for (j = 0; j < Dimension; j++)
264 for (i = 0; i < this.nrArguments; i++)
266 if (e[i] is
null || !e[i].MoveNext())
269 Arguments2[i] = e[i].Current;
272 Result.AddLast(this.EvaluateCanonicalExtension(Arguments2,
Variables));
283 ICollection<IElement> ChildElements;
290 e =
new IEnumerator<IElement>[this.nrArguments];
294 for (i = 0; i < this.nrArguments; i++)
298 switch (this.argumentTypes[i])
312 Dimension = ChildElements.Count;
313 else if (ChildElements.Count != Dimension)
316 e[i] = ChildElements.GetEnumerator();
325 else if (!((M = Argument as
IMatrix) is
null))
329 else if (M.
Rows != Dimension)
332 LinkedList<IElement> Vectors =
new LinkedList<IElement>();
334 for (j = 0; j < Dimension; j++)
335 Vectors.AddLast(M.
GetRow(j));
337 e[i] = Vectors.GetEnumerator();
339 Encapsulation = Operators.LambdaDefinition.EncapsulateToVector;
341 else if (!((S = Argument as
ISet) is
null))
348 Dimension = Size.Value;
349 else if (Size.Value != Dimension)
358 Arguments[i] = Operators.Vectors.VectorDefinition.Encapsulate(
new IElement[] { Argument },
false,
this);
364 if (Argument is
ISet)
371 else if (!((M = Argument as
IMatrix) is
null))
375 else if (M.
Rows != Dimension)
378 LinkedList<IElement> Vectors =
new LinkedList<IElement>();
380 for (j = 0; j < Dimension; j++)
381 Vectors.AddLast(M.
GetRow(j));
386 e[i] = ChildElements.GetEnumerator();
388 Encapsulation = Operators.LambdaDefinition.EncapsulateToVector;
392 Arguments[i] = Operators.Sets.SetDefinition.Encapsulate(
new IElement[] { Argument });
405 else if (!((S = Argument as
ISet) is
null))
412 Dimension = Size.Value;
413 else if (Size.Value != Dimension)
422 Arguments[i] = Operators.Matrices.MatrixDefinition.Encapsulate(
new IElement[] { Argument }, 1, 1,
this);
441 LinkedList<IElement> Result =
new LinkedList<IElement>();
444 for (j = 0; j < Dimension; j++)
446 for (i = 0; i < this.nrArguments; i++)
448 if (e[i] is
null || !e[i].MoveNext())
451 Arguments2[i] = e[i].Current;
454 Result.AddLast(await this.EvaluateCanonicalExtensionAsync(Arguments2,
Variables));
495 if (!this.arguments.ForAllChildNodes(Callback, State, Order))
500 bool RecalcIsAsync =
false;
502 for (i = 0; i < this.nrArguments; i++)
504 Node = this.arguments[i];
507 bool b = !Callback(Node, out
ScriptNode NewNode, State);
508 if (!(NewNode is
null))
510 this.arguments[i] = NewNode;
511 NewNode.SetParent(
this);
514 RecalcIsAsync =
true;
532 if (!this.arguments.ForAllChildNodes(Callback, State, Order))
543 AreEqual(this.arguments, O.arguments) &&
544 AreEqual(this.argumentTypes, O.argumentTypes) &&
551 int Result = base.GetHashCode();
552 Result ^= Result << 5 ^
GetHashCode(this.arguments);
553 Result ^= Result << 5 ^
GetHashCode(this.argumentTypes);
Script runtime exception.
Class managing a script expression.
Base class for all funcions.
Base class for multivariate funcions.
static readonly ArgumentType[] argumentTypes3Normal
Three normal parameters.
static readonly ArgumentType[] argumentTypes5Scalar
Five scalar parameters.
override IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
static readonly ArgumentType[] argumentTypes4Normal
Four normal parameters.
static readonly ArgumentType[] argumentTypes1Matrix
One matrix parameter.
static readonly ArgumentType[] argumentTypes8Normal
Eight normal parameters.
static readonly ArgumentType[] argumentTypes2Normal
Two normal parameters.
ScriptNode[] Arguments
Function arguments.
override bool Equals(object obj)
FunctionMultiVariate(ScriptNode[] Arguments, ArgumentType[] ArgumentTypes, int Start, int Length, Expression Expression)
Base class for funcions of one variable.
override int GetHashCode()
static readonly ArgumentType[] argumentTypes2Scalar
Two scalar parameters.
static readonly ArgumentType[] argumentTypes0
Zero parameters.
static readonly ArgumentType[] argumentTypes7Normal
Seven normal parameters.
abstract IElement Evaluate(IElement[] Arguments, Variables Variables)
Evaluates the function.
static readonly ArgumentType[] argumentTypes1Normal
One scalar parameter.
static readonly ArgumentType[] argumentTypes9Normal
Nine normal parameters.
override bool IsAsynchronous
If the node (or its decendants) include asynchronous evaluation. Asynchronous nodes should be evaluat...
static readonly ArgumentType[] argumentTypes1Vector
One vector parameter.
static readonly ArgumentType[] argumentTypes3Scalar
Three scalar parameters.
static readonly ArgumentType[] argumentTypes7Scalar
Seven scalar parameters.
static readonly ArgumentType[] argumentTypes9Scalar
Nine scalar parameters.
static readonly ArgumentType[] argumentTypes8Scalar
Eight scalar parameters.
static readonly ArgumentType[] argumentTypes6Normal
Six normal parameters.
ArgumentType[] ArgumentTypes
Function argument types.
static readonly ArgumentType[] argumentTypes5Normal
Five normal parameters.
virtual Task< IElement > EvaluateAsync(IElement[] Arguments, Variables Variables)
Evaluates the function.
override bool ForAllChildNodes(ScriptNodeEventHandler Callback, object State, SearchMethod Order)
Calls the callback method for all child nodes.
override async Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
static readonly ArgumentType[] argumentTypes1Scalar
One scalar parameter.
static readonly ArgumentType[] argumentTypes1Set
One set parameter.
static readonly ArgumentType[] argumentTypes6Scalar
Six scalar parameters.
static readonly ArgumentType[] argumentTypes4Scalar
Four scalar parameters.
Base class for all nodes in a parsed script tree.
bool ForAllChildNodes(ScriptNodeEventHandler Callback, object State, bool DepthFirst)
Calls the callback method for all child nodes.
int Length
Length of expression covered by node.
static bool AreEqual(ScriptNode S1, ScriptNode S2)
Compares if two script nodes are equal.
int Start
Start position in script expression.
void SetParent(ScriptNode Parent)
Sets the parent node. Can only be used when expression is being parsed.
abstract IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection. This method should be ...
virtual Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection. This method should be ...
static readonly ObjectValue Null
Null value.
Basic interface for all types of elements.
ICollection< IElement > ChildElements
An enumeration of child elements. If the element is a scalar, this property will return null.
IElement Encapsulate(ICollection< IElement > Elements, ScriptNode Node)
Encapsulates a set of elements into a similar structure as that provided by the current element.
bool IsScalar
If the element represents a scalar value.
Basic interface for matrices.
IVector GetRow(int Row)
Gets a row vector from the matrix.
Basic interface for vectors.
int Dimension
Dimension of vector.
Basic interface for all types of module elements.
Basic interface for all types of sets.
int? Size
Size of set, if finite and known, otherwise null is returned.
delegate IElement Encapsulation(ICollection< IElement > Elements, ScriptNode Node)
Delegate for encapsulation methods.
delegate bool ScriptNodeEventHandler(ScriptNode Node, out ScriptNode NewNode, object State)
Delegate for ScriptNode callback methods.
ArgumentType
Type of parameter used in a function definition or a lambda definition.
SearchMethod
Method to traverse the expression structure