示例#1
0
        /// <summary>
        /// VM Debugging API for general Debugging purposes
        /// temporarily used by Cmmand Line REPL
        /// </summary>
        /// <returns></returns>
        public string GetCoreDump()
        {
            // Prints out the final Value of every symbol in the program
            // Traverse order:
            //  Exelist, Globals symbols

            StringBuilder globaltrace = null;

            ProtoCore.DSASM.Executive exec = runnerCore.CurrentExecutive.CurrentDSASMExec;
            ProtoCore.DSASM.Mirror.ExecutionMirror execMirror = new ProtoCore.DSASM.Mirror.ExecutionMirror(exec, runnerCore);
            ProtoCore.DSASM.Executable             exe        = exec.rmem.Executable;

            // Only display symbols defined in the default top-most langauge block;
            // Otherwise garbage information may be displayed.
            string formattedString = string.Empty;

            if (exe.runtimeSymbols.Length > 0)
            {
                int blockId = 0;

                ProtoCore.DSASM.SymbolTable symbolTable = exe.runtimeSymbols[blockId];

                for (int i = 0; i < symbolTable.symbolList.Count; ++i)
                {
                    //int n = symbolTable.symbolList.Count - 1;
                    //formatParams.ResetOutputDepth();
                    ProtoCore.DSASM.SymbolNode symbolNode = symbolTable.symbolList[i];

                    bool isLocal  = ProtoCore.DSASM.Constants.kGlobalScope != symbolNode.functionIndex;
                    bool isStatic = (symbolNode.classScope != ProtoCore.DSASM.Constants.kInvalidIndex && symbolNode.isStatic);
                    if (symbolNode.isArgument || isLocal || isStatic || symbolNode.isTemp)
                    {
                        // These have gone out of scope, their values no longer exist
                        //return ((null == globaltrace) ? string.Empty : globaltrace.ToString());
                        continue;
                    }

                    ProtoCore.Runtime.RuntimeMemory rmem = exec.rmem;
                    ProtoCore.DSASM.StackValue      sv   = rmem.GetStackData(blockId, i, ProtoCore.DSASM.Constants.kGlobalScope);
                    formattedString = formattedString + string.Format("{0} = {1}\n", symbolNode.name, execMirror.GetStringValue(sv, rmem.Heap, blockId));

                    //if (null != globaltrace)
                    //{
                    //    int maxLength = 1020;
                    //    while (formattedString.Length > maxLength)
                    //    {
                    //        globaltrace.AppendLine(formattedString.Substring(0, maxLength));
                    //        formattedString = formattedString.Remove(0, maxLength);
                    //    }

                    //    globaltrace.AppendLine(formattedString);
                    //}
                }

                //formatParams.ResetOutputDepth();
            }

            //return ((null == globaltrace) ? string.Empty : globaltrace.ToString());
            return(formattedString);
        }
