public StackValue Evaluate(List <StackValue> args, StackFrame stackFrame) { // // Build the stackframe int classScopeCaller = (int)stackFrame.GetAt(DSASM.StackFrame.AbsoluteIndex.kClass).opdata; int returnAddr = (int)stackFrame.GetAt(DSASM.StackFrame.AbsoluteIndex.kReturnAddress).opdata; int blockDecl = (int)mProcNode.runtimeIndex; int blockCaller = (int)stackFrame.GetAt(DSASM.StackFrame.AbsoluteIndex.kFunctionCallerBlock).opdata; int framePointer = mRunTime.runtime.Core.Rmem.FramePointer; StackValue thisPtr = StackUtils.BuildPointer(-1); // Comment Jun: the caller type is the current type in the stackframe StackFrameType callerType = (StackFrameType)stackFrame.GetAt(StackFrame.AbsoluteIndex.kStackFrameType).opdata; StackFrameType type = StackFrameType.kTypeFunction; int depth = 0; List <StackValue> registers = new List <StackValue>(); // Comment Jun: Calling convention data is stored on the TX register StackValue svCallconvention = StackUtils.BuildNode(AddressType.CallingConvention, (long)ProtoCore.DSASM.CallingConvention.BounceType.kImplicit); mRunTime.runtime.TX = svCallconvention; StackValue svBlockDecl = StackUtils.BuildNode(AddressType.BlockIndex, blockDecl); mRunTime.runtime.SX = svBlockDecl; mRunTime.runtime.SaveRegisters(registers); ProtoCore.DSASM.StackFrame newStackFrame = new StackFrame(thisPtr, classScopeCaller, 1, returnAddr, blockDecl, blockCaller, callerType, type, depth, framePointer, registers); List <List <int> > replicationGuides = new List <List <int> >(); if (mRunTime.runtime.Core.Options.IDEDebugMode && mRunTime.runtime.Core.ExecMode != ProtoCore.DSASM.InterpreterMode.kExpressionInterpreter) { mRunTime.runtime.Core.DebugProps.SetUpCallrForDebug(mRunTime.runtime.Core, mRunTime.runtime, mProcNode, returnAddr - 1, false, mCallSite, args, replicationGuides, newStackFrame); } StackValue rx = mCallSite.JILDispatchViaNewInterpreter(new Runtime.Context(), args, replicationGuides, newStackFrame, mRunTime.runtime.Core); if (mRunTime.runtime.Core.Options.IDEDebugMode && mRunTime.runtime.Core.ExecMode != ProtoCore.DSASM.InterpreterMode.kExpressionInterpreter) { mRunTime.runtime.Core.DebugProps.RestoreCallrForNoBreak(mRunTime.runtime.Core, mProcNode); } return(rx); }
public StackValue Evaluate(List <StackValue> args, StackFrame stackFrame) { // Build the stackframe var runtimeCore = interpreter.runtime.RuntimeCore; int classScopeCaller = stackFrame.ClassScope; int returnAddr = stackFrame.ReturnPC; int blockDecl = procNode.RuntimeIndex; int blockCaller = stackFrame.FunctionCallerBlock; int framePointer = runtimeCore.RuntimeMemory.FramePointer; StackValue thisPtr = StackValue.BuildPointer(Constants.kInvalidIndex); // Functoion has variable input parameter. This case only happen // for FFI functions whose last parameter's type is (params T[]). // In this case, we need to convert argument list from // // {a1, a2, ..., am, v1, v2, ..., vn} // // to // // {a1, a2, ..., am, {v1, v2, ..., vn}} if (procNode.IsVarArg) { int paramCount = procNode.ArgumentInfos.Count; Validity.Assert(paramCount >= 1); int varParamCount = args.Count - (paramCount - 1); var varParams = args.GetRange(paramCount - 1, varParamCount).ToArray(); args.RemoveRange(paramCount - 1, varParamCount); try { var packedParams = interpreter.runtime.rmem.Heap.AllocateArray(varParams); args.Add(packedParams); } catch (RunOutOfMemoryException) { interpreter.runtime.RuntimeCore.RuntimeStatus.LogWarning(WarningID.RunOutOfMemory, Resources.RunOutOfMemory); return(StackValue.Null); } } bool isCallingMemberFunciton = procNode.ClassID != Constants.kInvalidIndex && !procNode.IsConstructor && !procNode.IsStatic; bool isValidThisPointer = true; if (isCallingMemberFunciton) { Validity.Assert(args.Count >= 1); thisPtr = args[0]; if (thisPtr.IsArray) { isValidThisPointer = ArrayUtils.GetFirstNonArrayStackValue(thisPtr, ref thisPtr, runtimeCore); } else { args.RemoveAt(0); } } if (!isValidThisPointer || (!thisPtr.IsPointer && !thisPtr.IsArray)) { runtimeCore.RuntimeStatus.LogWarning(WarningID.DereferencingNonPointer, Resources.kDeferencingNonPointer); return(StackValue.Null); } var callerType = stackFrame.StackFrameType; interpreter.runtime.TX = StackValue.BuildCallingConversion((int)ProtoCore.DSASM.CallingConvention.BounceType.Implicit); StackValue svBlockDecl = StackValue.BuildBlockIndex(blockDecl); // interpreter.runtime.SX = svBlockDecl; List <StackValue> registers = interpreter.runtime.GetRegisters(); var newStackFrame = new StackFrame(thisPtr, classScopeCaller, 1, returnAddr, blockDecl, blockCaller, callerType, StackFrameType.Function, 0, // depth framePointer, svBlockDecl.BlockIndex, registers, 0); bool isInDebugMode = runtimeCore.Options.IDEDebugMode && runtimeCore.Options.RunMode != InterpreterMode.Expression; if (isInDebugMode) { runtimeCore.DebugProps.SetUpCallrForDebug( runtimeCore, interpreter.runtime, procNode, returnAddr - 1, false, callsite, args, new List <List <ProtoCore.ReplicationGuide> >(), newStackFrame); } StackValue rx = callsite.JILDispatchViaNewInterpreter( new Runtime.Context(), args, new List <List <ProtoCore.ReplicationGuide> >(), null, newStackFrame, runtimeCore); if (isInDebugMode) { runtimeCore.DebugProps.RestoreCallrForNoBreak(runtimeCore, procNode); } return(rx); }
public StackValue Evaluate(List <StackValue> args, StackFrame stackFrame) { // Build the stackframe var runtimeCore = interpreter.runtime.Core; int classScopeCaller = (int)stackFrame.GetAt(StackFrame.AbsoluteIndex.kClass).opdata; int returnAddr = (int)stackFrame.GetAt(StackFrame.AbsoluteIndex.kReturnAddress).opdata; int blockDecl = (int)procNode.runtimeIndex; int blockCaller = (int)stackFrame.GetAt(StackFrame.AbsoluteIndex.kFunctionCallerBlock).opdata; int framePointer = runtimeCore.Rmem.FramePointer; StackValue thisPtr = StackValue.BuildPointer(-1); bool isCallingMemberFunciton = procNode.classScope != Constants.kInvalidIndex && !procNode.isConstructor && !procNode.isStatic; bool isValidThisPointer = true; if (isCallingMemberFunciton) { Validity.Assert(args.Count >= 1); thisPtr = args[0]; if (thisPtr.IsArray) { isValidThisPointer = ArrayUtils.GetFirstNonArrayStackValue(thisPtr, ref thisPtr, runtimeCore); } else { args.RemoveAt(0); } } if (!isValidThisPointer || (!thisPtr.IsPointer && !thisPtr.IsArray)) { runtimeCore.RuntimeStatus.LogWarning(WarningID.kDereferencingNonPointer, WarningMessage.kDeferencingNonPointer); return(StackValue.Null); } var callerType = (StackFrameType)stackFrame.GetAt(StackFrame.AbsoluteIndex.kStackFrameType).opdata; interpreter.runtime.TX = StackValue.BuildCallingConversion((int)ProtoCore.DSASM.CallingConvention.BounceType.kImplicit); StackValue svBlockDecl = StackValue.BuildBlockIndex(blockDecl); interpreter.runtime.SX = svBlockDecl; var repGuides = new List <List <ProtoCore.ReplicationGuide> >(); List <StackValue> registers = new List <StackValue>(); interpreter.runtime.SaveRegisters(registers); var newStackFrame = new StackFrame(thisPtr, classScopeCaller, 1, returnAddr, blockDecl, blockCaller, callerType, StackFrameType.kTypeFunction, 0, // depth framePointer, registers, null); bool isInDebugMode = runtimeCore.Options.IDEDebugMode && runtimeCore.ExecMode != InterpreterMode.kExpressionInterpreter; if (isInDebugMode) { runtimeCore.DebugProps.SetUpCallrForDebug(runtimeCore, interpreter.runtime, procNode, returnAddr - 1, false, callsite, args, repGuides, newStackFrame); } StackValue rx = callsite.JILDispatchViaNewInterpreter( new Runtime.Context(), args, repGuides, newStackFrame, runtimeCore); if (isInDebugMode) { runtimeCore.DebugProps.RestoreCallrForNoBreak(runtimeCore, procNode); } return(rx); }