예제 #1
0
        public ExecutionMirror Execute(ProtoCore.CompileTime.Context staticContext, ProtoCore.Runtime.Context runtimeContext, ProtoCore.Core core, bool isTest = true)
        {
            Validity.Assert(null != staticContext.SourceCode && String.Empty != staticContext.SourceCode);

            int  blockId   = ProtoCore.DSASM.Constants.kInvalidIndex;
            bool succeeded = Compile(staticContext, core, out blockId);

            if (succeeded)
            {
                core.GenerateExecutable();
                core.Rmem.PushGlobFrame(core.GlobOffset);
                core.RunningBlock = blockId;
                core.InitializeContextGlobals(staticContext.GlobalVarList);

                Validity.Assert(null != runtimeContext);
                Execute(core, runtimeContext);
                if (!isTest)
                {
                    core.Heap.Free();
                }
            }
            else
            {
                throw new ProtoCore.Exceptions.CompileErrorsOccured();
            }

            if (isTest && !core.Options.CompileToLib)
            {
                return(new ExecutionMirror(core.CurrentExecutive.CurrentDSASMExec, core));
            }

            return(null);
        }
        public ExecutionMirror Execute(ProtoCore.CompileTime.Context staticContext, ProtoCore.Runtime.Context runtimeContext, ProtoCore.Core core, bool isTest = true)
        {
            Validity.Assert(null != staticContext.SourceCode && String.Empty != staticContext.SourceCode);

            int blockId = ProtoCore.DSASM.Constants.kInvalidIndex;

            ProtoLanguage.CompileStateTracker compileState = Compile(staticContext, core, out blockId);
            Validity.Assert(null != compileState);
            if (compileState.compileSucceeded)
            {
                // This is the boundary between compilestate and runtime core
                // Generate the executable
                compileState.GenerateExecutable();

                // Get the executable from the compileState
                core.DSExecutable = compileState.DSExecutable;

                core.Rmem.PushGlobFrame(compileState.GlobOffset);
                core.RunningBlock = blockId;
                core.InitializeContextGlobals(staticContext.GlobalVarList);

                Validity.Assert(null != runtimeContext);
                Execute(core, runtimeContext, compileState);
                if (!isTest)
                {
                    core.Heap.Free();
                }
            }
            else
            {
                throw new ProtoCore.Exceptions.CompileErrorsOccured();
            }

            if (isTest && !core.Options.CompileToLib)
            {
                return(new ExecutionMirror(core.CurrentExecutive.CurrentDSASMExec, core));
            }

            // Save the Callsite state for this execution
            if (core.EnableCallsiteExecutionState)
            {
                ProtoCore.CallsiteExecutionState.SaveState(core.csExecutionState);
            }

            return(null);
        }