public ReturnPoint(InstructionPointer ip, int a) { instructionPointer = ip; popArgs = a; }
public void DoCALL(UInt32 instruction) { int numArgs = (int)((instruction & OpCodes.OP1_MASK) >> OpCodes.OP1_SHIFT); int numPop = (int)((instruction & OpCodes.OP2_MASK) >> OpCodes.OP2_SHIFT); VarArgs args = new VarArgs(); for (int i = 0; i < numArgs; i++) { if (i == 0) { args.PushLastArg(CurrentThread.PopStack()); } else { args.PushArg(CurrentThread.PopStack()); } } Object o = CurrentThread.PopStack(); if (o is Closure) { Closure closure = (Closure)o; Function f = closure.Func; InstructionPointer newIP = null; newIP = new InstructionPointer(f, closure.ClosedVars, 0); ReturnPoint retPoint = new ReturnPoint(CurrentIP, numPop); CurrentThread.PushStack(retPoint); CurrentThread.PushStack(CurrentThread.BasePosition); CurrentThread.BasePosition = CurrentThread.StackPosition - 1; CurrentThread.PushStack(args); CurrentIP = newIP; } else if (o is NativeFuncDelegate) { NativeFuncDelegate nativeFunc = (NativeFuncDelegate)o; VarArgs returnArgs = nativeFunc(args, Engine); CurrentThread.PushStack(returnArgs); CurrentIP.InstructionIndex++; } else if (o is NativeCoreFuncDelegate) { NativeCoreFuncDelegate nativeFunc = (NativeCoreFuncDelegate)o; nativeFunc(args, Engine); } else { throw new VMException(); } }