コード例 #1
0
ファイル: HeapObjects.cs プロジェクト: piotrkopec/Dynamo
        public static bool CompareFromDifferentCore(DSArray array1, DSArray array2, RuntimeCore rtCore1, RuntimeCore rtCore2, Context context = null)
        {
            if (array1.Count != array2.Count)
            {
                return(false);
            }

            for (int i = 0; i < array1.Count; i++)
            {
                if (!StackUtils.CompareStackValues(array1.GetValueAt(i), array2.GetValueAt(i), rtCore1, rtCore2, context))
                {
                    return(false);
                }
            }

            foreach (var key in array1.Dict.Keys)
            {
                StackValue value1 = array1.Dict[key];
                StackValue value2 = StackValue.Null;
                if (!array2.Dict.TryGetValue(key, out value2))
                {
                    return(false);
                }

                if (!StackUtils.CompareStackValues(value1, value2, rtCore1, rtCore2))
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #2
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)
        {
            Validity.Assert((int)StackFrame.AbsoluteIndex.kSize == kStackFrameSize);

            Frame = new StackValue[kStackFrameSize];

            Frame[(int)AbsoluteIndex.kFramePointer]         = StackUtils.BuildInt(framePointer);
            Frame[(int)AbsoluteIndex.kStackFrameType]       = StackUtils.BuildNode(AddressType.FrameType, (int)type);
            Frame[(int)AbsoluteIndex.kCallerStackFrameType] = StackUtils.BuildNode(AddressType.FrameType, (int)callerType);
            Frame[(int)AbsoluteIndex.kStackFrameDepth]      = StackUtils.BuildInt(depth);
            Frame[(int)AbsoluteIndex.kFunctionCallerBlock]  = StackUtils.BuildNode(AddressType.BlockIndex, functionBlockCaller);
            Frame[(int)AbsoluteIndex.kFunctionBlock]        = StackUtils.BuildNode(AddressType.BlockIndex, functionBlockDecl);
            Frame[(int)AbsoluteIndex.kReturnAddress]        = StackUtils.BuildInt(pc);
            Frame[(int)AbsoluteIndex.kFunction]             = StackUtils.BuildInt(funcIndex);
            Frame[(int)AbsoluteIndex.kClass]   = StackUtils.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];

            Validity.Assert(kStackFrameSize == Frame.Length);
        }
コード例 #3
0
ファイル: Heap.cs プロジェクト: riteshchandawar/designscript
        public bool IsTemporaryPointer(StackValue sv)
        {
            if (!StackUtils.IsReferenceType(sv))
            {
                return(false);
            }

            int         ptr = (int)sv.opdata;
            HeapElement he  = this.Heaplist[ptr];

            return(he.Active && he.Refcount == 0);
        }
コード例 #4
0
ファイル: Heap.cs プロジェクト: riteshchandawar/designscript
        public void DecRefCount(StackValue sv)
        {
            if (!StackUtils.IsReferenceType(sv))
            {
                return;
            }

            int ptr = (int)sv.opdata;

            Debug.Assert(this.Heaplist[ptr].Refcount > 0);
            this.Heaplist[ptr].Refcount--;
        }
コード例 #5
0
ファイル: Stack.cs プロジェクト: riteshchandawar/designscript
        // heaper method to support negative index into stack
        public static StackValue GetValue(this HeapElement hs, int ix, Core core)
        {
            int index = ix < 0 ? ix + hs.VisibleSize : ix;

            if (index >= hs.VisibleSize || index < 0)
            {
                //throw new IndexOutOfRangeException();
                core.RuntimeStatus.LogWarning(ProtoCore.RuntimeData.WarningID.kOverIndexing, RuntimeData.WarningMessage.kArrayOverIndexed);
                return(StackUtils.BuildNull());
            }

            return(hs.Stack[index]);
        }
