Exemple #1
0
        private void Init(
            StackValue thisPtr,
            int classIndex,
            int functionIndex,
            int returnAddress,
            int functionBlockIndex,
            int callerBlockIndex,
            StackFrameType callerStackFrameType,
            StackFrameType stackFrameType,
            int depth,
            int framePointer,
            int blockIndex,
            List <StackValue> registers,
            int execStateSize)
        {
            Frame = new StackValue[StackFrameSize];

            Frame[AbsoluteIndex.ThisPtr]              = thisPtr;
            Frame[AbsoluteIndex.ClassIndex]           = StackValue.BuildClassIndex(classIndex);
            Frame[AbsoluteIndex.FunctionIndex]        = StackValue.BuildFunctionIndex(functionIndex);
            Frame[AbsoluteIndex.ReturnAddress]        = StackValue.BuildInt(returnAddress);
            Frame[AbsoluteIndex.FunctionBlockIndex]   = StackValue.BuildBlockIndex(functionBlockIndex);
            Frame[AbsoluteIndex.CallerBlockIndex]     = StackValue.BuildBlockIndex(callerBlockIndex);
            Frame[AbsoluteIndex.CallerStackFrameType] = StackValue.BuildFrameType((int)callerStackFrameType);
            Frame[AbsoluteIndex.StackFrameType]       = StackValue.BuildFrameType((int)stackFrameType);
            Frame[AbsoluteIndex.StackFrameDepth]      = StackValue.BuildInt(depth);
            Frame[AbsoluteIndex.LocalVariableCount]   = StackValue.BuildInt(0);
            Frame[AbsoluteIndex.ExecutionStates]      = StackValue.BuildInt(execStateSize);
            Frame[AbsoluteIndex.BlockIndex]           = StackValue.BuildBlockIndex(blockIndex);
            Frame[AbsoluteIndex.RX]           = registers[0];
            Frame[AbsoluteIndex.TX]           = registers[1];
            Frame[AbsoluteIndex.FramePointer] = StackValue.BuildInt(framePointer);
        }
Exemple #2
0
        /// <summary>
        /// Get all keys from an array
        /// </summary>
        /// <param name="core"></param>
        /// <returns></returns>
        public StackValue[] GetKeys()
        {
            var keys = Enumerable.Range(0, VisibleSize).Select(i => StackValue.BuildInt(i))
                       .Concat(Dict.Keys)
                       .ToArray();

            return(keys);
        }
Exemple #3
0
        /// <summary>
        /// Returns a list of key-value pairs for an array.
        /// </summary>
        /// <param name="array"></param>
        /// <param name="runtimeCore"></param>
        /// <returns></returns>
        public IDictionary <StackValue, StackValue> ToDictionary()
        {
            var dict = Enumerable.Range(0, Count)
                       .Select(i => new KeyValuePair <StackValue, StackValue>(StackValue.BuildInt(i), GetValueAt(i)))
                       .Concat(Dict ?? Enumerable.Empty <KeyValuePair <StackValue, StackValue> >())
                       .ToDictionary(p => p.Key, p => p.Value);

            return(dict);
        }
Exemple #4
0
        private void GCDisposeObject(StackValue svPtr, Executive exe)
        {
            int classIndex = svPtr.metaData.type;

            if (this.disposeProcedureNode == null || classIndex != previousClassIndex)
            {
                previousClassIndex = classIndex;
                ClassNode cn = exe.exe.classTable.ClassNodes[classIndex];

                isDSObject = !string.IsNullOrEmpty(cn.ExternLib) && cn.ExternLib.Contains(".ds");

                disposeProcedureNode = cn.GetDisposeMethod();
                while (disposeProcedureNode == null)
                {
                    if (cn.Base != Constants.kInvalidIndex)
                    {
                        classIndex           = cn.Base;
                        cn                   = exe.exe.classTable.ClassNodes[classIndex];
                        disposeProcedureNode = cn.GetDisposeMethod();
                    }
                    else
                    {
                        break;
                    }
                }
            }

            //legacy dispose for design script objects.  This may be very rare
            if (disposeProcedureNode != null && isDSObject)
            {
                // TODO Jun/Jiong: Use build pointer utilities
                exe.rmem.Push(StackValue.BuildArrayDimension(0));
                exe.rmem.Push(StackValue.BuildPointer(svPtr.Pointer, svPtr.metaData));
                exe.rmem.Push(StackValue.BuildInt(1));

                ++exe.RuntimeCore.FunctionCallDepth;

                // TODO: Need to move IsExplicitCall to DebugProps and come up with a more elegant solution for this
                // fix for IDE-963 - pratapa
                bool explicitCall = exe.IsExplicitCall;
                bool tempFlag     = explicitCall;
                exe.Callr(disposeProcedureNode.RuntimeIndex, disposeProcedureNode.ID, classIndex, ref explicitCall);

                exe.IsExplicitCall = tempFlag;

                --exe.RuntimeCore.FunctionCallDepth;
            }
            else if (disposeProcedureNode != null)
            {
                exe.CallDispose(disposeProcedureNode, svPtr, classIndex);
            }
        }
Exemple #5
0
        public static StackValue AsInt(this StackValue operand)
        {
            switch (operand.optype)
            {
            case AddressType.Int:
                return(operand);

            case AddressType.Double:
                return(StackValue.BuildInt((Int64)Math.Round(operand.opdata_d, 0, MidpointRounding.AwayFromZero)));

            default:
                return(StackValue.Null);
            }
        }
