Beispiel #1
0
        public ExecutionMirror Execute(string code, ProtoCore.Core core, bool isTest = true)
        {
            int blockId = ProtoCore.DSASM.Constants.kInvalidIndex;

            ProtoLanguage.CompileStateTracker compileState = Compile(code, out blockId);
            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;

                Execute(core, new ProtoCore.Runtime.Context(), compileState);
                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 void Execute(string code, ProtoCore.Core core)
        {
            int blockId = ProtoCore.DSASM.Constants.kInvalidIndex;

            ProtoLanguage.CompileStateTracker compileState = Compile(code, 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;

                // Setup the initial size of the global stack
                core.Rmem.PushGlobFrame(compileState.GlobOffset);
                core.RunningBlock = blockId;

                Execute(core);
                core.Heap.Free();


                //core.GenerateExecutable();
                //core.Rmem.PushGlobFrame(core.GlobOffset);
                //core.RunningBlock = blockId;
                //Execute(core);
                //core.Heap.Free();
            }
            else
            {
                throw new ProtoCore.Exceptions.CompileErrorsOccured();
            }
        }
        private ProtoLanguage.CompileStateTracker Compile(out int blockId)
        {
            blockId = ProtoCore.DSASM.Constants.kInvalidIndex;

            compileState = ProtoScript.CompilerUtils.BuildDebuggertCompilerState();
            compileState.CurrentDSFileName = core.CurrentDSFileName;
            try
            {
                //defining the global Assoc block that wraps the entire .ds source file
                ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock();
                globalBlock.language = ProtoCore.Language.kAssociative;
                globalBlock.body     = code;
                //the wrapper block can be given a unique id to identify it as the global scope
                globalBlock.id = ProtoCore.LanguageCodeBlock.OUTERMOST_BLOCK_ID;

                //passing the global Assoc wrapper block to the compiler
                ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context();
                ProtoCore.Language            id      = globalBlock.language;



                compileState.Executives[id].Compile(compileState, out blockId, null, globalBlock, context, EventSink);

                compileState.BuildStatus.ReportBuildResult();

                int errors   = 0;
                int warnings = 0;
                compileState.compileSucceeded = compileState.BuildStatus.GetBuildResult(out errors, out warnings);


                // 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);
            }
            catch (Exception ex)
            {
                Messages.FatalCompileError fce = new Messages.FatalCompileError {
                    Message = ex.ToString()
                };

                Console.WriteLine(fce.Message);
                return(null);
            }

            return(compileState);
        }
        public ExecutionMirror Execute(string code, ProtoCore.Core core, Dictionary <string, Object> values, out ProtoLanguage.CompileStateTracker outcompileState, bool isTest = true)
        {
            //Inject the context data values from external source.
            //core.AddContextData(values);

            int blockId = ProtoCore.DSASM.Constants.kInvalidIndex;

            ProtoLanguage.CompileStateTracker compileState = outcompileState = Compile(code, core, values, out blockId);
            Validity.Assert(null != compileState);

            core.ContextDataManager = compileState.ContextDataManager;

            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;

                Execute(core, new ProtoCore.Runtime.Context(), 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);
        }
        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);
        }
        public ExecutionMirror Execute(List <ProtoCore.AST.AssociativeAST.AssociativeNode> astList, ProtoCore.Core core)
        {
            int blockId = ProtoCore.DSASM.Constants.kInvalidIndex;

            ProtoLanguage.CompileStateTracker compileState = Compile(astList, 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;

                Execute(core, new ProtoCore.Runtime.Context(), compileState);
            }
            else
            {
                throw new ProtoCore.Exceptions.CompileErrorsOccured();
            }

            if (!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);
        }
Beispiel #7
0
        private ProtoLanguage.CompileStateTracker Compile(string code, out int blockId)
        {
            staticContext.SetData(code, new Dictionary <string, object>(), graphCompiler.ExecutionFlagList);

            compileState = runner.Compile(staticContext, runnerCore, 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
                runnerCore.DSExecutable = compileState.DSExecutable;

                // Update the symbol tables
                // TODO Jun: Expand to accomoadate the list of symbols
                staticContext.symbolTable = runnerCore.DSExecutable.runtimeSymbols[0];
            }
            return(compileState);
        }
Beispiel #8
0
        private ProtoLanguage.CompileStateTracker Compile(out int blockId)
        {
            blockId = ProtoCore.DSASM.Constants.kInvalidIndex;

            compileState = ProtoScript.CompilerUtils.BuildDebuggertCompilerState();

            try
            {
                //defining the global Assoc block that wraps the entire .ds source file
                ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock();
                globalBlock.language = ProtoCore.Language.kAssociative;
                globalBlock.body = code;
                //the wrapper block can be given a unique id to identify it as the global scope
                globalBlock.id = ProtoCore.LanguageCodeBlock.OUTERMOST_BLOCK_ID;

                //passing the global Assoc wrapper block to the compiler
                ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context();
                ProtoCore.Language id = globalBlock.language;

                compileState.Executives[id].Compile(compileState, out blockId, null, globalBlock, context, EventSink);

                compileState.BuildStatus.ReportBuildResult();

                int errors = 0;
                int warnings = 0;
                compileState.compileSucceeded = compileState.BuildStatus.GetBuildResult(out errors, out warnings);

                // 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);

            }
            catch (Exception ex)
            {
                Messages.FatalCompileError fce = new Messages.FatalCompileError { Message = ex.ToString() };

                Console.WriteLine(fce.Message);
                return null;
            }

            return compileState;
        }
Beispiel #9
0
        private ProtoLanguage.CompileStateTracker Compile(string code, out int blockId)
        {
            staticContext.SetData(code, new Dictionary<string, object>(), graphCompiler.ExecutionFlagList);

            compileState = runner.Compile(staticContext, runnerCore, 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
                runnerCore.DSExecutable = compileState.DSExecutable;

                // Update the symbol tables
                // TODO Jun: Expand to accomoadate the list of symbols
                staticContext.symbolTable = runnerCore.DSExecutable.runtimeSymbols[0];
            }
            return compileState;
        }