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


C# StackContext.CreateNativePValue方法代码示例

本文整理汇总了C#中StackContext.CreateNativePValue方法的典型用法代码示例。如果您正苦于以下问题:C# StackContext.CreateNativePValue方法的具体用法?C# StackContext.CreateNativePValue怎么用?C# StackContext.CreateNativePValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StackContext的用法示例。


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

示例1: RunStatically

        public static PValue RunStatically(StackContext sctx, PValue[] args)
        {
            if(args.Length < 1)
                throw new PrexoniteException(Alias + "(...) requires at least one argument.");

            PValue rawVersion;
            
            if(args.Length == 1)
            {
                if(args[0].Type == PType.Object[typeof(MetaEntry)])
                {
                    var entry = (MetaEntry) args[0].Value;
                    ModuleName moduleName;
                    if (ModuleName.TryParse(entry, out moduleName))
                        return sctx.CreateNativePValue(sctx.Cache[moduleName]);
                    else
                        return PType.Null;
                }
                else
                {
                    var raw = args[0].CallToString(sctx);

                    ModuleName moduleName;
                    if (ModuleName.TryParse(raw, out moduleName))
                        return sctx.CreateNativePValue(sctx.Cache[moduleName]);
                    else
                        return PType.Null;
                }
            }
            else if((rawVersion = args[1]).Type.Equals(PType.Object[typeof(Version)]))
            {
                var raw = args[0].CallToString(sctx);

                return
                    sctx.CreateNativePValue(sctx.Cache[new ModuleName(raw,
                        (Version) rawVersion.Value)]);
            }
            else
            {
                var raw = args[0].CallToString(sctx);

                Version version;
                if (Version.TryParse(rawVersion.CallToString(sctx), out version))
                    return sctx.CreateNativePValue(sctx.Cache[new ModuleName(raw, version)]);
                else
                    return PType.Null;
            }
        }
开发者ID:SealedSun,项目名称:prx,代码行数:48,代码来源:CreateModuleName.cs

示例2: 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

示例3: 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

