Esempio n. 1
0
        /// <summary>
        ///     Executes the command.
        /// </summary>
        /// <param name = "sctx">The stack context in which to execut the command.</param>
        /// <param name = "args">The arguments to be passed to the command.</param>
        /// <returns>The value returned by the command. Must not be null. (But possibly {null~Null})</returns>
        public static PValue RunStatically(StackContext sctx, PValue[] args)
        {
            if (sctx == null)
                throw new ArgumentNullException("sctx");
            if (args == null)
                throw new ArgumentNullException("args");

            var lst = new List<PValue>(args.Length);
            lst.AddRange(args);
            return (PValue) lst;
        }
Esempio n. 2
0
        private static IEnumerable<PValue> CoroutineRunStatically(ContextCarrier sctxCarrier,
            IEnumerable<PValue> args)
        {
            if (args == null)
                throw new ArgumentNullException("args");
            if (sctxCarrier == null)
                throw new ArgumentNullException("sctxCarrier");

            var sctx = sctxCarrier.StackContext;

            var lst = new List<PValue>();

            foreach (var arg in args)
                lst.AddRange(Map._ToEnumerable(sctx, arg));

            for (var i = lst.Count - 1; i >= 0; i--)
                yield return lst[i];
        }
Esempio n. 3
0
File: All.cs Progetto: SealedSun/prx
        /// <summary>
        ///     Executes the command.
        /// </summary>
        /// <param name = "sctx">The stack context in which to execut the command.</param>
        /// <param name = "args">The arguments to be passed to the command.</param>
        /// <returns>The value returned by the command. Must not be null. (But possibly {null~Null})</returns>
        public static PValue RunStatically(StackContext sctx, PValue[] args)
        {
            if (sctx == null)
                throw new ArgumentNullException("sctx");
            if (args == null)
                throw new ArgumentNullException("args");
            var lst = new List<PValue>();
            foreach (var arg in args)
            {
                var set = Map._ToEnumerable(sctx, arg);
                if (set == null)
                    continue;
                else
                    lst.AddRange(set);
            }

            return (PValue) lst;
        }
Esempio n. 4
0
        public static PValue RunStatically(StackContext sctx, PValue[] args)
        {
            bool performSubCall;
            if (args.Length > 0 && args[0].Type.ToBuiltIn() == PType.BuiltIn.Bool)
                performSubCall = (bool) args[0].Value;
            else
                performSubCall = false;

            var rawCases = new List<PValue>();
            foreach (var arg in args.Skip(performSubCall ? 1 : 0))
            {
                var set = Map._ToEnumerable(sctx, arg);
                if (set == null)
                    continue;
                else
                    rawCases.AddRange(set);
            }

            var appCases =
                rawCases.Select(c => _isApplicable(sctx, c)).Where(x => x != null).Select(_extract).
                    ToArray();

            return RunStatically(sctx, appCases, performSubCall);
        }
Esempio n. 5
0
 /// <summary>
 ///     Takes an argument list and injects elements of top-level lists into that argument list.
 /// </summary>
 /// <param name = "sctx">The stack context in which to convert enumerables.</param>
 /// <param name = "args">The raw list of arguments to process.</param>
 /// <param name = "offset">The offset at which to start processing.</param>
 /// <returns>A copy of the argument list with top-level lists expanded.</returns>
 public static List<PValue> FlattenArguments(StackContext sctx, PValue[] args, int offset)
 {
     if (args == null)
         args = new PValue[] {};
     var iargs = new List<PValue>();
     for (var i = offset; i < args.Length; i++)
     {
         var arg = args[i];
         var folded = Map._ToEnumerable(sctx, arg);
         if (folded == null)
             iargs.Add(arg);
         else
             iargs.AddRange(folded);
     }
     return iargs;
 }
Esempio n. 6
0
        public static PValue RunStatically(StackContext sctx, PValue[] args)
        {
            if (sctx == null)
                throw new ArgumentNullException("sctx");
            if (args == null)
                throw new ArgumentNullException("args");

            //Get f
            IIndirectCall f;
            if (args.Length < 1)
                throw new PrexoniteException("The foldl command requires a function argument.");
            else
                f = args[0];

            //Get left
            PValue left;
            if (args.Length < 2)
                left = null;
            else
                left = args[1];

            //Get the source
            IEnumerable<PValue> source;
            if (args.Length == 3)
            {
                var psource = args[2];
                source = Map._ToEnumerable(sctx, psource) ?? new[] {psource};
            }
            else
            {
                var lstsource = new List<PValue>();
                for (var i = 1; i < args.Length; i++)
                {
                    var multiple = Map._ToEnumerable(sctx, args[i]);
                    if (multiple != null)
                        lstsource.AddRange(multiple);
                    else
                        lstsource.Add(args[i]);
                }
                source = lstsource;
            }

            return Run(sctx, f, left, source);
        }
Esempio n. 7
0
File: Map.cs Progetto: SealedSun/prx
        protected static IEnumerable<PValue> CoroutineRunStatically(ContextCarrier sctxCarrier,
            PValue[] args)
        {
            if (sctxCarrier == null)
                throw new ArgumentNullException("sctxCarrier");
            if (args == null)
                throw new ArgumentNullException("args");

            var sctx = sctxCarrier.StackContext;

            //Get f
            IIndirectCall f;
            if (args.Length < 1)
                f = null;
            else
                f = args[0];

            //Get the source
            IEnumerable<PValue> source;
            if (args.Length == 2)
            {
                var psource = args[1];
                source = _ToEnumerable(sctx, psource) ?? new[] {psource};
            }
            else
            {
                var lstsource = new List<PValue>();
                for (var i = 1; i < args.Length; i++)
                {
                    var multiple = _ToEnumerable(sctx, args[i]);
                    if (multiple != null)
                        lstsource.AddRange(multiple);
                    else
                        lstsource.Add(args[i]);
                }
                source = lstsource;
            }

            //Note: need to forward element because this method must remain lazy.
            foreach (var value in CoroutineRun(sctxCarrier, f, source))
            {
                yield return value;
            }
        }
Esempio n. 8
0
        /// <summary>
        ///     Implementation of (obj, id, arg1, arg2, arg3, ..., argn) => obj.id(arg1, arg2, arg3, ..., argn);
        /// </summary>
        /// <param name = "sctx">The stack context in which to call the member of <paramref name = "obj" />.</param>
        /// <param name = "obj">The obj to call.</param>
        /// <param name = "isSet">Indicates whether to perform a Set-call.</param>
        /// <param name = "id">The id of the member to call.</param>
        /// <param name = "args">The array of arguments to pass to the member call.<br />
        ///     Lists and coroutines are expanded.</param>
        /// <returns>The result returned by the member call.</returns>
        /// <exception cref = "ArgumentNullException"><paramref name = "sctx" /> is null.</exception>
        public PValue Run(StackContext sctx, PValue obj, bool isSet, string id, params PValue[] args)
        {
            if (obj == null)
                return PType.Null.CreatePValue();
            if (sctx == null)
                throw new ArgumentNullException("sctx");
            if (args == null)
                args = new PValue[] {};

            var iargs = new List<PValue>();
            for (var i = 0; i < args.Length; i++)
            {
                var arg = args[i];
                var folded = Map._ToEnumerable(sctx, arg);
                if (folded == null)
                    iargs.Add(arg);
                else
                    iargs.AddRange(folded);
            }

            return obj.DynamicCall(sctx, iargs.ToArray(), isSet ? PCall.Set : PCall.Get, id);
        }