コード例 #6
0
ファイル: Stack.cs プロジェクト: riteshchandawar/designscript
        //this method compares the heap for the stack variables and determines if the values of the heap are same
        private static bool CompareStackValuesFromHeap(StackValue sv1, StackValue sv2, Core c1, Core c2, ProtoCore.Runtime.Context context)
        {
            HeapElement heap1 = ArrayUtils.GetHeapElement(sv1, c1);
            HeapElement heap2 = ArrayUtils.GetHeapElement(sv1, c2);

            if (heap1.Stack.Length != heap2.Stack.Length)
            {
                return(false);
            }

            for (int i = 0; i < heap1.Stack.Length; i++)
            {
                if (!CompareStackValues(heap1.Stack[i], heap2.Stack[i], c1, c2, context))
                {
                    return(false);
                }
            }

            if (heap1.Dict != null && heap2.Dict != null)
            {
                if (heap1.Dict == heap2.Dict)
                {
                    return(true);
                }

                foreach (var key in heap1.Dict.Keys)
                {
                    StackValue value1 = heap1.Dict[key];
                    StackValue value2 = StackUtils.BuildNull();
                    if (!heap2.Dict.TryGetValue(key, out value2))
                    {
                        return(false);
                    }

                    if (!CompareStackValues(value1, value2, c1, c2))
                    {
                        return(false);
                    }
                }

                return(true);
            }
            else if (heap1.Dict == null && heap2.Dict == null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #7
0
ファイル: Heap.cs プロジェクト: riteshchandawar/designscript
        public void IncRefCount(StackValue sv)
        {
            if (!StackUtils.IsReferenceType(sv))
            {
                return;
            }

            int ptr = (int)sv.opdata;

            this.Heaplist[ptr].Refcount++;
            if (this.Heaplist[ptr].Refcount > 0)
            {
                this.Heaplist[ptr].Active = true;
            }
        }
コード例 #8
0
ファイル: Heap.cs プロジェクト: riteshchandawar/designscript
        public void RightShiftElements(int size)
        {
            Debug.Assert(VisibleSize + size <= AllocSize);
            if (size <= 0)
            {
                return;
            }

            for (int pos = VisibleSize - 1; pos >= 0; pos--)
            {
                int targetPos = pos + size;
                Stack[targetPos] = Stack[pos];
                Stack[pos]       = StackUtils.BuildNull();
            }

            VisibleSize = VisibleSize + size;
        }
コード例 #9
0
ファイル: Stack.cs プロジェクト: riteshchandawar/designscript
        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]         = StackUtils.BuildInt(framePointer);
            Frame[(int)AbsoluteIndex.kStackFrameType]       = StackUtils.BuildNode(AddressType.FrameType, (int)type);
            Frame[(int)AbsoluteIndex.kCallerStackFrameType] = StackUtils.BuildNode(AddressType.FrameType, (int)callerType);
            Frame[(int)AbsoluteIndex.kStackFrameDepth]      = StackUtils.BuildInt(depth);
            Frame[(int)AbsoluteIndex.kFunctionCallerBlock]  = StackUtils.BuildNode(AddressType.BlockIndex, functionBlockCaller);
            Frame[(int)AbsoluteIndex.kFunctionBlock]        = StackUtils.BuildNode(AddressType.BlockIndex, functionBlockDecl);
            Frame[(int)AbsoluteIndex.kReturnAddress]        = StackUtils.BuildInt(pc);
            Frame[(int)AbsoluteIndex.kFunction]             = StackUtils.BuildInt(funcIndex);
            Frame[(int)AbsoluteIndex.kClass]   = StackUtils.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] = StackUtils.BuildBoolean(execStates[n]);
                }
            }

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

            Validity.Assert(kStackFrameSize == Frame.Length);
        }
