periodic checkpoint

This commit is contained in:
Jordan Wages 2025-08-20 03:48:58 -05:00
commit e458cdd910
2 changed files with 38 additions and 6 deletions

View file

@ -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
{ {

View 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;
}
}
}