示例#2
0
        public void Execute(ProtoCore.Core core, ProtoCore.Runtime.Context context, ProtoLanguage.CompileStateTracker compileState)
        {
            try
            {
                compileState.NotifyExecutionEvent(ProtoCore.ExecutionStateEventArgs.State.kExecutionBegin);
                foreach (ProtoCore.DSASM.CodeBlock codeblock in core.DSExecutable.CodeBlockList)
                {
                    int locals = 0;


                    // Comment Jun:
                    // On first bounce, the stackframe depth is initialized to -1 in the Stackfame constructor.
                    // Passing it to bounce() increments it so the first depth is always 0
                    ProtoCore.DSASM.StackFrame stackFrame = new ProtoCore.DSASM.StackFrame(core.GlobOffset);

                    // Comment Jun: Tell the new bounce stackframe that this is an implicit bounce
                    // Register TX is used for this.
                    ProtoCore.DSASM.StackValue svCallConvention = ProtoCore.DSASM.StackUtils.BuildNode(ProtoCore.DSASM.AddressType.CallingConvention, (long)ProtoCore.DSASM.CallingConvention.BounceType.kImplicit);
                    stackFrame.SetAt(ProtoCore.DSASM.StackFrame.AbsoluteIndex.kRegisterTX, svCallConvention);

                    core.Bounce(codeblock.codeBlockId, codeblock.instrStream.entrypoint, context, stackFrame, locals, EventSink);
                }
                core.NotifyExecutionEvent(ProtoCore.ExecutionStateEventArgs.State.kExecutionEnd);
            }
            catch
            {
                core.NotifyExecutionEvent(ProtoCore.ExecutionStateEventArgs.State.kExecutionEnd);
                throw;
            }
        }
        private ProtoCore.Lang.Obj ExecExecutiveExpression(ExpressionInterpreterRunner exprInterpreter, string expression)
        {
            if (expression.Equals("@pc"))
            {
                int pc = core.CurrentExecutive.CurrentDSASMExec.PC;
                ProtoCore.DSASM.StackValue svpc = ProtoCore.DSASM.StackUtils.BuildInt(pc);
                return(new ProtoCore.Lang.Obj(svpc)
                {
                    Payload = pc, Type = new Type {
                        UID = (int)PrimitiveType.kTypeInt, IsIndexable = false
                    }
                });
            }
            else if (expression.StartsWith("@rc(") && expression.EndsWith(")"))
            {
                /*
                 * string subexpression = expression.Substring(4, expression.Length - 5);
                 * var watchMirror = exprInterpreter.Execute(subexpression);
                 * if (null != watchMirror)
                 * {
                 *  ProtoCore.Lang.Obj value = watchMirror.GetWatchValue();
                 *  if (value != null)
                 *  {
                 *      int rc = watchMirror.GetReferenceCount(value);
                 *      ProtoCore.DSASM.StackValue rcValue = ProtoCore.DSASM.StackUtils.BuildInt(rc);
                 *      return new ProtoCore.Lang.Obj(rcValue) { Payload = rc, Type = new Type { UID = (int)PrimitiveType.kTypeInt, IsIndexable = false } };
                 *  }
                 * }
                 */
            }

            return(null);
        }
