Esempio n. 1
0
        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.IsObject() && !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);
        }