示例4: RunStatically

        public static PValue RunStatically(StackContext sctx, PValue[] args)
        {
            if (args.Length < 2)
                throw new PrexoniteException("then command requires two arguments.");

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

示例5: RunStatically

 // Bound statically by CIL compiler
 // ReSharper disable UnusedMember.Global
 public static PValue RunStatically(StackContext sctx, PValue[] args)
     // ReSharper restore UnusedMember.Global
 {
     var carrier = new ContextCarrier();
     var corctx = new CoroutineContext(sctx, CoroutineRunStatically(carrier, args));
     carrier.StackContext = corctx;
     return sctx.CreateNativePValue(new Coroutine(corctx));
 }
开发者ID:SealedSun,项目名称:prx,代码行数:10,代码来源:Reverse.cs

示例6: Test1

        /* function foo(a) [share c]
         * {
         *    var b;
         *    var d;
         *    return ->d;
         * }
        */

        public static void Test1(StackContext sctx, PValue[] args, PVariable[] sharedVariables,
            out PValue result)
        {
            var a = args[0];
            var b = PType.Null.CreatePValue();
            var c = sharedVariables[0];
            var d = new PVariable();
            d.Value = PType.Null;

            var argv = new[] {a, b};

            a = new PValue(true, PType.Bool);
            b = sctx.CreateNativePValue(sctx.ParentApplication.Functions["funcid"]);

            a.DynamicCall(sctx, null, PCall.Get, "memid");

            result = sctx.CreateNativePValue(d);
        }
开发者ID:SealedSun,项目名称:prx,代码行数:26,代码来源:CilTestCommand.cs

示例7: RunStatically

        // ReSharper disable MemberCanBePrivate.Global
        public static PValue RunStatically(StackContext sctx, PValue[] args)
            // ReSharper restore MemberCanBePrivate.Global
        {
            if (args.Length < 3)
                throw new PrexoniteException(Alias + " requires three arguments: " + Alias +
                    "(fMoveNext, fCurrent, fDispose);");

            return sctx.CreateNativePValue(new EnumeratorProxy(sctx, args[0], args[1], args[2]));
        }
开发者ID:SealedSun,项目名称:prx,代码行数:10,代码来源:CreateEnumerator.cs

示例8: Run

        public override PValue Run(StackContext sctx, PValue[] args)
        {
            if (args.Length < 1)
                return PType.Null;

            var closed = new PValue[args.Length - 1];
            Array.Copy(args, 1, closed, 0, args.Length - 1);
            return sctx.CreateNativePValue(new FunctionalPartialCall(args[0], closed));
        }
开发者ID:SealedSun,项目名称:prx,代码行数:9,代码来源:FunctionalPartialCallCommand.cs

示例9: RunStatically

        public static PValue RunStatically(StackContext sctx, PValue[] args)
        {
            if (args.Length == 0)
                return PType.Null;

            var arg = args[0];
            if (arg == null)
                return PType.Null;

            return sctx.CreateNativePValue(arg);
        }
开发者ID:SealedSun,项目名称:prx,代码行数:11,代码来源:Boxed.cs

示例10: Run

        /// <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 override PValue Run(StackContext sctx, PValue[] args)
        {
            if (sctx == null)
                throw new ArgumentNullException("sctx");
            if (args == null)
                throw new ArgumentNullException("args");

            var carrier = new ContextCarrier();
            var corctx = new CoroutineContext(sctx, CoroutineRun(carrier, args));
            carrier.StackContext = corctx;
            return sctx.CreateNativePValue(new Coroutine(corctx));
        }
开发者ID:SealedSun,项目名称:prx,代码行数:18,代码来源:CoroutineCommand.cs

示例11: TryDynamicCall

        internal bool TryDynamicCall(
            StackContext sctx,
            PValue subject,
            PValue[] args,
            PCall call,
            string id,
            out PValue result,
            out MemberInfo resolvedMember,
            bool suppressIObject)
        {
            result = null;
            resolvedMember = null;

            if (id == null)
                id = "";

            var iobj = subject.Value as IObject;
            if ((!suppressIObject) && iobj != null &&
                iobj.TryDynamicCall(sctx, args, call, id, out result))
                return true;

            //Special interop members
            switch (id.ToLowerInvariant())
            {
                case @"\implements":
                    foreach (var arg in args)
                    {
                        Type T;
                        if (arg.Type is ObjectPType &&
                            typeof (Type).IsAssignableFrom(((ObjectPType) arg.Type).ClrType))
                            T = (Type) arg.Value;
                        else
                            T = GetType(sctx, arg.CallToString(sctx));

                        if (!T.IsAssignableFrom(ClrType))
                        {
                            result = false;
                            return true;
                        }
                    }
                    result = true;
                    return true;
                case @"\boxed":
                    result = sctx.CreateNativePValue(subject);
                    return true;
            }

            var cond = new call_conditions(sctx, args, call, id);
            MemberTypes mtypes;
            MemberFilter filter;
            if (id.Length != 0)
            {
                filter = _member_filter;

                if (id.LastIndexOf('\\') == 0)
                    return false; //Default index accessors do not accept calling directives
                mtypes = MemberTypes.Event | MemberTypes.Field | MemberTypes.Method |
                    MemberTypes.Property;
            }
            else
            {
                filter = _default_member_filter;
                mtypes = MemberTypes.Property | MemberTypes.Method;
                cond.memberRestriction = new List<MemberInfo>(_clrType.GetDefaultMembers());
                cond.IgnoreId = true;
                if (subject.Value is Array)
                {
                    cond.memberRestriction.AddRange(
                        _clrType.FindMembers(
                            MemberTypes.Method,
                            BindingFlags.Public | BindingFlags.Instance,
                            Type.FilterName,
                            cond.Call == PCall.Get ? "GetValue" : "SetValue"));
                    cond.memberRestriction.AddRange(
                        _clrType.FindMembers(
                            MemberTypes.Method,
                            BindingFlags.Public | BindingFlags.Instance,
                            Type.FilterName,
                            cond.Call == PCall.Get ? "Get" : "Set"));
                }
            }

            //Get public member candidates, a stack is used so that newly discovered members 
            // can be examined with priority
            var candidates = new Stack<MemberInfo>(
                _clrType.FindMembers(
                    mtypes,
                    //Member types
                    BindingFlags.Instance | BindingFlags.Public,
                    //Search domain
                    filter,
                    cond)); //Filter

            if (candidates.Count == 1)
                resolvedMember = candidates.Peek();

            var ret = _try_execute(candidates, cond, subject, out result);
            if (!ret) //Call did not succeed -> member invalid
                resolvedMember = null;

//.........这里部分代码省略.........
开发者ID:SealedSun,项目名称:prx,代码行数:101,代码来源:ObjectPType.cs

示例12: Run

            public override PValue Run(StackContext sctx, PValue[] args)
            {
                if (args.Length < CallingConventionArgumentsCount)
                    throw new PrexoniteException(
                        "Id of macro implementation, effect flag, call type and/or context missing.");

                var entityRef = _getMacroRef(sctx, args[0]);

                //Parse arguments
                var context = _getContext(args[1]);
                var call = _getCallType(args[2]);
                var justEffect = _getEffectFlag(args[3]);

                // Prepare macro
                var target = _loader.FunctionTargets[context.Function];
                var argList = Call.FlattenArguments(sctx, args, CallingConventionArgumentsCount);
                _detectRuntimeValues(argList);

                var inv = new AstExpand(context.Invocation.Position, entityRef, call);
                inv.Arguments.AddRange(argList.Select(p => (AstExpr) p.Value));

                //Execute the macro
                MacroSession macroSession = null;
                try
                {
                    macroSession = target.AcquireMacroSession();

                    return sctx.CreateNativePValue(
                        macroSession.ExpandMacro(inv, justEffect));
                }
                finally
                {
                    if (macroSession != null)
                        target.ReleaseMacroSession(macroSession);
                }
            }
开发者ID:SealedSun,项目名称:prx,代码行数:36,代码来源:CallMacro.cs

示例13: Invoke

        protected override PValue Invoke(StackContext sctx, PValue[] nonArguments,
            PValue[] arguments)
        {
            var end = _wrappingDirectives.Offset + _wrappingDirectives.Count;
            var effectiveArguments = new PValue[_getEffectiveArgc(arguments.Length)];
            var effIdx = 0;
            var argIdx = 0;
            for (var i = _wrappingDirectives.Offset; i < end; i++)
            {
                var directive = _wrappingDirectives.Array[i];

                System.Diagnostics.Debug.Assert(directive != 0);

                if (directive > 0)
                {
                    Array.Copy(arguments, argIdx, effectiveArguments, effIdx, directive);
                    argIdx += directive;
                    effIdx += directive;
                }
                else
                {
                    directive = -directive;

                    var list = new List<PValue>(directive);
                    for (var j = 0; j < directive; j++)
                        list.Add(arguments[argIdx++]);

                    effectiveArguments[effIdx++] = sctx.CreateNativePValue(list);
                }
            }

            System.Diagnostics.Debug.Assert(effectiveArguments.Length - effIdx ==
                arguments.Length - argIdx);

            Array.Copy(arguments, argIdx, effectiveArguments, effIdx,
                effectiveArguments.Length - effIdx);

            return nonArguments[0].IndirectCall(sctx, effectiveArguments);
        }
开发者ID:SealedSun,项目名称:prx,代码行数:39,代码来源:PartialCallStar.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");

            PValue head;
            var nextArg = ((IEnumerable<PValue>) args).GetEnumerator();
            IEnumerator<PValue> nextX;
            try
            {
                if (!nextArg.MoveNext())
                    throw new PrexoniteException("headtail requires at least one argument.");
                var arg = nextArg.Current;
                var xs = Map._ToEnumerable(sctx, arg);
                nextX = xs.GetEnumerator();
                try
                {
                    if (!nextX.MoveNext())
                        return PType.Null;
                    head = nextX.Current;
                }
                catch (Exception)
                {
                    nextX.Dispose();
                    throw;
                }
            }
            catch (Exception)
            {
                nextArg.Dispose();
                throw;
            }

            return
                (PValue)
                    new List<PValue>
                        {
                            head,
                            sctx.CreateNativePValue(
                                new Coroutine(new CoroutineContext(sctx, _tail(sctx, nextX, nextArg))))
                        };
        }
开发者ID:SealedSun,项目名称:prx,代码行数:44,代码来源:HeadTail.cs

示例15: PrepareMacroImplementation

        /// <summary>
        ///     Provides macro environment to its implementing function. The resulting closure 
        ///     implements the expansion of the macro.
        /// </summary>
        /// <param name = "sctx">The stack context to use for wrapping the context.</param>
        /// <param name = "func">The implementation of the macro.</param>
        /// <param name = "context">The macro context for this expansion.</param>
        /// <returns>A closure that implements the expansion of this macro.</returns>
        public static Closure PrepareMacroImplementation(StackContext sctx, PFunction func,
            MacroContext context)
        {
            var contextVar =
                CompilerTarget.CreateReadonlyVariable(sctx.CreateNativePValue(context));

            var env = new SymbolTable<PVariable>(1) {{MacroAliases.ContextAlias, contextVar}};

            var sharedVariables =
                func.Meta[PFunction.SharedNamesKey].List.Select(entry => env[entry.Text]).
                    ToArray();
            return new Closure(func, sharedVariables);
        }
开发者ID:SealedSun,项目名称:prx,代码行数:21,代码来源:MacroSession.cs


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