示例#4
0
 public override ProtoCore.DSASM.StackValue Execute(int codeblock, int entry, ProtoCore.Runtime.Context callContext, System.Collections.Generic.List <ProtoCore.DSASM.Instruction> breakpoints, ProtoCore.DebugServices.EventSink sink = null, bool fepRun = false)
 {
     ProtoCore.DSASM.Interpreter interpreter = new ProtoCore.DSASM.Interpreter(core, fepRun);
     CurrentDSASMExec = interpreter.runtime;
     ProtoCore.DSASM.StackValue sv = interpreter.Run(breakpoints, codeblock, entry, Language.kAssociative);
     return(sv);
 }
        public void TestSimpleAddition()
        {
            // 1. Create code block node with value of 123.
            // 2. Create "Add" function node.
            // 3. Drag to connect from output of code block node to first input of add function node.
            //
            string commands = @"
                CreateCodeBlockNode|d:15381.0|d:15112.0|s:Your code goes here
                BeginNodeEdit|u:0x10000001|e:DesignScriptStudio.Graph.Core.NodePart,Text
                EndNodeEdit|u:0x10000001|s:3|b:True
                CreateCodeBlockNode|d:15339.0|d:15196.0|s:Your code goes here
                BeginNodeEdit|u:0x10000002|e:DesignScriptStudio.Graph.Core.NodePart,Text
                EndNodeEdit|u:0x10000002|s:5|b:True
                CreateFunctionNode|d:15497.0|d:15135.0|s:Special Nodes|s:+|s:double,double
                MouseDown|e:System.Windows.Input.MouseButton,Left|u:0x10000001|e:DesignScriptStudio.Graph.Core.NodePart,OutputSlot|i:0|e:System.Windows.Input.ModifierKeys,None
                BeginDrag|e:System.Windows.Input.MouseButton,Left|u:0x10000001|e:DesignScriptStudio.Graph.Core.NodePart,OutputSlot|i:0|e:System.Windows.Input.ModifierKeys,None|d:15343.0|d:15113.0
                EndDrag|e:System.Windows.Input.MouseButton,Left|u:0x10000003|e:DesignScriptStudio.Graph.Core.NodePart,InputSlot|i:0|e:System.Windows.Input.ModifierKeys,None|d:15449.0|d:15129.0
                MouseUp|e:System.Windows.Input.MouseButton,Left|u:0x10000003|e:DesignScriptStudio.Graph.Core.NodePart,InputSlot|i:0|e:System.Windows.Input.ModifierKeys,None
                MouseDown|e:System.Windows.Input.MouseButton,Left|u:0x10000002|e:DesignScriptStudio.Graph.Core.NodePart,OutputSlot|i:0|e:System.Windows.Input.ModifierKeys,None
                BeginDrag|e:System.Windows.Input.MouseButton,Left|u:0x10000002|e:DesignScriptStudio.Graph.Core.NodePart,OutputSlot|i:0|e:System.Windows.Input.ModifierKeys,None|d:15301.0|d:15199.0
                EndDrag|e:System.Windows.Input.MouseButton,Left|u:0x10000003|e:DesignScriptStudio.Graph.Core.NodePart,InputSlot|i:1|e:System.Windows.Input.ModifierKeys,None|d:15436.0|d:15147.0
                MouseUp|e:System.Windows.Input.MouseButton,Left|u:0x10000003|e:DesignScriptStudio.Graph.Core.NodePart,InputSlot|i:1|e:System.Windows.Input.ModifierKeys,None";

            GraphController controller = new GraphController(null);

            // Indicate that the test case is interested in the values of
            // all these nodes whose IDs are represented by the input array.
            controller.RegisterPreviewRequest(new uint[]
            {
                0x10000001,
                0x10000002,
                0x10000003
            });

            bool result = controller.RunCommands(commands);

            Assert.AreEqual(true, result);

            // WaitForPreviewRequestCompletion method internally creates a Task and
            // blocks on its 'Result' property until either it timed out, or all the
            // requested node values are computed.
            Assert.AreEqual(true, controller.WaitForPreviewRequestCompletion(100000));

            // These calls are just to validate requested node values.
            PreviewRequest requestedData = controller.GetPreviewRequest();

            ProtoCore.DSASM.StackValue value = requestedData.GetNodeValue(0x10000003);
            Assert.AreEqual(8, value.opdata);

            value = requestedData.GetNodeValue(0x10000001);
            Assert.AreEqual(3, value.opdata);

            value = requestedData.GetNodeValue(0x10000002);
            Assert.AreEqual(5, value.opdata);
        }
示例#6
0
 public override ProtoCore.DSASM.StackValue Execute(int codeblock, int entry, ProtoCore.Runtime.Context callContext, ProtoCore.DebugServices.EventSink sink)
 {
     ProtoCore.DSASM.StackValue sv = new ProtoCore.DSASM.StackValue();
     if (!core.Options.CompileToLib)
     {
         ProtoCore.DSASM.Interpreter interpreter = new ProtoCore.DSASM.Interpreter(core);
         CurrentDSASMExec = interpreter.runtime;
         sv = interpreter.Run(codeblock, entry, Language.kAssociative);
     }
     return(sv);
 }
示例#7
0
        public override ProtoCore.DSASM.StackValue Execute(int codeblock, int entry, ProtoCore.Runtime.Context callContext, ProtoCore.DebugServices.EventSink sink)
        {
            ProtoCore.DSASM.StackValue sv = new ProtoCore.DSASM.StackValue();
            if (!core.Options.CompileToLib)
            {
                ProtoCore.DSASM.Interpreter interpreter = new ProtoCore.DSASM.Interpreter(core);
                CurrentDSASMExec = interpreter.runtime;
                sv = interpreter.Run(codeblock, entry, ProtoCore.Language.kImperative);
                return sv;
            }

            return new ProtoCore.DSASM.StackValue();
        }
示例#8
0
        public static StackValue BuildChar(char ch)
        {
            StackValue value = new ProtoCore.DSASM.StackValue();

            value.optype   = ProtoCore.DSASM.AddressType.Char;
            value.opdata   = ProtoCore.Utils.EncodingUtils.ConvertCharacterToInt64(ch);
            value.opdata_d = value.opdata;

            MetaData mdata = new MetaData();

            mdata.type     = (int)PrimitiveType.kTypeChar;
            value.metaData = mdata;
            return(value);
        }
