periodic checkpoint
This commit is contained in:
parent
b1e9e58783
commit
e458cdd910
2 changed files with 38 additions and 6 deletions
|
@ -3,7 +3,7 @@ using ValueType = csmic.ValueType;
|
||||||
|
|
||||||
namespace stdlib.functions
|
namespace stdlib.functions
|
||||||
{
|
{
|
||||||
public class AbsoluteValue : ICodedFunction
|
public class AbsoluteValue : FunctionBase, ICodedFunction
|
||||||
{
|
{
|
||||||
public IEnumerable<FunctionArgument> ExpectedArguments
|
public IEnumerable<FunctionArgument> ExpectedArguments
|
||||||
{
|
{
|
||||||
|
@ -13,14 +13,15 @@ namespace stdlib.functions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public FunctionValue ReturnValue => new FunctionValue(ValueType.Numeric, 0m);
|
public FunctionValue ReturnValue
|
||||||
|
{
|
||||||
|
new FunctionValue(ValueType.Numeric, 0m);
|
||||||
|
}
|
||||||
|
=>
|
||||||
|
|
||||||
public FunctionValue Execute(params FunctionArgument[] args)
|
public FunctionValue Execute(params FunctionArgument[] args)
|
||||||
{
|
{
|
||||||
if (args == null || args.Length < 1 || args[0] == null || args[0].Value == null)
|
base.ArgumentCheck(args);
|
||||||
{
|
|
||||||
return new FunctionValue(ValueType.None, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
31
src/stdlib/functions/FunctionBase.cs
Normal file
31
src/stdlib/functions/FunctionBase.cs
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
using csmic;
|
||||||
|
using ValueType = csmic.ValueType;
|
||||||
|
|
||||||
|
namespace stdlib.functions
|
||||||
|
{
|
||||||
|
public abstract class FunctionBase
|
||||||
|
{
|
||||||
|
public virtual IEnumerable<FunctionArgument> ExpectedArguments { get; }
|
||||||
|
|
||||||
|
internal bool ArgumentCheck(params FunctionArgument[] args)
|
||||||
|
{
|
||||||
|
if (args == null || args.Length != this.ExpectedArguments.Count())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var expectedArgumentsArray = this.ExpectedArguments.ToArray();
|
||||||
|
for (int i = 0; i < args.Length; i++)
|
||||||
|
{
|
||||||
|
var expectedArgument = expectedArgumentsArray[i];
|
||||||
|
var argument = args[i];
|
||||||
|
if(argument.Value == null || argument.Value.Type != expectedArgument.Value.Type)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue