当前位置: 首页>>代码示例>>C#>>正文


C# PValue类代码示例

本文整理汇总了C#中PValue的典型用法代码示例。如果您正苦于以下问题:C# PValue类的具体用法?C# PValue怎么用?C# PValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PValue类属于命名空间,在下文中一共展示了PValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RunStatically

        public static PValue RunStatically(StackContext sctx, PValue[] args)
        {
            if (args.Length == 0)
            {
                return sctx.CreateNativePValue(NoSourcePosition.Instance);
            }

            string file = args[0].CallToString(sctx);
            int? line, column;

            PValue box;
            if (args.Length >= 2 && args[1].TryConvertTo(sctx, IntPType.Instance,true,out box))
            {
                line = (int) box.Value;
            }
            else
            {
                line = null;
            }

            if (args.Length >= 3 && args[2].TryConvertTo(sctx, IntPType.Instance, true, out box))
            {
                column = (int) box.Value;
            }
            else
            {
                column = null;
            }

            return sctx.CreateNativePValue(new SourcePosition(file, line ?? -1, column ?? -1));
        }
开发者ID:SealedSun,项目名称:prx,代码行数:31,代码来源:CreateSourcePosition.cs

示例2: CoroutineRunStatically

        public static IEnumerable<PValue> CoroutineRunStatically(ContextCarrier getSctx,
            PValue[] args)
        {
            if (args == null)
                throw new ArgumentNullException("args");
            if (getSctx == null)
                throw new ArgumentNullException("getSctx");

            if (args.Length < 1)
                throw new PrexoniteException("toseq requires one argument.");

            var xsT = args[0];
            PValue xs;

            var sctx = getSctx.StackContext;

            while (!(xs = ForceCommand.Force(sctx, xsT)).IsNull)
            {
                //Accept key value pairs directly
                var kvp = xs.Value as PValueKeyValuePair;
                if (kvp != null)
                {
                    yield return kvp.Key;
                    xsT = kvp.Value;
                }
                    //Late bound
                else
                {
                    var k = xs.DynamicCall(sctx, Runtime.EmptyPValueArray, PCall.Get, "Key");
                    yield return k;
                    xsT = xs.DynamicCall(sctx, Runtime.EmptyPValueArray, PCall.Get, "Value");
                }
            }
        }
开发者ID:SealedSun,项目名称:prx,代码行数:34,代码来源:ToSeqCommand.cs

示例3: IndirectCall

        public override bool IndirectCall(
            StackContext sctx, PValue subject, PValue[] args, out PValue result)
        {
            if (sctx == null)
                throw new ArgumentNullException("sctx");
            if (subject == null)
                throw new ArgumentNullException("subject");
            if (args == null)
                args = new PValue[] {};

            result = null;

            var argc = args.Length;

            var pvht = (PValueHashtable) subject.Value;

            if (argc == 0)
            {
                result =
                    sctx.CreateNativePValue(new PValueEnumeratorWrapper(pvht.GetPValueEnumerator()));
            }
            else if (argc == 1)
            {
                if (!pvht.TryGetValue(args[0], out result))
                    result = false;
            }
            else
            {
                pvht.AddOverride(args[0], args[1]);
            }

            return result != null;
        }
开发者ID:SealedSun,项目名称:prx,代码行数:33,代码来源:HashPType.cs

示例4: CoroutineRunStatically

        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;

            foreach (var arg in args)
            {
                if (arg == null)
                    throw new ArgumentException("No element in seqconcat(args...) must be null.", "args");
                var xss = Map._ToEnumerable(sctx, arg);
                if (xss == null)
                    continue;
                foreach (var xsRaw in xss)
                {
                    var xs = Map._ToEnumerable(sctx, xsRaw);
                    if(xs == null)
                        throw new ArgumentException("The elements in the sequences passed to seqconcat(..) must be sequences themselves.");
                    foreach (var x in xs)
                        yield return x;
                }
            }
        }
开发者ID:SealedSun,项目名称:prx,代码行数:26,代码来源:SeqConcat.cs

示例5: CoroutineRun

        protected override IEnumerable<PValue> CoroutineRun(ContextCarrier sctxCarrier,
            PValue[] args)
        {
            if (args == null)
                throw new ArgumentNullException("args");
            if (sctxCarrier == null)
                throw new ArgumentNullException("sctxCarrier");

            var t = new Dictionary<PValue, object>();

            var sctx = sctxCarrier.StackContext;

            foreach (var arg in args)
            {
                var xs = Map._ToEnumerable(sctx, arg);
                if (xs == null)
                    continue;
                foreach (var x in xs)
                    if (!t.ContainsKey(x))
                    {
                        t.Add(x, null);
                        yield return x;
                    }
            }
        }
开发者ID:SealedSun,项目名称:prx,代码行数:25,代码来源:Distinct.cs

示例6: TryDefer

        public bool TryDefer(StackContext sctx, PValue[] args,
            out StackContext partialApplicationContext, out PValue result)
        {
            var effectiveArgs = _getEffectiveArgs(args);

            partialApplicationContext = null;
            result = null;

            //The following code exists in a very similar form in PartialCall.cs, FunctionalPartialCall.cs
            if ((_subject.Type is ObjectPType))
            {
                var raw = _subject.Value;
                var stackAware = raw as IStackAware;
                if (stackAware != null)
                {
                    partialApplicationContext = stackAware.CreateStackContext(sctx, effectiveArgs);
                    return true;
                }

                var partialApplication = raw as IMaybeStackAware;
                if (partialApplication != null)
                    return partialApplication.TryDefer(sctx, effectiveArgs,
                        out partialApplicationContext,
                        out result);
            }

            result = _subject.IndirectCall(sctx, effectiveArgs);
            return false;
        }
开发者ID:SealedSun,项目名称:prx,代码行数:29,代码来源:FlippedFunctionalPartialCall.cs

示例7: RunStatically

        public static PValue RunStatically(StackContext sctx, PValue[] args)
        {
            if (args == null)
                throw new ArgumentNullException("args");
            if (sctx == null)
                throw new ArgumentNullException("sctx");

            //let sum xs acc = Seq.foldl (fun a b -> a + b) acc xs

            PValue acc;
            IEnumerable<PValue> xsArgs;

            if (args.Length == 0)
                return PType.Null;

            if (args.Length == 1)
            {
                acc = PType.Null;
                xsArgs = args;
            }
            else
            {
                acc = args[args.Length - 1];
                xsArgs = args.Take(args.Length - 1);
            }

            var xss = xsArgs.Select(e => Map._ToEnumerable(sctx, e)).Where(e => e != null);

            foreach (var xs in xss)
                foreach (var x in xs)
                    acc = acc.Addition(sctx, x);

            return acc;
        }
开发者ID:SealedSun,项目名称:prx,代码行数:34,代码来源:Sum.cs

示例8: DoTryDefer

        protected override bool DoTryDefer(StackContext sctx, PValue[] nonArguments,
            PValue[] arguments, out StackContext partialApplicationContext, out PValue result)
        {
            partialApplicationContext = null;
            result = null;

            //The following code exists in a very similar form in FunctionalPartialCall.cs, FlippedFunctionalPartialCall.cs
            if ((nonArguments[0].Type is ObjectPType))
            {
                var raw = nonArguments[0].Value;
                var stackAware = raw as IStackAware;
                if (stackAware != null)
                {
                    partialApplicationContext = stackAware.CreateStackContext(sctx, arguments);
                    return true;
                }

                var partialApplication = raw as IMaybeStackAware;
                if (partialApplication != null)
                    return partialApplication.TryDefer(sctx, arguments,
                        out partialApplicationContext,
                        out result);
            }

            result = Invoke(sctx, nonArguments, arguments);
            return false;
        }
开发者ID:SealedSun,项目名称:prx,代码行数:27,代码来源:PartialCall.cs

示例9: CoroutineRunStatically

        protected static IEnumerable<PValue> CoroutineRunStatically(ContextCarrier sctxCarrier,
            PValue[] args)
        {
            if (sctxCarrier == null)
                throw new ArgumentNullException("sctxCarrier");
            if (args == null)
                throw new ArgumentNullException("args");
            if (args.Length < 2)
                throw new PrexoniteException("TakeWhile requires at least two arguments.");

            var sctx = sctxCarrier.StackContext;

            var f = args[0];

            var i = 0;
            for (var k = 1; k < args.Length; k++)
            {
                var arg = args[k];
                var set = Map._ToEnumerable(sctx, arg);
                if (set == null)
                    continue;
                foreach (var value in set)
                    if (
                        (bool)
                            f.IndirectCall(sctx, new[] {value, i++}).ConvertTo(sctx, PType.Bool,
                                true).Value)
                        yield return value;
            }
        }
开发者ID:SealedSun,项目名称:prx,代码行数:29,代码来源:TakeWhile.cs

示例10: RunStatically

        public static PValue RunStatically(StackContext sctx, PValue[] args)
        {
            if (args == null)
                throw new ArgumentNullException("args");
            if (sctx == null)
                throw new ArgumentNullException("sctx");

            var xss = new List<IEnumerable<PValue>>();
            foreach (var arg in args)
            {
                var xs = Map._ToEnumerable(sctx, arg);
                if (xs != null)
                    xss.Add(xs);
            }

            var n = xss.Count;
            if (n < 2)
                throw new PrexoniteException("Except requires at least two sources.");

            var t = new Dictionary<PValue, bool>();
            //All elements of the last source are considered candidates
            foreach (var x in xss[n - 1])
                if (!t.ContainsKey(x))
                    t.Add(x, true);

            for (var i = 0; i < n - 1; i++)
                foreach (var x in xss[i])
                    if (t.ContainsKey(x))
                        t.Remove(x);

            return sctx.CreateNativePValue(t.Keys);
        }
开发者ID:SealedSun,项目名称:prx,代码行数:32,代码来源:Except.cs

示例11: _EnforceThunk

        // ReSharper restore MemberCanBePrivate.Global

        internal static PValue _EnforceThunk(PValue value)
        {
            if (value.Type.Equals(PType.Object[typeof (Thunk)]))
                return value;
            else
                return PType.Object.CreatePValue(Thunk.NewValue(value));
        }
开发者ID:SealedSun,项目名称:prx,代码行数:9,代码来源:ThunkCommand.cs

示例12: RunStatically

        /// <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)
        {
            var text = Concat.ConcatenateString(sctx, args);
            StaticPrint.Writer.WriteLine(text);

            return text;
        }
开发者ID:SealedSun,项目名称:prx,代码行数:13,代码来源:StaticPrintLine.cs

示例13: CoroutineRunStatically

        protected static IEnumerable<PValue> CoroutineRunStatically(ContextCarrier ctxCarrier,
            PValue[] args)
        {
            if (ctxCarrier == null)
                throw new ArgumentNullException("ctxCarrier");
            if (args == null)
                throw new ArgumentNullException("args");

            if (args.Length < 1)
                throw new PrexoniteException("Limit requires at least one argument.");

            var i = 0;
            var sctx = ctxCarrier.StackContext;
            var count = (int) args[0].ConvertTo(sctx, PType.Int, true).Value;

            for (var j = 1; j < args.Length; j++)
            {
                var arg = args[j];
                var set = Map._ToEnumerable(sctx, arg);
                if (set == null)
                    throw new PrexoniteException(arg + " is neither a list nor a coroutine.");
                using (var setEnumerator = set.GetEnumerator())
                {
                    while (i++ < count && setEnumerator.MoveNext())
                    {
                        yield return setEnumerator.Current;
                    }
                    if (i >= count)
                        yield break;
                }
            }
        }
开发者ID:SealedSun,项目名称:prx,代码行数:32,代码来源:Limit.cs

示例14: RunStatically

        public static PValue RunStatically(StackContext sctx, PValue[] args)
        {
            if (sctx == null)
                throw new ArgumentNullException("sctx");
            if (args == null)
                throw new ArgumentNullException("args");

            if (args.Length < 1)
                throw new PrexoniteException("Each requires at least two arguments");
            var f = args[0];

            var eargs = new PValue[1];
            for (var i = 1; i < args.Length; i++)
            {
                var arg = args[i];
                var set = Map._ToEnumerable(sctx, arg);
                if (set == null)
                    continue;
                foreach (var value in set)
                {
                    eargs[0] = value;
                    f.IndirectCall(sctx, eargs);
                }
            }

            return PType.Null;
        }
开发者ID:SealedSun,项目名称:prx,代码行数:27,代码来源:Each.cs

示例15: Run

		public override PValue Run(StackContext sctx, PValue[] args)
		{
			if(args.Length < 2)
				throw new PrexoniteException("The Subtraction operator requires two arguments.");

			return args[0].Subtraction(sctx,args[1]);			
		}
开发者ID:SealedSun,项目名称:prx,代码行数:7,代码来源:Operators.cs


注:本文中的PValue类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。