示例#9
0
        public StackFrame(int globalOffset)
        {
            ProtoCore.DSASM.StackValue svThisPtr = ProtoCore.DSASM.StackUtils.BuildPointer(ProtoCore.DSASM.Constants.kInvalidPointer);
            int ci          = ProtoCore.DSASM.Constants.kInvalidIndex;
            int fi          = ProtoCore.DSASM.Constants.kInvalidIndex;
            int returnAddr  = ProtoCore.DSASM.Constants.kInvalidIndex;
            int blockDecl   = ProtoCore.DSASM.Constants.kInvalidIndex;
            int blockCaller = 0;

            StackFrameType callerType   = StackFrameType.kTypeLanguage;
            StackFrameType type         = StackFrameType.kTypeLanguage;
            int            depth        = -1;
            int            framePointer = globalOffset;

            Init(svThisPtr, ci, fi, returnAddr, blockDecl, blockCaller, callerType, type, depth, framePointer, ProtoCore.DSASM.StackUtils.BuildInvalidRegisters(), new List <bool>());
        }
示例#10
0
        public void VerifyReferenceCount(string dsVariable, int referencCount)
        {
            try
            {
                ProtoCore.DSASM.StackValue sv = testMirror.GetRawFirstValue(dsVariable);

                if (sv.optype != ProtoCore.DSASM.AddressType.ArrayPointer &&
                    sv.optype != ProtoCore.DSASM.AddressType.Pointer)
                {
                    if (referencCount != 0)
                    {
                        Assert.Fail(String.Format("\t{0} is not a heap element, it doesn't sense to verify its reference count. Should always be 0", dsVariable));
                    }
                }
                else
                {
                    int ptr = (int)sv.opdata;
                    ProtoCore.DSASM.HeapElement he = testMirror.MirrorTarget.rmem.Heap.Heaplist[ptr];

                    if (he.Refcount != referencCount)
                    {
                        Assert.Fail(String.Format("\t{0}'s reference count is {1}, which is not equal to expected {2}", dsVariable, he.Refcount, referencCount));
                    }
                    else if (referencCount > 0)
                    {
                        if (!he.Active)
                        {
                            Assert.Fail(String.Format("\t{0}'s reference count == {1}, but somehow it is makred as inactive.", dsVariable, referencCount));
                        }
                    }
                }
            }
            catch (NotImplementedException)
            {
                Assert.Fail("\tFailed to get the value of variable " + dsVariable);
            }
        }
