Beispiel #1
0
        public static StringValue Substring(FunctionArgument _args, EvalContext cal)
        {
            var args = _args.Arguments;

            OperationHelper.AssertArgsNumberThrowIf(null, 3, args);
            OperationHelper.AssertCertainValueThrowIf(null, args);
            var ov    = cal.GetValue <StringValue>(args[0]);
            var begin = (int)cal.GetValue <RealNumber>(args[1]);
            var len   = (int)cal.GetValue <RealNumber>(args[2]);

            return(new StringValue(ov.Value.Substring(begin, len)));
        }
Beispiel #2
0
        public void Push(FunctionArgument _args, EvalContext cal)
        {
            OperationHelper.AssertArgsNumberThrowIf(this, 1, _args.Arguments);
            var v = cal.GetValue <IValue>(_args.Arguments[0]);

            stack.Enqueue(v);
        }
Beispiel #3
0
        static void Execute(ForeachFunctionValue main, FunctionArgument args, EvalContext cal)
        {
            var children = args.Contents;

            try
            {
                IEnumerableValue l = cal.GetValue <IEnumerableValue>(cal.Evaluate(main.Collection));
                foreach (var t in l)
                {
                    cal.Variables.Set(main.Vid, t);
                    try
                    {
                        foreach (var v in children)
                        {
                            cal.Evaluate(v);
                        }
                    }
                    catch (BContinue)
                    {
                        continue;
                    }
                }
            }
            catch (BBreak)
            {
                return;
            }
        }
Beispiel #4
0
        static void Execute(ForFunctionValue main, FunctionArgument args, EvalContext cal)
        {
            var children = args.Contents;

            try
            {
                for (cal.Evaluate(main.Begin);
                     cal.GetValue <bool>(cal.Evaluate(main.Condition));
                     cal.Evaluate(main.Step))
                {
                    try
                    {
                        foreach (var v in children)
                        {
                            cal.Evaluate(v);
                        }
                    }
                    catch (BContinue)
                    {
                        continue;
                    }
                }
            }
            catch (BBreak)
            {
                return;
            }
        }
Beispiel #5
0
        static void Execute(DoWhileFunctionValue main, FunctionArgument args, EvalContext cal)
        {
            var children = args.Contents;

            try
            {
                do
                {
                    try
                    {
                        foreach (var v in children)
                        {
                            cal.Evaluate(v);
                        }
                    }
                    catch (BContinue)
                    {
                        continue;
                    }
                }while (cal.GetValue <bool>(cal.Evaluate(main.Condition)));
            }
            catch (BBreak)
            {
                return;
            }
        }
Beispiel #6
0
        public object Has(FunctionArgument _args, EvalContext cal)
        {
            var args = _args.Arguments;

            OperationHelper.AssertArgsNumberThrowIf(this, 1, args);
            OperationHelper.AssertCertainValueThrowIf(this, args);
            var ov = cal.GetValue <IValue>(args[0]);

            return(this.Contains(ov));
        }
Beispiel #7
0
        public static FileEasyWriter OpenEasyWrite(FunctionArgument _args, EvalContext cal)
        {
            var args = _args.Arguments;

            OperationHelper.AssertArgsNumberThrowIf(null, 1, args);
            OperationHelper.AssertCertainValueThrowIf(null, args);
            var ov = cal.GetValue <StringValue>(args)[0];

            return(new FileEasyWriter(ov));
        }
Beispiel #8
0
        public static bool Exists(FunctionArgument _args, EvalContext cal)
        {
            var args = _args.Arguments;

            OperationHelper.AssertArgsNumberThrowIf(null, 1, args);
            OperationHelper.AssertCertainValueThrowIf(null, args);
            var ov = cal.GetValue <StringValue>(args)[0];

            return(File.Exists(ov));
        }
Beispiel #9
0
        public static number Cos(FunctionArgument _args, EvalContext cal)
        {
            var args = _args.Arguments;

            OperationHelper.AssertArgsNumberThrowIf(null, 1, args);
            OperationHelper.AssertCertainValueThrowIf(null, args);
            var ov = cal.GetValue <number>(args[0]);

            return(new number(System.Math.Cos(ov)));
        }
Beispiel #10
0
        public static TupleValue Split(FunctionArgument _args, EvalContext cal)
        {
            var args = _args.Arguments;

            OperationHelper.AssertArgsNumberThrowIf(null, 2, args);
            OperationHelper.AssertCertainValueThrowIf(null, args);
            var ov = cal.GetValue <StringValue>(args);

            return(new TupleValue(ov[0].Value.Split(ov[1].Value[0]).Select(x => new iExpr.Values.ConcreteValue(new StringValue(x)))));
        }
Beispiel #11
0
        public static StringValue Remove(FunctionArgument _args, EvalContext cal)
        {
            var args = _args.Arguments;

            OperationHelper.AssertCertainValueThrowIf(null, args);
            if (OperationHelper.AssertArgsNumber(3, args))
            {
                var ov    = cal.GetValue <StringValue>(args[0]);
                var begin = (int)cal.GetValue <RealNumber>(args[1]);
                var len   = (int)cal.GetValue <RealNumber>(args[2]);
                return(new StringValue(ov.Value.Remove(begin, len)));
            }
            else if (OperationHelper.AssertArgsNumber(2, args))
            {
                var ov    = cal.GetValue <StringValue>(args[0]);
                var begin = (int)cal.GetValue <RealNumber>(args[1]);
                return(new StringValue(ov.Value.Remove(begin)));
            }
            ExceptionHelper.RaiseWrongArgsNumber(null, 3, args?.Length ?? 0);
            return(default);
Beispiel #12
0
        static IExpr Execute(IfFunctionValue main, FunctionArgument args, EvalContext cal)
        {
            var children = args.Contents;

            if (cal.GetValue <bool>(cal.Evaluate(main.Condition)))
            {
                foreach (var v in children)
                {
                    cal.Evaluate(v);
                }
                return(BuiltinValues.Null);
            }
            else
            {
                return(new ElseFunctionValue(true, main));
            }
        }
Beispiel #13
0
        internal static List <double> GetAll(IExpr[] args, EvalContext context)
        {
            List <IExpr> ls = new List <IExpr>();

            foreach (var v in args)
            {
                switch (v)
                {
                case CollectionValue c:
                    ls.AddRange(c);
                    break;

                default:
                    ls.Add(v);
                    break;
                }
            }
            return(new List <double>(ls.Select(x => context.GetValue <double>(x))));
        }
Beispiel #14
0
        public static number Next(FunctionArgument _args, EvalContext cal)
        {
            var args = _args.Arguments;

            OperationHelper.AssertCertainValueThrowIf(null, args);
            var ov = cal.GetValue <number>(args);

            switch (ov.Length)
            {
            case 0:
                return(new number(rand.Next()));

            case 1:
                return(new number(rand.Next(ov[0])));

            case 2:
                return(new number(rand.Next(ov[0], ov[1])));
            }
            ExceptionHelper.RaiseWrongArgsNumber(null, 2, args?.Length ?? 0);
            return(default);
Beispiel #15
0
 public Gift(FunctionArgument _args, EvalContext cal)
 {
     OperationHelper.AssertArgsNumberThrowIf(this, 1, _args.Arguments);
     Name = cal.GetValue <string>(_args.Arguments[0]);
 }