Exemple #6
0
        private void Init(StackValue svThisPtr, int classIndex, int funcIndex, int pc, int functionBlockDecl, int functionBlockCaller, StackFrameType callerType, StackFrameType type, int depth,
                          int framePointer, List <StackValue> stack, List <bool> execStates)
        {
            Validity.Assert((int)StackFrame.AbsoluteIndex.kSize == kStackFrameSize);

            Frame = new StackValue[kStackFrameSize];

            Frame[(int)AbsoluteIndex.kFramePointer]         = StackValue.BuildInt(framePointer);
            Frame[(int)AbsoluteIndex.kStackFrameType]       = StackValue.BuildFrameType((int)type);
            Frame[(int)AbsoluteIndex.kCallerStackFrameType] = StackValue.BuildFrameType((int)callerType);
            Frame[(int)AbsoluteIndex.kStackFrameDepth]      = StackValue.BuildInt(depth);
            Frame[(int)AbsoluteIndex.kFunctionCallerBlock]  = StackValue.BuildBlockIndex(functionBlockCaller);
            Frame[(int)AbsoluteIndex.kFunctionBlock]        = StackValue.BuildBlockIndex(functionBlockDecl);
            Frame[(int)AbsoluteIndex.kReturnAddress]        = StackValue.BuildInt(pc);
            Frame[(int)AbsoluteIndex.kFunction]             = StackValue.BuildInt(funcIndex);
            Frame[(int)AbsoluteIndex.kClass]   = StackValue.BuildInt(classIndex);
            Frame[(int)AbsoluteIndex.kThisPtr] = svThisPtr;

            Frame[(int)AbsoluteIndex.kRegisterAX] = stack[0];
            Frame[(int)AbsoluteIndex.kRegisterBX] = stack[1];
            Frame[(int)AbsoluteIndex.kRegisterCX] = stack[2];
            Frame[(int)AbsoluteIndex.kRegisterDX] = stack[3];
            Frame[(int)AbsoluteIndex.kRegisterEX] = stack[4];
            Frame[(int)AbsoluteIndex.kRegisterFX] = stack[5];
            Frame[(int)AbsoluteIndex.kRegisterLX] = stack[6];
            Frame[(int)AbsoluteIndex.kRegisterRX] = stack[7];
            Frame[(int)AbsoluteIndex.kRegisterSX] = stack[8];
            Frame[(int)AbsoluteIndex.kRegisterTX] = stack[9];

            int execStateSize = 0;

            if (null != execStates)
            {
                execStateSize   = execStates.Count;
                ExecutionStates = new StackValue[execStateSize];
                for (int n = 0; n < execStateSize; ++n)
                {
                    ExecutionStates[n] = StackValue.BuildBoolean(execStates[n]);
                }
            }

            Frame[(int)AbsoluteIndex.kExecutionStates] = StackValue.BuildInt(execStateSize);
            Frame[(int)AbsoluteIndex.kLocalVariables]  = StackValue.BuildInt(0);

            Validity.Assert(kStackFrameSize == Frame.Length);
        }
Exemple #7
0
        private void GCDisposeObject(StackValue svPtr, Executive exe)
        {
            int       classIndex = svPtr.metaData.type;
            ClassNode cn         = exe.exe.classTable.ClassNodes[classIndex];

            ProcedureNode pn = cn.GetDisposeMethod();

            while (pn == null)
            {
                if (cn.baseList != null && cn.baseList.Count != 0)
                {
                    classIndex = cn.baseList[0];
                    cn         = exe.exe.classTable.ClassNodes[classIndex];
                    pn         = cn.GetDisposeMethod();
                }
                else
                {
                    break;
                }
            }

            if (pn != null)
            {
                // TODO Jun/Jiong: Use build pointer utilities
                exe.rmem.Push(StackValue.BuildArrayDimension(0));
                exe.rmem.Push(StackValue.BuildPointer(svPtr.opdata, svPtr.metaData));
                exe.rmem.Push(StackValue.BuildArrayDimension(0));
                exe.rmem.Push(StackValue.BuildStaticType((int)PrimitiveType.kTypeVar));
                exe.rmem.Push(StackValue.BuildInt(1));

                ++exe.RuntimeCore.FunctionCallDepth;

                // TODO: Need to move IsExplicitCall to DebugProps and come up with a more elegant solution for this
                // fix for IDE-963 - pratapa
                bool explicitCall = exe.IsExplicitCall;
                bool tempFlag     = explicitCall;
                exe.Callr(pn.runtimeIndex, pn.procId, classIndex, ref explicitCall);

                exe.IsExplicitCall = tempFlag;

                --exe.RuntimeCore.FunctionCallDepth;
            }
        }
Exemple #8
0
 public IDictionary <StackValue, StackValue> ToDictionary()
 {
     return(Enumerable.Range(0, Count)
            .Select(i => new KeyValuePair <StackValue, StackValue>(StackValue.BuildInt(i), GetValueAt(i)))
            .ToDictionary(p => p.Key, p => p.Value));
 }
Exemple #9
0
 public void Push(Int64 val)
 {
     runtime.rmem.Push(StackValue.BuildInt(val));
 }