示例#11
0
        private bool ProcessDynamicFunction(Instruction instr)
        {
            int fptr = ProtoCore.DSASM.Constants.kInvalidIndex;
            int functionDynamicIndex = (int)instr.op1.opdata;
            int classIndex = (int)instr.op2.opdata;
            int depth = (int)instr.op3.opdata;
            bool isDotMemFuncBody = functionDynamicIndex == ProtoCore.DSASM.Constants.kInvalidIndex;
            bool isFunctionPointerCall = false;
            if (isDotMemFuncBody)
            {
                functionDynamicIndex = (int)rmem.Pop().opdata;
            }

            DSASM.DynamicFunctionNode dynamicFunctionNode = core.DynamicFunctionTable.functionTable[functionDynamicIndex];

            if (isDotMemFuncBody)
            {
                classIndex = dynamicFunctionNode.classIndex;
            }

            string procName = dynamicFunctionNode.functionName;
            List<ProtoCore.Type> arglist = dynamicFunctionNode.argList;
            if (procName == ProtoCore.DSASM.Constants.kFunctionPointerCall && depth == 0)
            {
                isFunctionPointerCall = true;
                classIndex = ProtoCore.DSASM.Constants.kGlobalScope;
                StackValue fpSv = rmem.Pop();
                if (fpSv.optype != AddressType.FunctionPointer)
                {
                    rmem.Pop(arglist.Count); //remove the arguments
                    return false;
                }
                fptr = (int)fpSv.opdata;
            }



            //retrieve the function arguments
            List<StackValue> argSvList = new List<StackValue>();
            if (isDotMemFuncBody)
            {
                arglist = new List<Type>();
                StackValue argArraySv = rmem.Pop();
                for (int i = 0; i < core.Heap.Heaplist[(int)argArraySv.opdata].VisibleSize; ++i)
                {
                    StackValue sv = core.Heap.Heaplist[(int)argArraySv.opdata].Stack[i];
                    argSvList.Add(sv); //actual arguments
                    ProtoCore.Type paramType = new ProtoCore.Type();
                    paramType.UID = (int)sv.metaData.type;
                    paramType.IsIndexable = sv.optype == AddressType.ArrayPointer;
                    if (paramType.IsIndexable)
                    {
                        StackValue paramSv = sv;
                        while (paramSv.optype == AddressType.ArrayPointer)
                        {
                            paramType.rank++;
                            int arrayHeapPtr = (int)paramSv.opdata;
                            if (core.Heap.Heaplist[arrayHeapPtr].VisibleSize > 0)
                            {
                                paramSv = core.Heap.Heaplist[arrayHeapPtr].Stack[0];
                                paramType.UID = (int)paramSv.metaData.type;
                            }
                            else
                            {
                                paramType.UID = (int)ProtoCore.PrimitiveType.kTypeArray;
                                break;
                            }
                        }
                    }
                    arglist.Add(paramType); //build arglist
                }
                argSvList.Reverse();
            }
            else
            {
                for (int i = 0; i < arglist.Count; i++)
                {
                    StackValue argSv = rmem.Pop();
                    argSvList.Add(argSv);
                }
            }
            int lefttype = DSASM.Constants.kGlobalScope;
            bool isLeftClass = false;
            if (isDotMemFuncBody && rmem.Stack.Last().optype == AddressType.Int) //constructor or static function
            {
                //in this case, ptr won't be used
                lefttype = (int)rmem.Pop().opdata;
                isLeftClass = true;
            }
            else if (depth > 0)
            {
                //resolve the identifier list            
                StackValue pSv = GetFinalPointer(depth);
                //push the resolved stack value to stack
                rmem.Push(pSv);
                lefttype = (int)pSv.metaData.type;
            }

            int type = lefttype;

            if (depth > 0)
            {
                // check whether it is function pointer, this checking is done at runtime to handle the case
                // when turning on converting dot operator to function call
                if (!((int)ProtoCore.PrimitiveType.kTypeVoid == type
                    || ProtoCore.DSASM.Constants.kInvalidIndex == type
                    || core.ClassTable.ClassNodes[type].symbols == null))
                {
                    bool hasThisSymbol;
                    ProtoCore.DSASM.AddressType addressType;
                    SymbolNode node = null;
                    bool isStatic = false;
                    int symbolIndex = core.ClassTable.ClassNodes[type].GetSymbolIndex(procName, type, DSASM.Constants.kGlobalScope, core.RunningBlock, core, out hasThisSymbol, out addressType);
                    if (ProtoCore.DSASM.Constants.kInvalidIndex != symbolIndex)
                    {
                        if (addressType == AddressType.StaticMemVarIndex)
                        {
                            node = core.CodeBlockList[0].symbolTable.symbolList[symbolIndex];
                            isStatic = true;
                        }
                        else
                        {
                            node = core.ClassTable.ClassNodes[type].symbols.symbolList[symbolIndex];
                        }
                    }
                    if (node != null)
                    {
                        isFunctionPointerCall = true;
                        StackValue fpSv = new StackValue();
                        fpSv.opdata = node.symbolTableIndex;
                        fpSv.optype = isStatic ? AddressType.StaticMemVarIndex : AddressType.Pointer;
                        if (fpSv.optype == AddressType.StaticMemVarIndex)
                        {
                            StackValue op2 = new StackValue();
                            op2.optype = AddressType.ClassIndex;
                            op2.opdata = Constants.kInvalidIndex;

                            fpSv = GetOperandData(0, fpSv, op2);
                        }
                        else
                        {
                            int ptr = (int)rmem.Stack.Last().opdata;
                            fpSv = core.Heap.Heaplist[ptr].Stack[(int)fpSv.opdata];
                        }
                        //assuming the dimension is zero, as funtion call with nonzero dimension is not supported yet

                        // Check the last pointer
                        AddressType addrtype = fpSv.optype;
                        if (AddressType.Pointer == addrtype || AddressType.Invalid == addrtype)
                        {
                            /*
                              if lookahead is Not a pointer then
                                  move to that pointer and get its value at stack index 0 (or further if array)
                                  push that
                              else 
                                  push the current ptr
                              end
                            */

                            // Determine if we still need to move one more time on the heap
                            // Peek into the pointed data using nextPtr. 
                            // If nextPtr is not a pointer (a primitive) then return the data at nextPtr
                            int nextPtr = (int)fpSv.opdata;
                            bool isActualData =
                                    AddressType.Pointer != core.Heap.Heaplist[nextPtr].Stack[0].optype
                                && AddressType.ArrayPointer != core.Heap.Heaplist[nextPtr].Stack[0].optype
                                && AddressType.Invalid != core.Heap.Heaplist[nextPtr].Stack[0].optype; // Invalid is an uninitialized member

                            if (isActualData)
                            {
                                // Move one more and get the value at the first heapstack
                                fpSv = core.Heap.Heaplist[nextPtr].Stack[0];
                            }
                        }
                        if (fpSv.optype != AddressType.FunctionPointer)
                        {
                            rmem.Pop(); //remove final pointer
                            return false;
                        }
                        fptr = (int)fpSv.opdata;
                    }
                }
            }

            ProtoCore.DSASM.ProcedureNode procNode = null;
            if (isFunctionPointerCall)
            {
                ProtoCore.DSASM.FunctionPointerNode fptrNode;
                if (core.FunctionPointerTable.functionPointerDictionary.TryGetByFirst(fptr, out fptrNode))
                {
                    int blockId = fptrNode.blockId;
                    int procId = fptrNode.procId;
                    procName = exe.procedureTable[blockId].procList[procId].name;
                    CodeBlock codeblock = core.GetCodeBlock(core.CodeBlockList, blockId);
                    procNode = core.GetFirstVisibleProcedure(procName, arglist, codeblock);
                    type = ProtoCore.DSASM.Constants.kGlobalScope; //function class scope must be kGlobalScope
                }
                else
                {
                    procNode = null;
                }
            }
            else
            {
                // This is a member function of the previous type
                if (ProtoCore.DSASM.Constants.kInvalidIndex != type)
                {
                    int realType;
                    bool isAccessible;
                    ProtoCore.DSASM.ProcedureNode memProcNode = core.ClassTable.ClassNodes[type].GetMemberFunction(procName, arglist, classIndex, out isAccessible, out realType);

                    if (memProcNode == null)
                    {
                        string property;
                        if (CoreUtils.TryGetPropertyName(procName, out property))
                        {
                            string classname = core.ClassTable.ClassNodes[type].name;
                            string message = String.Format(ProtoCore.RuntimeData.WarningMessage.kPropertyOfClassNotFound, classname, property);
                            core.RuntimeStatus.LogWarning(ProtoCore.RuntimeData.WarningID.kMethodResolutionFailure, message);
                        }
                        else
                        {
                            string message = String.Format(ProtoCore.RuntimeData.WarningMessage.kMethodResolutionFailure, procName);
                            core.RuntimeStatus.LogWarning(ProtoCore.RuntimeData.WarningID.kMethodResolutionFailure, message);
                        }
                    }
                    else
                    {
                        procNode = memProcNode;
                        type = realType;

                        // if the proc node is not accessible, that error will be handled by
                        // callr() later on. 
                    }
                }
            }

            if (null != procNode)
            {
                if (ProtoCore.DSASM.Constants.kInvalidIndex != procNode.procId)
                {
                    if (isLeftClass || (isFunctionPointerCall && depth > 0)) //constructor or static function or function pointer call
                    {
                        rmem.Pop(); //remove the array dimension for "isLeftClass" or final pointer for "isFunctionPointerCall"
                        instr.op3.opdata = 0; //depth = 0
                    }
                    //push back the function arguments
                    for (int i = argSvList.Count - 1; i >= 0; i--)
                    {
                        rmem.Push(argSvList[i]);
                    }
                    //push value-not-provided default argument
                    for (int i = arglist.Count; i < procNode.argInfoList.Count; i++)
                    {
                        rmem.Push(StackUtils.BuildDefaultArgument());
                    }

                    // Push the function declaration block  
                    ProtoCore.DSASM.StackValue opblock = new ProtoCore.DSASM.StackValue();
                    opblock.optype = ProtoCore.DSASM.AddressType.BlockIndex;
                    opblock.opdata = procNode.runtimeIndex;
                    rmem.Push(opblock);

                    int dimensions = 0;
                    ProtoCore.DSASM.StackValue opdim = new ProtoCore.DSASM.StackValue();
                    opdim.optype = ProtoCore.DSASM.AddressType.ArrayDim;
                    opdim.opdata = dimensions;
                    rmem.Push(opdim);

                    //Modify the operand data
                    instr.op1.opdata = procNode.procId;
                    instr.op1.optype = AddressType.FunctionIndex;
                    instr.op2.opdata = type;

                    return true;
                }

            }
            if (!(isFunctionPointerCall && depth == 0))
            {
                rmem.Pop(); //remove the array dimension for "isLeftClass" or final pointer
            }
            return false;
        }
