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


C# ICpu.PeekRaw方法代码示例

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


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

示例1: Execute

        public override void Execute(ICpu cpu)
        {
            bool worked;
            object shouldBeArgMarker = cpu.PeekRaw(0,out worked);

            if ( !worked || (shouldBeArgMarker == null) || (shouldBeArgMarker.GetType() != OpcodeCall.ArgMarkerType) )
            {
                throw new KOSArgumentMismatchException("Called with too many arguments.");
            }
        }
开发者ID:CalebJ2,项目名称:KOS,代码行数:10,代码来源:Opcode.cs

示例2: Execute

        public override void Execute(ICpu cpu)
        {
            // Return value should be atop the stack - we have to pop it so that
            // we can reach the arg start marker under it:
            object returnVal = cpu.PopValue();

            // The next thing on the stack under the return value should be the marker that indicated where
            // the parameters started.  It should be thrown away now.  If the next thing is NOT the marker
            // of where the parameters started, that is proof the stack is misaligned, probably because the
            // number of args passed didn't match the number of DECLARE PARAMETER statements in the function:
            string shouldBeArgMarker = cpu.PopStack() as string;

            if ( (shouldBeArgMarker == null) || (!(shouldBeArgMarker.Equals(OpcodeCall.ARG_MARKER_STRING))) )
            {
                throw new KOSArgumentMismatchException(
                    string.Format("(detected when returning from function and the stack still had {0} on it)",
                    (shouldBeArgMarker ?? "a non-string value"))
                );
            }
            // If the proper argument marker was found, then it's all okay, so put the return value
            // back, where it belongs, now that the arg start marker was popped off:
            cpu.PushStack(returnVal);

            // Now, after the eval was done, NOW finally pop the scope, after we don't need local vars anymore:
            if( Depth > 0 )
                OpcodePopScope.DoPopScope(cpu, Depth);

            // The only thing on the "above stack" now that is allowed to get in the way of
            // finding the context record that tells us where to jump back to, are the potential
            // closure scope frames that might have been pushed if this subroutine was
            // called via a delegate reference.  Consume any of those that are in
            // the way, then expect the context record.  Any other pattern encountered
            // is proof the stack alignment got screwed up:
            bool okay;
            VariableScope peeked = cpu.PeekRaw(-1, out okay) as VariableScope;
            while (okay && peeked != null && peeked.IsClosure)
            {
                cpu.PopAboveStack(1);
                peeked = cpu.PeekRaw(-1, out okay) as VariableScope;
            }
            object shouldBeContextRecord = cpu.PopAboveStack(1);
            if ( !(shouldBeContextRecord is SubroutineContext) )
            {
                // This should never happen with any user code:
                throw new Exception( "kOS internal error: Stack misalignment detected when returning from routine.");
            }

            var contextRecord = shouldBeContextRecord as SubroutineContext;

            int destinationPointer = contextRecord.CameFromInstPtr;
            int currentPointer = cpu.InstructionPointer;
            DeltaInstructionPointer = destinationPointer - currentPointer;
        }
开发者ID:space-is-hard,项目名称:KOS,代码行数:53,代码来源:Opcode.cs


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