Esempio n. 1
0
        /// <summary>
        /// Execute the data stored in core
        /// This is the entry point of all DS code to be executed
        /// </summary>
        /// <param name="core"></param>
        /// <returns></returns>
        public ProtoCore.RuntimeCore ExecuteVM(ProtoCore.Core core)
        {
            ProtoCore.RuntimeCore runtimeCore = CreateRuntimeCore(core);
            runtimeCore.StartTimer();
            try
            {
                foreach (ProtoCore.DSASM.CodeBlock codeblock in core.CodeBlockList)
                {
                    // 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);
                    stackFrame.FramePointer = runtimeCore.RuntimeMemory.FramePointer;

                    // Comment Jun: Tell the new bounce stackframe that this is an implicit bounce
                    // Register TX is used for this.
                    StackValue svCallConvention = StackValue.BuildCallingConversion((int)ProtoCore.DSASM.CallingConvention.BounceType.Implicit);
                    stackFrame.TX = svCallConvention;

                    // Initialize the entry point interpreter
                    int locals = 0; // This is the global scope, there are no locals
                    ProtoCore.DSASM.Interpreter interpreter = new ProtoCore.DSASM.Interpreter(runtimeCore);
                    runtimeCore.CurrentExecutive.CurrentDSASMExec = interpreter.runtime;
                    runtimeCore.CurrentExecutive.CurrentDSASMExec.Bounce(codeblock.codeBlockId, codeblock.instrStream.entrypoint, stackFrame, locals);
                }
                runtimeCore.NotifyExecutionEvent(ProtoCore.ExecutionStateEventArgs.State.ExecutionEnd);
            }
            catch
            {
                runtimeCore.NotifyExecutionEvent(ProtoCore.ExecutionStateEventArgs.State.ExecutionEnd);
                throw;
            }
            return(runtimeCore);
        }
Esempio n. 2
0
        /// <summary>
        /// ExecuteLive is called by the liverunner where a persistent RuntimeCore is provided
        /// ExecuteLive assumes only a single global scope
        /// </summary>
        /// <param name="core"></param>
        /// <param name="runtimeCore"></param>
        /// <param name="runningBlock"></param>
        /// <param name="staticContext"></param>
        /// <param name="runtimeContext"></param>
        /// <returns></returns>
        public ProtoCore.RuntimeCore ExecuteLive(ProtoCore.Core core, ProtoCore.RuntimeCore runtimeCore)
        {
            try
            {
                Executable exe = runtimeCore.DSExecutable;
                Validity.Assert(exe.CodeBlocks.Count == 1);
                CodeBlock codeBlock   = runtimeCore.DSExecutable.CodeBlocks[0];
                int       codeBlockID = codeBlock.codeBlockId;

                // 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);
                stackFrame.FramePointer = runtimeCore.RuntimeMemory.FramePointer;

                // Comment Jun: Tell the new bounce stackframe that this is an implicit bounce
                // Register TX is used for this.
                StackValue svCallConvention = StackValue.BuildCallingConversion((int)ProtoCore.DSASM.CallingConvention.BounceType.Implicit);
                stackFrame.TX = svCallConvention;

                // Initialize the entry point interpreter
                int locals = 0; // This is the global scope, there are no locals
                if (runtimeCore.CurrentExecutive.CurrentDSASMExec == null)
                {
                    ProtoCore.DSASM.Interpreter interpreter = new ProtoCore.DSASM.Interpreter(runtimeCore);
                    runtimeCore.CurrentExecutive.CurrentDSASMExec = interpreter.runtime;
                }

                runtimeCore.CurrentExecutive.CurrentDSASMExec.BounceUsingExecutive(
                    runtimeCore.CurrentExecutive.CurrentDSASMExec,
                    codeBlock.codeBlockId,
                    runtimeCore.StartPC,
                    stackFrame,
                    locals);

                runtimeCore.NotifyExecutionEvent(ProtoCore.ExecutionStateEventArgs.State.ExecutionEnd);
            }
            catch
            {
                runtimeCore.NotifyExecutionEvent(ProtoCore.ExecutionStateEventArgs.State.ExecutionEnd);
                throw;
            }
            return(runtimeCore);
        }