示例#12
0
        public static StackValue BuildChar(char ch)
        {
            StackValue value = new ProtoCore.DSASM.StackValue();
            value.optype = ProtoCore.DSASM.AddressType.Char;
            value.opdata = ProtoCore.Utils.EncodingUtils.ConvertCharacterToInt64(ch);
            value.opdata_d = value.opdata;

            MetaData mdata = new MetaData();
            mdata.type = (int)PrimitiveType.kTypeChar;
            value.metaData = mdata;
            return value;
        }
示例#13
0
        public override ProtoCore.DSASM.StackValue Execute(ProtoCore.Runtime.Context c, List <ProtoCore.DSASM.StackValue> formalParameters, ProtoCore.DSASM.StackFrame stackFrame, Core core)
        {
            ProtoCore.DSASM.Interpreter interpreter  = new ProtoCore.DSASM.Interpreter(core, true);
            ProtoCore.DSASM.Executive   oldDSASMExec = null;
            if (core.CurrentExecutive != null)
            {
                oldDSASMExec = core.CurrentExecutive.CurrentDSASMExec;
                core.CurrentExecutive.CurrentDSASMExec = interpreter.runtime;
            }

            // Assert for the block type
            activation.globs = core.DSExecutable.runtimeSymbols[core.RunningBlock].GetGlobalSize();

            // Params
            formalParameters.Reverse();
            for (int i = 0; i < formalParameters.Count; i++)
            {
                interpreter.Push(formalParameters[i]);
            }

            ProtoCore.DSASM.StackValue svThisPtr   = stackFrame.GetAt(DSASM.StackFrame.AbsoluteIndex.kThisPtr);
            ProtoCore.DSASM.StackValue svBlockDecl = stackFrame.GetAt(DSASM.StackFrame.AbsoluteIndex.kFunctionBlock);

            // Jun: Make sure we have no empty or unaligned frame data
            Validity.Assert(DSASM.StackFrame.kStackFrameSize == stackFrame.Frame.Length);

            // Setup the stack frame data
            //int thisPtr = (int)stackFrame.GetAt(DSASM.StackFrame.AbsoluteIndex.kThisPtr).opdata;
            int ci           = activation.classIndex;
            int fi           = activation.funcIndex;
            int returnAddr   = (int)stackFrame.GetAt(DSASM.StackFrame.AbsoluteIndex.kReturnAddress).opdata;
            int blockDecl    = (int)svBlockDecl.opdata;
            int blockCaller  = (int)stackFrame.GetAt(DSASM.StackFrame.AbsoluteIndex.kFunctionCallerBlock).opdata;
            int framePointer = core.Rmem.FramePointer;
            int locals       = activation.locals;


            // Update the running block to tell the execution engine which set of instruction to execute
            // TODO(Jun/Jiong): Considering store the orig block id to stack frame
            int origRunningBlock = core.RunningBlock;

            core.RunningBlock = (int)svBlockDecl.opdata;

            // Set SX register
            interpreter.runtime.SX = svBlockDecl;

            DSASM.StackFrameType callerType = (DSASM.StackFrameType)stackFrame.GetAt(DSASM.StackFrame.AbsoluteIndex.kCallerStackFrameType).opdata;

            List <ProtoCore.DSASM.StackValue> registers = new List <DSASM.StackValue>();

            ProtoCore.DSASM.StackValue svCallConvention;
            bool isDispose = procedureNode.name.Equals(ProtoCore.DSDefinitions.Kw.kw_Dispose);

            bool explicitCall = !c.IsReplicating && !c.IsImplicitCall && !isDispose;

            if (explicitCall)
            {
                svCallConvention = ProtoCore.DSASM.StackUtils.BuildNode(ProtoCore.DSASM.AddressType.CallingConvention, (long)ProtoCore.DSASM.CallingConvention.CallType.kExplicit);
            }
            else
            {
                svCallConvention = ProtoCore.DSASM.StackUtils.BuildNode(ProtoCore.DSASM.AddressType.CallingConvention, (long)ProtoCore.DSASM.CallingConvention.CallType.kImplicit);
            }
            stackFrame.SetAt(DSASM.StackFrame.AbsoluteIndex.kRegisterTX, svCallConvention);
            interpreter.runtime.TX = svCallConvention;

            // Set SX register
            stackFrame.SetAt(DSASM.StackFrame.AbsoluteIndex.kRegisterSX, svBlockDecl);
            interpreter.runtime.SX = svBlockDecl;

            // TODO Jun:
            // The stackframe carries the current set of registers
            // Determine if this can be done even for the non explicit call implementation
            registers.AddRange(stackFrame.GetRegisters());


            // Comment Jun: the depth is always 0 for a function call as we are reseting this for each function call
            // This is only incremented for every language block bounce
            int depth = (int)stackFrame.GetAt(DSASM.StackFrame.AbsoluteIndex.kStackFrameDepth).opdata;

            DSASM.StackFrameType type = (DSASM.StackFrameType)stackFrame.GetAt(DSASM.StackFrame.AbsoluteIndex.kStackFrameType).opdata;
            Validity.Assert(depth == 0);
            Validity.Assert(type == DSASM.StackFrameType.kTypeFunction);
            core.Rmem.PushStackFrame(svThisPtr, ci, fi, returnAddr, blockDecl, blockCaller, callerType, type, depth, framePointer, registers, locals);


            ProtoCore.DSASM.StackValue svRet;

            if (explicitCall)
            {
                svRet = ProtoCore.DSASM.StackUtils.BuildNode(DSASM.AddressType.ExplicitCall, activation.pc);
            }
            else
            {
                if (core.ExecMode != DSASM.InterpreterMode.kExpressionInterpreter && core.Options.IDEDebugMode)
                {
                    svRet = interpreter.Run(core.Breakpoints, core.RunningBlock, activation.pc, Language.kInvalid);
                }
                else
                {
                    svRet = interpreter.Run(core.RunningBlock, activation.pc, Language.kInvalid);
                }
                core.RunningBlock = origRunningBlock;
            }

            if (core.CurrentExecutive != null)
            {
                core.CurrentExecutive.CurrentDSASMExec = oldDSASMExec;
            }
            return(svRet); //DSASM.Mirror.ExecutionMirror.Unpack(svRet, core.heap, core);
        }
示例#14
0
 public Obj(ProtoCore.DSASM.StackValue dsasmValue)
 {
     DsasmValue = dsasmValue;
 }
示例#15
0
 /// <summary>
 /// Experimental constructor that takes in a core object
 /// </summary>
 /// <param name="sv"></param>
 public MirrorData(ProtoCore.Core core, ProtoCore.DSASM.StackValue sv)
 {
     this.core = core;
     svData    = sv;
 }
示例#16
0
 /// <summary>
 /// Experimental constructor that takes in a core object
 /// </summary>
 /// <param name="sv"></param>
 public MirrorData(ProtoCore.Core core, ProtoCore.DSASM.StackValue sv)
 {
     this.core = core;
     svData = sv;
 }