public void AddCall(StackFrame f) { MemoryUsed += MemoryCalc.CalcSizeOf(f.Locals); MemoryUsed += StackFrame.MemSize; if (MemoryUsed > MAX_MEMORY) { throw new VMException("Out of memory"); } }
public void CompleteCall(StackFrame f) { MemoryUsed -= MemoryCalc.CalcSizeOf(f.Locals); MemoryUsed -= StackFrame.MemSize; }
private static void TestNextFrame(RuntimeState state, RuntimeState deserRunState, out StackFrame origTopFrame, out StackFrame deserFrame) { origTopFrame = state.Calls.Pop(); deserFrame = deserRunState.Calls.Pop(); Assert.AreEqual(origTopFrame.Locals, deserFrame.Locals); Assert.AreEqual(origTopFrame.ReturnAddress, deserFrame.ReturnAddress); Assert.AreEqual(origTopFrame.FunctionInfo.Address, deserFrame.FunctionInfo.Address); Assert.AreEqual(origTopFrame.FunctionInfo.Name, deserFrame.FunctionInfo.Name); Assert.AreEqual(origTopFrame.FunctionInfo.NumberOfArguments, deserFrame.FunctionInfo.NumberOfArguments); Assert.AreEqual(origTopFrame.FunctionInfo.NumberOfLocals, deserFrame.FunctionInfo.NumberOfLocals); Assert.AreEqual(state.MemInfo.MemoryUsed, deserRunState.MemInfo.MemoryUsed); if (state.EventQueue.Count > 0) { PostedEvent origEvent = state.EventQueue.Pop(); PostedEvent deserEvent = deserRunState.EventQueue.Pop(); Assert.AreEqual(origEvent.Args, deserEvent.Args); Assert.AreEqual(origEvent.EventType, deserEvent.EventType); Assert.AreEqual(origEvent.TransitionToState, deserEvent.TransitionToState); } Assert.AreEqual(state.RunState, deserRunState.RunState); Assert.AreEqual(state.GeneralEnable, deserRunState.GeneralEnable); Assert.AreEqual(state.TimerInterval, deserRunState.TimerInterval); }
private void _Call(int funcIndex) { FunctionInfo fi = (FunctionInfo)_script.ConstPool[funcIndex]; StackFrame f = new StackFrame(fi, _state.IP); // push new stack frame for parameters and locals if (f == null) throw new VMException("Attempt to push null call frame."); _state.Calls.Push(f); // move args from operand stack to top frame on call stack for (int a = fi.NumberOfArguments - 1; a >= 0; a--) { f.Locals[a] = _state.Operands.Pop(); } //tell the memory tracker about this call _state.MemInfo.AddCall(f); _state.TopFrame = f; _state.IP = fi.Address; // branch to function }