Exemplo n.º 1
0
        private ExecutionMirror Execute(string code, ProtoCore.Core core, bool isTest = true)
        {
            int  blockId   = ProtoCore.DSASM.Constants.kInvalidIndex;
            bool succeeded = Compile(code, core, out blockId);

            if (succeeded)
            {
                core.GenerateExecutable();
                core.Rmem.PushGlobFrame(core.GlobOffset);
                core.RunningBlock = blockId;
                Execute(core);

                if (!isTest)
                {
                    core.Heap.Free();
                }


                if (isTest && !core.Options.CompileToLib)
                {
                    return(new ExecutionMirror(core.CurrentExecutive.CurrentDSASMExec, core));
                }
                else
                {
                    return(null);
                }
            }
            //else
            //  throw new ProtoCore.Exceptions.CompileErrorsOccured();

            //if (isTest && !core.Options.CompileToLib)
            //    return new ExecutionMirror(core.CurrentExecutive.CurrentDSASMExec, core);
            //else
            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Compile and execute the given sourcecode
        /// </summary>
        /// <param name="code"></param>
        /// <param name="core"></param>
        /// <param name="isTest"></param>
        /// <returns></returns>
        public ExecutionMirror Execute(string sourcecode, ProtoCore.Core core, bool isTest = true)
        {
            int  blockId   = ProtoCore.DSASM.Constants.kInvalidIndex;
            bool succeeded = Compile(sourcecode, core, out blockId);

            if (succeeded)
            {
                core.GenerateExecutable();
                try
                {
                    Execute(core, blockId, new ProtoCore.CompileTime.Context(), new ProtoCore.Runtime.Context());
                }
                catch (ProtoCore.Exceptions.ExecutionCancelledException e)
                {
                    Console.WriteLine("The execution has been cancelled!");
                }

                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);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Compile and execute the source that is stored in the static context
        /// </summary>
        /// <param name="staticContext"></param>
        /// <param name="runtimeContext"></param>
        /// <param name="core"></param>
        /// <param name="isTest"></param>
        /// <returns></returns>
        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);

            core.AddContextData(staticContext.GlobalVarList);

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

            if (succeeded)
            {
                core.GenerateExecutable();
                Validity.Assert(null != runtimeContext);
                Execute(core, blockId, staticContext, 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);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Compile and execute the given list of ASTs
        /// </summary>
        /// <param name="astList"></param>
        /// <param name="core"></param>
        /// <param name="isTest"></param>
        /// <returns></returns>
        public ExecutionMirror Execute(List <ProtoCore.AST.AssociativeAST.AssociativeNode> astList, ProtoCore.Core core, bool isTest = true)
        {
            int  blockId   = ProtoCore.DSASM.Constants.kInvalidIndex;
            bool succeeded = Compile(astList, core, out blockId);

            if (succeeded)
            {
                core.GenerateExecutable();
                Execute(core, blockId, new ProtoCore.CompileTime.Context(), new ProtoCore.Runtime.Context());
                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);
        }
Exemplo n.º 5
0
        public ExecutionMirror Execute(string code, ProtoCore.Core core, Dictionary <string, Object> values, bool isTest = true)
        {
            //Inject the context data values from external source.
            core.AddContextData(values);
            int  blockId   = ProtoCore.DSASM.Constants.kInvalidIndex;
            bool succeeded = Compile(code, core, out blockId);

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

                Execute(core, new ProtoCore.Runtime.Context());

                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);
        }
Exemplo n.º 6
0
        public ExecutionMirror Execute(string code, ProtoCore.Core core, bool isTest = true)
        {
            int  blockId   = ProtoCore.DSASM.Constants.kInvalidIndex;
            bool succeeded = Compile(code, core, out blockId);

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

                Execute(core, new ProtoCore.Runtime.Context());
                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);
        }
Exemplo n.º 7
0
        /// <summary>
        /// The public method to compile DS code and stores the executable in core
        /// </summary>
        /// <param name="sourcecode"></param>
        /// <param name="compileCore"></param>
        /// <returns></returns>
        public bool CompileAndGenerateExe(string sourcecode, ProtoCore.Core compileCore, ProtoCore.CompileTime.Context context)
        {
            bool succeeded = Compile(sourcecode, compileCore, context);

            if (succeeded)
            {
                compileCore.GenerateExecutable();
            }
            return(succeeded);
        }
Exemplo n.º 8
0
        /// <summary>
        /// The public method to compile DS code
        /// </summary>
        /// <param name="sourcecode"></param>
        /// <param name="compileCore"></param>
        /// <param name="dsExecutable"></param>
        /// <returns></returns>
        public bool CompileMe(string sourcecode, ProtoCore.Core compileCore, out Executable dsExecutable)
        {
            int  blockID   = 0;
            bool succeeded = Compile(sourcecode, compileCore, out blockID);

            compileCore.GenerateExecutable();
            dsExecutable = compileCore.DSExecutable;

            return(succeeded);
        }
Exemplo n.º 9
0
        /// <summary>
        /// The public method to compile DS AST and stores the executable in core
        /// </summary>
        /// <param name="astList"></param>
        /// <param name="compileCore"></param>
        /// <returns></returns>
        public bool CompileAndGenerateExe(
            List <ProtoCore.AST.AssociativeAST.AssociativeNode> astList,
            ProtoCore.Core compileCore,
            ProtoCore.CompileTime.Context context)
        {
            bool succeeded = Compile(astList, compileCore, context);

            if (succeeded)
            {
                compileCore.GenerateExecutable();
            }
            return(succeeded);
        }
Exemplo n.º 10
0
        public void Execute(string code, ProtoCore.Core core)
        {
            int  blockId   = ProtoCore.DSASM.Constants.kInvalidIndex;
            bool succeeded = Compile(code, core, out blockId);

            if (succeeded)
            {
                core.GenerateExecutable();
                core.Rmem.PushGlobFrame(core.GlobOffset);
                core.RunningBlock = blockId;
                Execute(core);
                core.Heap.Free();
            }
            else
            {
                throw new ProtoCore.Exceptions.CompileErrorsOccured();
            }
        }
Exemplo n.º 11
0
        private bool Compile(string code, out int blockId)
        {
            //ProtoCore.CompileTime.Context staticContext = new ProtoCore.CompileTime.Context(code, new Dictionary<string, object>(), graphCompiler.ExecutionFlagList);
            staticContext.SetData(code, new Dictionary <string, object>(), graphCompiler.ExecutionFlagList);

            bool succeeded = runner.Compile(staticContext, runnerCore, out blockId);

            if (succeeded)
            {
                // Regenerate the DS executable
                runnerCore.GenerateExecutable();

                // Update the symbol tables
                // TODO Jun: Expand to accomoadate the list of symbols
                staticContext.symbolTable = runnerCore.DSExecutable.runtimeSymbols[0];
            }
            return(succeeded);
        }
Exemplo n.º 12
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));
            }

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

            return(null);
        }