コード例 #10
0
        public static bool CompareFromDifferentCore(DSArray array1, DSArray array2, RuntimeCore rtCore1, RuntimeCore rtCore2, Context context = null)
        {
            if (array1.Count != array2.Count)
            {
                return(false);
            }

            for (int i = 0; i < array1.Count; i++)
            {
                if (!StackUtils.CompareStackValues(array1.GetValueAt(i), array2.GetValueAt(i), rtCore1, rtCore2, context))
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #11
0
ファイル: Heap.cs プロジェクト: riteshchandawar/designscript
        private void GCDisposeObject(ref StackValue svPtr, Executive exe)
        {
            int           classIndex = (int)svPtr.metaData.type;
            ClassNode     cn         = exe.exe.classTable.ClassNodes[classIndex];
            ProcedureNode pn         = null;

            while (pn == null)
            {
                pn = cn.GetDisposeMethod();
                if (pn == null && cn.baseList != null && cn.baseList.Count != 0) // search the base class
                {
                    // assume multiple inheritance is not allowed
                    // it will only has a single base class
                    classIndex = cn.baseList[0];
                    cn         = exe.exe.classTable.ClassNodes[cn.baseList[0]];
                }
                else
                {
                    break;
                }
            }

            if (pn != null)
            {
                // TODO Jun/Jiong: Use build pointer utilities
                exe.rmem.Push(StackUtils.BuildNode(AddressType.ArrayDim, 0));
                exe.rmem.Push(StackUtils.BuildPointer(svPtr.opdata, svPtr.metaData));
                exe.rmem.Push(StackUtils.BuildNode(AddressType.BlockIndex, pn.runtimeIndex));
                exe.rmem.Push(StackUtils.BuildNode(AddressType.ArrayDim, 0));
                exe.rmem.Push(StackUtils.BuildStaticType((int)ProtoCore.PrimitiveType.kTypeVar));

                ++exe.Core.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.procId, classIndex, 1, ref explicitCall);

                exe.isExplicitCall = tempFlag;

                --exe.Core.FunctionCallDepth;
            }
        }
コード例 #12
0
ファイル: Heap.cs プロジェクト: riteshchandawar/designscript
        //
        // TODO Jun: Optimize the reallocation routines
        //      1. Copying the temps can be optimized.
        //      2. Explore using List for the HeapStack stack. In this case we take advantage of .Net List arrays
        //
        public void ReAllocate(int size)
        {
            int newAllocatedSize = GetNewSize(size);

            // Copy current contents into a temp array
            StackValue[] tempstack = new StackValue[AllocSize];
            Stack.CopyTo(tempstack, 0);

            // Reallocate the array and copy the temp contents to it
            Stack = new StackValue[newAllocatedSize];
            tempstack.CopyTo(Stack, 0);

            for (int i = AllocSize; i < newAllocatedSize; ++i)
            {
                Stack[i] = StackUtils.BuildNull();
            }

            AllocSize = newAllocatedSize;
            Debug.Assert(size <= AllocSize);
        }
コード例 #13
0
ファイル: Stack.cs プロジェクト: riteshchandawar/designscript
        public static StackValue BuildString(string str, Heap heap)
        {
            var svchars = new List <StackValue>();

            foreach (char ch in str)
            {
                svchars.Add(ProtoCore.DSASM.StackUtils.BuildChar(ch));
            }

            lock (heap.cslock)
            {
                int size = str.Length;

                int ptr = heap.Allocate(size);

                for (int i = 0; i < size; ++i)
                {
                    heap.Heaplist[ptr].Stack[i] = BuildChar(str[i]);
                }

                return(StackUtils.BuildString(ptr));
            }
        }
コード例 #14
0
 public void Push(Int64 val)
 {
     runtime.rmem.Push(StackUtils.BuildInt(val));
 }
コード例 #15
0
 public void Push(double val)
 {
     runtime.rmem.Push(StackUtils.BuildDouble(val));
 }
コード例 #16
0
ファイル: Heap.cs プロジェクト: rafatahmed/Dynamo
 public bool Equals(StackValue x, StackValue y)
 {
     return StackUtils.CompareStackValues(x, y, runtimeCore, runtimeCore);
 }
コード例 #17
0
ファイル: Heap.cs プロジェクト: riteshchandawar/designscript
 public bool Equals(StackValue x, StackValue y)
 {
     return(StackUtils.CompareStackValues(x, y, core, core));
 }