本文整理汇总了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.");
}
}
示例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;
}