Esempio n. 1
0
        public bool Compile(List <ProtoCore.AST.AssociativeAST.AssociativeNode> astList, ProtoCore.Core core, out int blockId)
        {
            bool buildSucceeded = false;

            blockId = ProtoCore.DSASM.Constants.kInvalidIndex;
            if (astList.Count <= 0)
            {
                // Nothing to compile
                buildSucceeded = true;
            }
            else
            {
                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     = string.Empty;
                    //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();
                    context.SetData(string.Empty, new Dictionary <string, object>(), null);
                    ProtoCore.Language id = globalBlock.language;


                    ProtoCore.AST.AssociativeAST.CodeBlockNode codeblock = new ProtoCore.AST.AssociativeAST.CodeBlockNode();
                    codeblock.Body.AddRange(astList);

                    core.Compilers[id].Compile(out blockId, null, globalBlock, context, EventSink, codeblock);

                    core.BuildStatus.ReportBuildResult();

                    buildSucceeded = core.BuildStatus.BuildSucceeded;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }

            return(buildSucceeded);
        }
Esempio n. 2
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);
            blockId = -1;
            bool succeeded = false;// runner.Compile(staticContext, runnerCore, out blockId);

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

                // Update the symbol tables
                // TODO Jun: Expand to accomoadate the list of symbols
                staticContext.symbolTable = runnerCore.DSExecutable.runtimeSymbols[0];
            }
            return(succeeded);
        }
Esempio n. 3
0
        public bool Compile(string code, int currentBlockID, out int blockId)
        {
            bool buildSucceeded = false;

            blockId = ProtoCore.DSASM.Constants.kInvalidIndex;
            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.language = ProtoCore.Language.kImperative;
                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();
                context.SetData(string.Empty, null, null, currentBlockID, runtimeCore.RuntimeMemory);
                ProtoCore.Language id = globalBlock.language;

                runtimeCore.ExprInterpreterExe.iStreamCanvas = new InstructionStream(globalBlock.language, Core);

                // Save the global offset and restore after compilation
                int offsetRestore = Core.GlobOffset;
                Core.GlobOffset = runtimeCore.RuntimeMemory.Stack.Count;

                Core.Compilers[id].Compile(out blockId, null, globalBlock, context, EventSink);

                // Restore the global offset
                Core.GlobOffset = offsetRestore;

                Core.BuildStatus.ReportBuildResult();

                buildSucceeded = Core.BuildStatus.BuildSucceeded;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            return(buildSucceeded);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        public bool Compile(List<ProtoCore.AST.AssociativeAST.AssociativeNode> astList, ProtoCore.Core core, out int blockId)
        {
            bool buildSucceeded = false;

            core.ExecMode = ProtoCore.DSASM.InterpreterMode.kNormal;

            blockId = ProtoCore.DSASM.Constants.kInvalidIndex;
            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 = string.Empty;
                //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();
                context.SetData(string.Empty, new Dictionary<string, object>(), null);
                ProtoCore.Language id = globalBlock.language;

                
		        ProtoCore.AST.AssociativeAST.CodeBlockNode codeblock = new ProtoCore.AST.AssociativeAST.CodeBlockNode();
                codeblock.Body.AddRange(astList);

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

                core.BuildStatus.ReportBuildResult();

                buildSucceeded = core.BuildStatus.BuildSucceeded;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            return buildSucceeded;
        }