Esempio n. 3
0
        /// <summary>
        /// Execute the data stored in core
        /// This is the entry point of all DS code to be executed
        /// </summary>
        /// <param name="core"></param>
        /// <param name="runningBlock"></param>
        /// <param name="staticContext"></param>
        /// <param name="runtimeContext"></param>
        public ProtoCore.RuntimeCore Execute(
            ProtoCore.Core core, int runningBlock, ProtoCore.CompileTime.Context staticContext, ProtoCore.Runtime.Context runtimeContext)
        {
            //========================Generate runtimecore here===============================//
            ProtoCore.RuntimeCore runtimeCore = core.__TempCoreHostForRefactoring;

            // Move these core setup to runtime core
            runtimeCore.RuntimeMemory.PushFrameForGlobals(core.GlobOffset);
            runtimeCore.RunningBlock = runningBlock;
            runtimeCore.RuntimeStatus.MessageHandler = core.BuildStatus.MessageHandler;

            try
            {
                runtimeCore.NotifyExecutionEvent(ProtoCore.ExecutionStateEventArgs.State.kExecutionBegin);
                foreach (ProtoCore.DSASM.CodeBlock codeblock in core.CodeBlockList)
                {
                    // 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);
                    stackFrame.FramePointer = runtimeCore.RuntimeMemory.FramePointer;

                    // Comment Jun: Tell the new bounce stackframe that this is an implicit bounce
                    // Register TX is used for this.
                    StackValue svCallConvention = StackValue.BuildCallingConversion((int)ProtoCore.DSASM.CallingConvention.BounceType.kImplicit);
                    stackFrame.TX = svCallConvention;

                    // Initialize the entry point interpreter
                    int locals = 0; // This is the global scope, there are no locals
                    ProtoCore.DSASM.Interpreter interpreter = new ProtoCore.DSASM.Interpreter(runtimeCore);
                    runtimeCore.CurrentExecutive.CurrentDSASMExec = interpreter.runtime;
                    runtimeCore.CurrentExecutive.CurrentDSASMExec.Bounce(codeblock.codeBlockId, codeblock.instrStream.entrypoint, runtimeContext, stackFrame, locals);
                }
                runtimeCore.NotifyExecutionEvent(ProtoCore.ExecutionStateEventArgs.State.kExecutionEnd);
            }
            catch
            {
                runtimeCore.NotifyExecutionEvent(ProtoCore.ExecutionStateEventArgs.State.kExecutionEnd);
                throw;
            }
            return(runtimeCore);
        }
Esempio n. 4
0
        /// <summary>
        /// Setup to run with customised launch options
        /// </summary>
        /// <param name="configuration"></param>
        /// <returns>Ready to run?</returns>
        ///
        private bool _PreStart(string code, Config.RunConfiguration configuration, string fileName)
        {
            this.code = code;
            if (null == core)
            {
                core = new ProtoCore.Core(new ProtoCore.Options {
                    IDEDebugMode = true
                });
                core.Compilers.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Compiler(core));
                core.Compilers.Add(ProtoCore.Language.kImperative, new ProtoImperative.Compiler(core));
            }

            runtimeCore = core.__TempCoreHostForRefactoring;
            runtimeCore.RuntimeStatus.MessageHandler = core.BuildStatus.MessageHandler;

            if (null != fileName)
            {
                core.CurrentDSFileName          = Path.GetFullPath(fileName);
                core.Options.RootModulePathName = Path.GetFullPath(fileName);
            }

            //Run the compilation process
            if (Compile(out resumeBlockID))
            {
                inited = true;

                //int blockId = ProtoCore.DSASM.Constants.kInvalidIndex;
                //core.runningBlock = blockId;

                ProtoCore.Runtime.Context context = new ProtoCore.Runtime.Context();
                runtimeCore.SetProperties(core.Options, core.DSExecutable, core.DebuggerProperties, context, core.ExprInterpreterExe);
                runtimeCore.NotifyExecutionEvent(ProtoCore.ExecutionStateEventArgs.State.kExecutionBegin);

                FirstExec();
                diList = BuildReverseIndex();
                return(true);
            }
            else
            {
                inited = false;
                return(false);
            }
        }