Exemplo n.º 1
0
        internal static ProtoCore.Core TestRunnerRunOnly(string code)
        {
            ProtoCore.Core core;
            ProtoScript.Runners.ProtoScriptTestRunner fsr = new ProtoScriptTestRunner();


            ProtoScript.Config.RunConfiguration runnerConfig;
            string testPath = @"..\..\..\Scripts\Debugger\";

            // Specify some of the requirements of IDE.
            var options = new ProtoCore.Options();

            options.ExecutionMode       = ProtoCore.ExecutionMode.Serial;
            options.SuppressBuildOutput = false;

            core = new ProtoCore.Core(options);
            core.Executives.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Executive(core));
            core.Executives.Add(ProtoCore.Language.kImperative, new ProtoImperative.Executive(core));

            runnerConfig             = new ProtoScript.Config.RunConfiguration();
            runnerConfig.IsParrallel = false;
            fsr = new ProtoScriptTestRunner();

            DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());
            CLRModuleType.ClearTypes();

            //Run

            ProtoLanguage.CompileStateTracker compileState = null;
            fsr.Execute(code, core, out compileState);

            return(core);
        }
Exemplo n.º 2
0
 /// <summary>
 /// This consutructor is for instantiating a Runtime mirror object where we already have the mirrorData
 /// </summary>
 /// <param name="mirrorData"></param>
 /// <param name="core"></param>
 public RuntimeMirror(MirrorData mirrorData, ProtoCore.Core core, ProtoLanguage.CompileStateTracker compileState = null) : base(core, compileState)
 {
     Validity.Assert(this.core != null);
     TargetExecutive     = core.CurrentExecutive.CurrentDSASMExec;
     deprecateThisMirror = new DSASM.Mirror.ExecutionMirror(TargetExecutive, core);
     this.mirrorData     = mirrorData;
 }
Exemplo n.º 3
0
        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();
            }
        }
Exemplo n.º 4
0
        public CoreCodeGen(ProtoLanguage.CompileStateTracker compileState, ProtoCore.DSASM.CodeBlock parentBlock = null)
        {
            Debug.Assert(compileState != null);
            this.compileState = compileState;
            argOffset         = 0;
            globalClassIndex  = compileState.ClassIndex;

            if (null == CoreCodeGen.CodeRangeTable)
            {
                CoreCodeGen.CodeRangeTable = new CodeRangeTable();
            }
            if (null == CoreCodeGen.IdentLocation)
            {
                CoreCodeGen.IdentLocation = new IdentLocationTable();
            }
            if (null == CoreCodeGen.ImportTable)
            {
                CoreCodeGen.ImportTable = new ImportTable();
            }

            context  = new ProtoCore.CompileTime.Context();
            opKwData = new ProtoCore.DSASM.OpKeywordData();

            targetLangBlock = ProtoCore.DSASM.Constants.kInvalidIndex;

            enforceTypeCheck = true;

            localProcedure  = compileState.ProcNode;
            globalProcIndex = null != localProcedure ? localProcedure.procId : ProtoCore.DSASM.Constants.kGlobalScope;

            tryLevel = 0;
        }
Exemplo n.º 5
0
        public ProtoLanguage.CompileStateTracker Compile(string code, out int blockId)
        {
            ProtoLanguage.CompileStateTracker compileState = ProtoScript.CompilerUtils.BuildDefaultCompilerState();

            blockId = ProtoCore.DSASM.Constants.kInvalidIndex;
            try
            {
                System.IO.MemoryStream     sourceMemStream = new System.IO.MemoryStream(System.Text.Encoding.Default.GetBytes(code));
                ProtoScript.GenerateScript gs = new ProtoScript.GenerateScript(compileState);

                compileState.Script = gs.preParseFromStream(sourceMemStream);

                foreach (ProtoCore.LanguageCodeBlock codeblock in compileState.Script.codeblockList)
                {
                    ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context();
                    ProtoCore.Language            id      = codeblock.language;

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

                compileState.BuildStatus.ReportBuildResult();

                int errors   = 0;
                int warnings = 0;
                compileState.compileSucceeded = compileState.BuildStatus.GetBuildResult(out errors, out warnings);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            return(compileState);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
            public ProtoCore.Mirror.RuntimeMirror LookupName(string name, int blockID)
            {
                // TODO Jun: The expression interpreter must be integrated into the mirror
                core.Rmem.PushConstructBlockId(blockID);
                core.DebugProps.CurrentBlockId = blockID;
                ProtoScript.Runners.ExpressionInterpreterRunner watchRunner = new ExpressionInterpreterRunner(core, null);

                List <ProtoCore.Core.CodeBlockCompilationSnapshot> snapShots = null;

                if (core.Options.IsDeltaExecution)
                {
                    snapShots = ProtoCore.Core.CodeBlockCompilationSnapshot.CaptureCoreCompileState(core);
                }
                ProtoCore.DSASM.Mirror.ExecutionMirror mirror = watchRunner.Execute(name);
                if (core.Options.IsDeltaExecution && snapShots != null)
                {
                    core.ResetDeltaCompileFromSnapshot(snapShots);
                }
                ProtoCore.Lang.Obj objExecVal = mirror.GetWatchValue();

                ProtoLanguage.CompileStateTracker compileState = GraphToDSCompiler.GraphUtilities.GetCompilationState();

                ProtoCore.Mirror.RuntimeMirror runtimeMirror = new ProtoCore.Mirror.RuntimeMirror(new ProtoCore.Mirror.MirrorData(core, objExecVal.DsasmValue), core, compileState);
                Validity.Assert(runtimeMirror != null);

                return(runtimeMirror);
            }
Exemplo n.º 8
0
        public static void TestMinFac()
        {
            Assert.Ignore("Testing old C++ FFI. Ignored");

            String code =
                @"[Associative] 
             { 
               external (""factorial"") def factorial : int (num4 : int); 
               a = factorial(4); 
             }
            ";


            ProtoScript.Runners.ProtoScriptTestRunner fsr = new ProtoScript.Runners.ProtoScriptTestRunner();
            ProtoCore.Core core = new ProtoCore.Core(new ProtoCore.Options());
            core.Executives.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Executive(core));
            core.Executives.Add(ProtoCore.Language.kImperative, new ProtoImperative.Executive(core));

            ProtoLanguage.CompileStateTracker compileState = null;
            ExecutionMirror mirror = fsr.Execute(code, core, out compileState);

            Obj o = mirror.GetValue("a");

            Assert.IsTrue((Int64)o.Payload == 24);
        }
Exemplo n.º 9
0
        public ProtoLanguage.CompileStateTracker Compile(string code, out int blockId)
        {
            ProtoLanguage.CompileStateTracker compileState = ProtoScript.CompilerUtils.BuildDefaultCompilerState();

            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     = 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);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            return(compileState);
        }
Exemplo n.º 10
0
        public void Execute(ProtoCore.Core core, ProtoCore.Runtime.Context context, ProtoLanguage.CompileStateTracker compileState)
        {
            try
            {
                compileState.NotifyExecutionEvent(ProtoCore.ExecutionStateEventArgs.State.kExecutionBegin);
                foreach (ProtoCore.DSASM.CodeBlock codeblock in core.DSExecutable.CodeBlockList)
                {
                    int locals = 0;


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

                    // Comment Jun: Tell the new bounce stackframe that this is an implicit bounce
                    // Register TX is used for this.
                    ProtoCore.DSASM.StackValue svCallConvention = ProtoCore.DSASM.StackUtils.BuildNode(ProtoCore.DSASM.AddressType.CallingConvention, (long)ProtoCore.DSASM.CallingConvention.BounceType.kImplicit);
                    stackFrame.SetAt(ProtoCore.DSASM.StackFrame.AbsoluteIndex.kRegisterTX, svCallConvention);

                    core.Bounce(codeblock.codeBlockId, codeblock.instrStream.entrypoint, context, stackFrame, locals, EventSink);
                }
                core.NotifyExecutionEvent(ProtoCore.ExecutionStateEventArgs.State.kExecutionEnd);
            }
            catch
            {
                core.NotifyExecutionEvent(ProtoCore.ExecutionStateEventArgs.State.kExecutionEnd);
                throw;
            }
        }
        public ExecutionMirror LoadAndExecute(string filename, ProtoCore.Core core, bool isTest = true)
        {
            System.IO.StreamReader reader = null;
            try
            {
                reader = new System.IO.StreamReader(filename, Encoding.UTF8, true);
            }
            catch (System.IO.IOException)
            {
                throw new FatalError("Cannot open file " + filename);
            }

            string strSource = reader.ReadToEnd();

            reader.Dispose();
            //Start the timer
            core.StartTimer();

            core.Options.RootModulePathName = ProtoCore.Utils.FileUtils.GetFullPathName(filename);
            core.CurrentDSFileName          = core.Options.RootModulePathName;

            ProtoLanguage.CompileStateTracker compileState = null;
            Execute(strSource, core, out compileState);

            if (isTest && !core.Options.CompileToLib)
            {
                return(new ExecutionMirror(core.CurrentExecutive.CurrentDSASMExec, core));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 12
0
        public override bool Compile(ProtoLanguage.CompileStateTracker compileState, out int blockId, ProtoCore.DSASM.CodeBlock parentBlock, ProtoCore.LanguageCodeBlock langBlock, ProtoCore.CompileTime.Context callContext, ProtoCore.DebugServices.EventSink sink, ProtoCore.AST.Node codeBlockNode, ProtoCore.AssociativeGraph.GraphNode graphNode = null)
        {
            Debug.Assert(langBlock != null);
            blockId = ProtoCore.DSASM.Constants.kInvalidIndex;

            bool buildSucceeded      = false;
            bool isLanguageSignValid = isLanguageSignValid = compileState.Langverify.Verify(langBlock);

            if (isLanguageSignValid)
            {
                try
                {
                    ProtoImperative.CodeGen codegen = new ProtoImperative.CodeGen(compileState, parentBlock);

                    codegen.context             = callContext;
                    codegen.codeBlock.EventSink = sink;
                    blockId = codegen.Emit(codeBlockNode as ProtoCore.AST.ImperativeAST.CodeBlockNode, graphNode);
                }
                catch (ProtoCore.BuildHaltException e)
                {
#if DEBUG
                    //core.BuildStatus.LogSemanticError(e.errorMsg);
#endif
                }

                int errors   = 0;
                int warnings = 0;
                buildSucceeded = compileState.BuildStatus.GetBuildResult(out errors, out warnings);
            }
            return(buildSucceeded);
        }
Exemplo n.º 13
0
 private static ProtoLanguage.CompileStateTracker BuildCompilerState(ProtoLanguage.CompileOptions options)
 {
     ProtoLanguage.CompileStateTracker compileState = new ProtoLanguage.CompileStateTracker(options);
     compileState.Executives.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Executive());
     compileState.Executives.Add(ProtoCore.Language.kImperative, new ProtoImperative.Executive());
     return(compileState);
 }
Exemplo n.º 14
0
        public CoreCodeGen(ProtoLanguage.CompileStateTracker compileState, ProtoCore.DSASM.CodeBlock parentBlock = null)
        {
            Debug.Assert(compileState != null);
            this.compileState = compileState;
            argOffset = 0;
            globalClassIndex = compileState.ClassIndex;

            if (null == CoreCodeGen.CodeRangeTable)
                CoreCodeGen.CodeRangeTable = new CodeRangeTable();
            if (null == CoreCodeGen.IdentLocation)
                CoreCodeGen.IdentLocation = new IdentLocationTable();
            if (null == CoreCodeGen.ImportTable)
                CoreCodeGen.ImportTable = new ImportTable();

            context = new ProtoCore.CompileTime.Context();

            targetLangBlock = ProtoCore.DSASM.Constants.kInvalidIndex;

            enforceTypeCheck = true;

            localProcedure = compileState.ProcNode;
            globalProcIndex = null != localProcedure ? localProcedure.procId : ProtoCore.DSASM.Constants.kGlobalScope;

            tryLevel = 0;
        }
Exemplo n.º 15
0
        private static void InsertDotMemVarMethod(ProtoLanguage.CompileStateTracker compileState, ProtoCore.AST.Node root)
        {
            ProtoCore.AST.AssociativeAST.FunctionDefinitionNode funcDefNode = new ProtoCore.AST.AssociativeAST.FunctionDefinitionNode();
            funcDefNode.access     = ProtoCore.DSASM.AccessSpecifier.kPublic;
            funcDefNode.Name       = ProtoCore.DSASM.Constants.kDotArgMethodName;
            funcDefNode.ReturnType = new ProtoCore.Type()
            {
                Name = compileState.TypeSystem.GetType((int)PrimitiveType.kTypeVar), UID = (int)PrimitiveType.kTypeVar
            };
            ProtoCore.AST.AssociativeAST.ArgumentSignatureNode args = new ProtoCore.AST.AssociativeAST.ArgumentSignatureNode();
            args.AddArgument(new ProtoCore.AST.AssociativeAST.VarDeclNode()
            {
                memregion    = ProtoCore.DSASM.MemoryRegion.kMemStack,
                access       = ProtoCore.DSASM.AccessSpecifier.kPublic,
                NameNode     = BuildAssocIdentifier(compileState, ProtoCore.DSASM.Constants.kLHS),
                ArgumentType = new ProtoCore.Type {
                    Name = compileState.TypeSystem.GetType((int)PrimitiveType.kTypeVar), UID = (int)PrimitiveType.kTypeVar
                }
            });
            args.AddArgument(new ProtoCore.AST.AssociativeAST.VarDeclNode()
            {
                memregion    = ProtoCore.DSASM.MemoryRegion.kMemStack,
                access       = ProtoCore.DSASM.AccessSpecifier.kPublic,
                NameNode     = BuildAssocIdentifier(compileState, ProtoCore.DSASM.Constants.kRHS),
                ArgumentType = new ProtoCore.Type {
                    Name = compileState.TypeSystem.GetType((int)PrimitiveType.kTypeInt), UID = (int)PrimitiveType.kTypeInt
                }
            });
            args.AddArgument(new ProtoCore.AST.AssociativeAST.VarDeclNode()
            {
                memregion    = ProtoCore.DSASM.MemoryRegion.kMemStack,
                access       = ProtoCore.DSASM.AccessSpecifier.kPublic,
                NameNode     = BuildAssocIdentifier(compileState, "%rhsDimExprList"),
                ArgumentType = new ProtoCore.Type {
                    Name = compileState.TypeSystem.GetType((int)PrimitiveType.kTypeInt), UID = (int)PrimitiveType.kTypeInt, IsIndexable = true, rank = 1
                }
            });
            args.AddArgument(new ProtoCore.AST.AssociativeAST.VarDeclNode()
            {
                memregion    = ProtoCore.DSASM.MemoryRegion.kMemStack,
                access       = ProtoCore.DSASM.AccessSpecifier.kPublic,
                NameNode     = BuildAssocIdentifier(compileState, "%rhsDim"),
                ArgumentType = new ProtoCore.Type {
                    Name = compileState.TypeSystem.GetType((int)PrimitiveType.kTypeInt), UID = (int)PrimitiveType.kTypeInt
                }
            });
            funcDefNode.Singnature = args;

            ProtoCore.AST.AssociativeAST.CodeBlockNode  body    = new ProtoCore.AST.AssociativeAST.CodeBlockNode();
            ProtoCore.AST.AssociativeAST.IdentifierNode _return = BuildAssocIdentifier(compileState, ProtoCore.DSDefinitions.Kw.kw_return, ProtoCore.PrimitiveType.kTypeReturn);

            ProtoCore.AST.AssociativeAST.DotFunctionBodyNode dotNode = new ProtoCore.AST.AssociativeAST.DotFunctionBodyNode(args.Arguments[0].NameNode, args.Arguments[1].NameNode, args.Arguments[2].NameNode, args.Arguments[3].NameNode);
            body.Body.Add(new ProtoCore.AST.AssociativeAST.BinaryExpressionNode()
            {
                LeftNode = _return, Optr = ProtoCore.DSASM.Operator.assign, RightNode = dotNode
            });
            funcDefNode.FunctionBody = body;
            (root as ProtoCore.AST.AssociativeAST.CodeBlockNode).Body.Add(funcDefNode);
        }
Exemplo n.º 16
0
 public InstructionStream(ProtoCore.Language langId, ProtoLanguage.CompileStateTracker compileState)
 {
     language        = langId;
     entrypoint      = Constants.kInvalidIndex;
     instrList       = new List <Instruction>();
     dependencyGraph = new ProtoCore.AssociativeGraph.DependencyGraph(compileState);
     xUpdateList     = new List <AssociativeGraph.UpdateNodeRef>();
 }
Exemplo n.º 17
0
 internal ClassMirror(ProtoLanguage.CompileStateTracker compileState, ProtoCore.DSASM.ClassNode classNode, LibraryMirror libraryMirror)
 //: base(compileState)
 {
     this.compileState  = compileState;
     ClassName          = classNode.name;
     this.libraryMirror = libraryMirror;
     this.classNode     = classNode;
 }
        // public static readonly string kInstanceVarName = "__instance";

        public ImportModuleHandler(ProtoLanguage.CompileStateTracker compileState)
        {
            this.compileState = compileState;
            if (compileState.Options.RootModulePathName != null)
            {
                mModuleTable[compileState.Options.RootModulePathName] = null;
            }
        }
        public ExpressionInterpreterRunner(ProtoCore.Core core, ProtoLanguage.CompileStateTracker compileState)
        {
            Core = core;
            core.ExecMode = ProtoCore.DSASM.InterpreterMode.kExpressionInterpreter;

            this.compileState = compileState;
            compileState.ExecMode = ProtoCore.DSASM.InterpreterMode.kExpressionInterpreter; ;
        }
        public ExpressionInterpreterRunner(ProtoCore.Core core, ProtoLanguage.CompileStateTracker compileState = null)
        {
            Core          = core;
            core.ExecMode = ProtoCore.DSASM.InterpreterMode.kExpressionInterpreter;

            this.compileState     = compileState;
            compileState.ExecMode = ProtoCore.DSASM.InterpreterMode.kExpressionInterpreter;;
        }
Exemplo n.º 21
0
 public void TestScript(string scriptCode)
 {
     ProtoCore.Core core = new ProtoCore.Core(new ProtoCore.Options());
     core.Executives.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Executive(core));
     core.Executives.Add(ProtoCore.Language.kImperative, new ProtoImperative.Executive(core));
     ProtoScript.Runners.ProtoScriptTestRunner fsr          = new ProtoScript.Runners.ProtoScriptTestRunner();
     ProtoLanguage.CompileStateTracker         compileState = null;
     fsr.Execute(scriptCode, core, out compileState);
 }
Exemplo n.º 22
0
        public static string GetSSATemp(ProtoLanguage.CompileStateTracker compileState)
        {
            // Jun Comment: The current convention for auto generated SSA variables begin with '%'
            // This ensures that the variables is compiler generated as the '%' symbol cannot be used as an identifier and will fail compilation
            string SSATemp = ProtoCore.DSASM.Constants.kSSATempPrefix + compileState.SSASubscript.ToString();

            ++compileState.SSASubscript;
            return(SSATemp);
        }
Exemplo n.º 23
0
        public static bool RunAndCompareNoAssert(string scriptFile)
        {
            Dictionary <int, List <string> > map = new Dictionary <int, List <string> >();
            String       includePath             = Path.GetFullPath(scriptFile);
            StreamReader file = new StreamReader(scriptFile);

            WatchTestFx.GeneratePrintStatements(file, ref map);
            file = new StreamReader(scriptFile);
            String code = file.ReadToEnd();

            file.Close();
            InjectionExecutive.ExpressionMap.Clear();
            ExecutionMirror mirror;

            ProtoLanguage.CompileStateTracker compileState = null;
            Core core = TestRunnerRunOnly(includePath, code, map, "ManagedAsmGeometry.dll", "ManagedAsmPersistentManager.dll", out mirror, out compileState);

            //XML Result
            Dictionary <Expression, List <string> > expressionValues = InjectionExecutive.ExpressionMap;
            string xmlFile       = Path.GetFileName(Path.ChangeExtension(scriptFile, ".xml"));
            string baseXmlFile   = Path.Combine(BaseDir, xmlFile);
            string outputXmlFile = Path.Combine(ScriptDir, xmlFile);

            DumpDictionaryAsXml(expressionValues, outputXmlFile);

            //Log
            string           logFile       = Path.GetFileName(Path.ChangeExtension(scriptFile, ".log"));
            string           baseLogFile   = Path.Combine(BaseDir, logFile);
            string           outputLogFile = Path.Combine(ScriptDir, logFile);
            TextOutputStream tStream       = compileState.BuildStatus.MessageHandler as TextOutputStream;
            StreamWriter     osw           = new StreamWriter(outputLogFile);

            osw.Write(tStream.ToString());
            if (null != mirror)
            {
                osw.Write(mirror.GetCoreDump());
            }
            osw.Close();

            //Compare XML
            StringBuilder msg = new StringBuilder();

            if (!CompareXml(outputXmlFile, baseXmlFile, msg))
            {
                return(false);
            }

            //Compare Log
            if (!CompareLog(outputLogFile, baseLogFile))
            {
                return(false);
            }

            //sw.Close();

            return(true);
        }
Exemplo n.º 24
0
        public static ContextDataManager GetInstance(ProtoLanguage.CompileStateTracker compileState)
        {
            if (compileState.ContextDataManager != null)
            {
                return(compileState.ContextDataManager);
            }

            compileState.ContextDataManager = new ContextDataManager(compileState);
            return(compileState.ContextDataManager);
        }
Exemplo n.º 25
0
        private static void InsertInlineConditionOperationMethod(ProtoLanguage.CompileStateTracker compileState, ProtoCore.AST.Node root, PrimitiveType condition, PrimitiveType r)
        {
            ProtoCore.AST.AssociativeAST.FunctionDefinitionNode funcDefNode = new ProtoCore.AST.AssociativeAST.FunctionDefinitionNode();
            funcDefNode.access     = ProtoCore.DSASM.AccessSpecifier.kPublic;
            funcDefNode.Name       = ProtoCore.DSASM.Constants.kInlineCondition;
            funcDefNode.ReturnType = new ProtoCore.Type()
            {
                Name = compileState.TypeSystem.GetType((int)r), UID = (int)r
            };
            ProtoCore.AST.AssociativeAST.ArgumentSignatureNode args = new ProtoCore.AST.AssociativeAST.ArgumentSignatureNode();
            args.AddArgument(new ProtoCore.AST.AssociativeAST.VarDeclNode()
            {
                memregion    = ProtoCore.DSASM.MemoryRegion.kMemStack,
                access       = ProtoCore.DSASM.AccessSpecifier.kPublic,
                NameNode     = BuildAssocIdentifier(compileState, "%condition"),
                ArgumentType = new ProtoCore.Type {
                    Name = compileState.TypeSystem.GetType((int)condition), UID = (int)condition
                }
            });
            args.AddArgument(new ProtoCore.AST.AssociativeAST.VarDeclNode()
            {
                memregion    = ProtoCore.DSASM.MemoryRegion.kMemStack,
                access       = ProtoCore.DSASM.AccessSpecifier.kPublic,
                NameNode     = BuildAssocIdentifier(compileState, "%trueExp"),
                ArgumentType = new ProtoCore.Type {
                    Name = compileState.TypeSystem.GetType((int)r), UID = (int)r
                }
            });
            args.AddArgument(new ProtoCore.AST.AssociativeAST.VarDeclNode()
            {
                memregion    = ProtoCore.DSASM.MemoryRegion.kMemStack,
                access       = ProtoCore.DSASM.AccessSpecifier.kPublic,
                NameNode     = BuildAssocIdentifier(compileState, "%falseExp"),
                ArgumentType = new ProtoCore.Type {
                    Name = compileState.TypeSystem.GetType((int)r), UID = (int)r
                }
            });
            funcDefNode.Singnature = args;

            ProtoCore.AST.AssociativeAST.CodeBlockNode  body    = new ProtoCore.AST.AssociativeAST.CodeBlockNode();
            ProtoCore.AST.AssociativeAST.IdentifierNode _return = BuildAssocIdentifier(compileState, ProtoCore.DSDefinitions.Kw.kw_return, ProtoCore.PrimitiveType.kTypeReturn);
            ProtoCore.AST.AssociativeAST.IdentifierNode con     = BuildAssocIdentifier(compileState, "%condition");
            ProtoCore.AST.AssociativeAST.IdentifierNode t       = BuildAssocIdentifier(compileState, "%trueExp");
            ProtoCore.AST.AssociativeAST.IdentifierNode f       = BuildAssocIdentifier(compileState, "%falseExp");

            body.Body.Add(new ProtoCore.AST.AssociativeAST.BinaryExpressionNode()
            {
                LeftNode = _return, Optr = Operator.assign, RightNode = new ProtoCore.AST.AssociativeAST.InlineConditionalNode()
                {
                    ConditionExpression = con, TrueExpression = t, FalseExpression = f
                }
            });
            funcDefNode.FunctionBody = body;
            (root as ProtoCore.AST.AssociativeAST.CodeBlockNode).Body.Add(funcDefNode);
        }
Exemplo n.º 26
0
 public static ProtoLanguage.CompileStateTracker BuildDebuggertCompilerState(Dictionary <string, Object> context = null)
 {
     ProtoLanguage.CompileOptions options = new ProtoLanguage.CompileOptions();
     options.IDEDebugMode = true;
     ProtoLanguage.CompileStateTracker compileState = BuildCompilerState(options);
     if (null != context)
     {
         compileState.AddContextData(context);
     }
     return(compileState);
 }
Exemplo n.º 27
0
 public static ProtoLanguage.CompileStateTracker BuildLiveRunnerCompilerState(Dictionary <string, Object> context = null)
 {
     ProtoLanguage.CompileOptions options = new ProtoLanguage.CompileOptions();
     options.IsDeltaExecution = true;
     ProtoLanguage.CompileStateTracker compileState = BuildCompilerState(options);
     if (null != context)
     {
         compileState.AddContextData(context);
     }
     return(compileState);
 }
Exemplo n.º 28
0
 private static void InsertBuiltInMethods(ProtoLanguage.CompileStateTracker compileState, ProtoCore.AST.Node root, bool builtinMethodsLoaded)
 {
     if (!builtinMethodsLoaded)
     {
         ProtoCore.Lang.BuiltInMethods builtInMethods = new Lang.BuiltInMethods(compileState);
         foreach (ProtoCore.Lang.BuiltInMethods.BuiltInMethod method in builtInMethods.Methods)
         {
             (root as ProtoCore.AST.AssociativeAST.CodeBlockNode).Body.Add(GenerateBuiltInMethodSignatureNode(method));
         }
     }
 }
Exemplo n.º 29
0
            public LibraryMirror(ProtoLanguage.CompileStateTracker compileState, string libName, IList <ProtoCore.DSASM.ClassNode> classNodes) : base(compileState)
            {
                LibraryName = libName;

                classMirrors = new List <ClassMirror>();
                foreach (ProtoCore.DSASM.ClassNode cnode in classNodes)
                {
                    ClassMirror classMirror = new ClassMirror(compileState, cnode, this);
                    classMirrors.Add(classMirror);
                }
            }
        public bool RegisterExtensionApplicationType(ProtoLanguage.CompileStateTracker compileState, SysType type)
        {
            if (!typeof(IExtensionApplication).IsAssignableFrom(type))
            {
                return(false);
            }

            FFIExecutionSession session = GetSession(compileState, true);

            session.AddExtensionAppType(type);
            return(true);
        }
Exemplo n.º 31
0
            //public ClassMirror()
            //{
            //}

            public ClassMirror(ProtoCore.Type type, ProtoLanguage.CompileStateTracker compileState)
            {
                if (core != null)
                {
                    ClassName = type.Name;
                    if (classNode == null)
                    {
                        ProtoCore.DSASM.ClassTable classTable = core.DSExecutable.classTable;
                        classNode = classTable.ClassNodes[type.UID];
                    }
                    libraryMirror = new LibraryMirror(classNode.ExternLib, compileState);
                }
            }
Exemplo n.º 32
0
        internal void TestRunnerRunOnly(string includePath, string code, Dictionary <int, List <string> > map /*, string executionLogFilePath*/)
        {
            ProtoScript.Runners.ProtoScriptTestRunner fsr = new ProtoScriptTestRunner();


            ProtoScript.Config.RunConfiguration runnerConfig;

            // Specify some of the requirements of IDE.

            core.Options.ExecutionMode       = ProtoCore.ExecutionMode.Serial;
            core.Options.SuppressBuildOutput = false;
            core.Options.WatchTestMode       = true;

            // Cyclic dependency threshold is lowered from the default (2000)
            // as this causes the test framework to be painfully slow
            core.Options.kDynamicCycleThreshold = 5;

            // Pass the absolute path so that imported filepaths can be resolved
            // in "FileUtils.GetDSFullPathName()"
            if (!String.IsNullOrEmpty(includePath))
            {
                includePath = Path.GetDirectoryName(includePath);
                core.Options.IncludeDirectories.Add(includePath);
            }

            //StreamWriter sw = File.CreateText(executionLogFilePath);
            TextOutputStream fs = new TextOutputStream(map);

            // By specifying this option we inject a mock Executive ('InjectionExecutive')
            // that prints stackvalues at every assignment statement
            // by overriding the POP_handler instruction - pratapa
            core.ExecutiveProvider = new InjectionExecutiveProvider();

            //core.BuildStatus.MessageHandler = fs;
            core.RuntimeStatus.MessageHandler = fs;

            core.Executives.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Executive(core));
            core.Executives.Add(ProtoCore.Language.kImperative, new ProtoImperative.Executive(core));

            runnerConfig             = new ProtoScript.Config.RunConfiguration();
            runnerConfig.IsParrallel = false;

            DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());

            //Run
            ProtoLanguage.CompileStateTracker compileState = null;
            Mirror = fsr.Execute(code, core, out compileState);

            //sw.Close();
            core.Cleanup();
        }
Exemplo n.º 33
0
        public static ProtoLanguage.CompileStateTracker BuildDefaultCompilerState(Dictionary<string, Object> context = null)
        {
            ProtoLanguage.CompileOptions options = new ProtoLanguage.CompileOptions();

            ProtoLanguage.CompileStateTracker compileState = new ProtoLanguage.CompileStateTracker(options);

            compileState.Executives.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Executive());
            compileState.Executives.Add(ProtoCore.Language.kImperative, new ProtoImperative.Executive());

            if (null != context)
            {
                compileState.AddContextData(context);
            }

            return compileState;
        }
Exemplo n.º 34
0
        internal SymbolDatabaseProxy(ProtoLanguage.CompileStateTracker compileState, Dictionary<ScopeInfo, CodeRange> scopeIdentifiers)
        {
            this.compileState = compileState;

            try
            {
                string connString = "Data Source=:memory:";
                connection = new SQLiteConnection(connString);
                connection.Open();
            }
            catch (Exception)
            {
                if (null != connection)
                    connection.Dispose();

                connection = null;
                return;
            }

            PopulateDatabase(scopeIdentifiers);
        }
Exemplo n.º 35
0
        public BuildStatus(ProtoLanguage.CompileStateTracker compilestate, bool warningAsError, System.IO.TextWriter writer = null, bool errorAsWarning = false)
        {
            this.compileState = compilestate;
            warnings = new List<BuildData.WarningEntry>();

            errors = new List<BuildData.ErrorEntry>();
            this.warningAsError = warningAsError;
            this.errorAsWarning = errorAsWarning;

            if (writer != null)
            {
                consoleOut = System.Console.Out;
                System.Console.SetOut(writer);
            }

            // Create a default console output stream, and this can
            // be overwritten in IDE by assigning it a different value.
            this.MessageHandler = new ConsoleOutputStream();
            if (compilestate.Options.WebRunner)
            {
                this.WebMsgHandler = new WebOutputStream(compilestate);
            }
        }
Exemplo n.º 36
0
 public WebOutputStream(ProtoLanguage.CompileStateTracker state)
 {
     this.compileState = state;
     this.filename = state.CurrentDSFileName;
 }
Exemplo n.º 37
0
        public CodeGen(ProtoLanguage.CompileStateTracker compileTracker, ProtoCore.DSASM.CodeBlock parentBlock = null)
        {
            Debug.Assert(compileTracker != null);
            this.compileStateTracker = compileTracker;
            buildStatus = compileStateTracker.BuildStatus;
            isEntrySet = false;

            emitReplicationGuide = false;

            dumpByteCode = compileStateTracker.Options.DumpByteCode;
            isAssocOperator = false;

            pc = 0;
            argOffset = 0;
            globalClassIndex = compileStateTracker.ClassIndex;

            context = new ProtoCore.CompileTime.Context();
            opKwData = new ProtoCore.DSASM.OpKeywordData();

            targetLangBlock = ProtoCore.DSASM.Constants.kInvalidIndex;

            enforceTypeCheck = true;

            localProcedure = compileStateTracker.ProcNode;
            globalProcIndex = null != localProcedure ? localProcedure.procId : ProtoCore.DSASM.Constants.kGlobalScope;

            tryLevel = 0;

            functionCallStack = new List<DSASM.ProcedureNode>();

            IsAssociativeArrayIndexing = false;

            if (compileStateTracker.AsmOutput == null)
            {
                if (compileStateTracker.Options.CompileToLib)
                {
                    string path = "";
                    if (compileStateTracker.Options.LibPath == null)
                    {
                        path += compileStateTracker.Options.RootModulePathName + "ASM";
                    }
                    else
                    {
                        path = Path.Combine(compileStateTracker.Options.LibPath, Path.GetFileNameWithoutExtension(compileStateTracker.Options.RootModulePathName) + ".dsASM");
                    }

                    compileStateTracker.AsmOutput = new StreamWriter(File.Open(path, FileMode.Create));
                }
                else
                {
                    compileStateTracker.AsmOutput = Console.Out;
                }
            }

            ssaPointerList = new List<AST.AssociativeAST.AssociativeNode>();
        }
Exemplo n.º 38
0
 public GenerateScript(ProtoLanguage.CompileStateTracker compileState)
 {
     script = new Script();
     this.compileState = compileState;
 }
Exemplo n.º 39
0
 // public static readonly string kInstanceVarName = "__instance";
 public ImportModuleHandler(ProtoLanguage.CompileStateTracker compileState)
 {
     this.compileState = compileState;
     if (compileState.Options.RootModulePathName != null)
         mModuleTable[compileState.Options.RootModulePathName] = null;
 }
Exemplo n.º 40
0
        public static List<ProtoCore.AST.Node> ParseCodeBlock(string code)
        {
            Validity.Assert(code != null);

            if (string.IsNullOrEmpty(code))
                return null;

            // TODO: Change the logic to ignore Import statements in this case using parser - pratapa
            // Check if this will work with modifier blocks as well
            /*string[] stmts = code.Split(';');
            string source = "";
            for (int i=0; i < stmts.Length; ++i)
            {
                if (!stmts[i].Contains("import"))
                    source += stmts[i] + ";";
            }*/


            ProtoLanguage.CompileOptions options = new ProtoLanguage.CompileOptions();
            ProtoLanguage.CompileStateTracker compileState = new ProtoLanguage.CompileStateTracker(options);
            
            //compileState.Executives.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Executive(compileState));
            //compileState.Executives.Add(ProtoCore.Language.kImperative, new ProtoImperative.Executive(compileState));

            System.IO.MemoryStream memstream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(code));
            ProtoCore.DesignScriptParser.Scanner s = new ProtoCore.DesignScriptParser.Scanner(memstream);
            ProtoCore.DesignScriptParser.Parser p = new ProtoCore.DesignScriptParser.Parser(s, compileState);

            p.Parse();
            ProtoCore.AST.AssociativeAST.CodeBlockNode cbn = p.root as ProtoCore.AST.AssociativeAST.CodeBlockNode;

            Validity.Assert(cbn != null);
            return p.GetParsedASTList(cbn);
        }
Exemplo n.º 41
0
        private static void BuildCompileState(bool isCodeBlockNode = false, bool isPreloadedAssembly = false)
        {
            if (compileState == null)
            {
                ProtoLanguage.CompileOptions options = new ProtoLanguage.CompileOptions();
                options.RootModulePathName = rootModulePath;
                compileState = new ProtoLanguage.CompileStateTracker(options);
                compileState.Executives.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Executive());
                compileState.Executives.Add(ProtoCore.Language.kImperative, new ProtoImperative.Executive());

            }
            else
            {
                compileState.ResetForPrecompilation();
            }

            compileState.IsParsingPreloadedAssembly = isPreloadedAssembly;
            compileState.IsParsingCodeBlockNode = isCodeBlockNode;
            compileState.ParsingMode = ProtoCore.ParseMode.AllowNonAssignment;
        }
Exemplo n.º 42
0
 //: base(compileState)
 internal ClassMirror(ProtoLanguage.CompileStateTracker compileState, ProtoCore.DSASM.ClassNode classNode, LibraryMirror libraryMirror)
 {
     this.compileState = compileState;
     ClassName = classNode.name;
     this.libraryMirror = libraryMirror;
     this.classNode = classNode;
 }
Exemplo n.º 43
0
 public Parser(Scanner scanner, ProtoLanguage.CompileStateTracker cs, bool _builtinMethodsLoaded = false)
 {
     this.scanner = scanner;
     errors = new Errors();
     errors.compileState = cs;
     this.compileState = cs;
     builtinMethodsLoaded = _builtinMethodsLoaded;
     commentNode = new CodeBlockNode();
 }
Exemplo n.º 44
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 });

                //Register the default executives
                //@TODO(Luke) this will need generaling to support dynamic loading of executives
                core.Executives.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Executive(core));
                core.Executives.Add(ProtoCore.Language.kImperative, new ProtoImperative.Executive(core));
            }

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

            //Run the compilation process
            compileState = Compile(out resumeBlockID);
            if (compileState.compileSucceeded)
            {
                inited = true;
                core.NotifyExecutionEvent(ProtoCore.ExecutionStateEventArgs.State.kExecutionBegin);

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

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

                return false;
            }
        }
Exemplo n.º 45
0
 public NodeBuilder(ProtoLanguage.CompileStateTracker compileState)
 {
     this.compileState = compileState;
 }
Exemplo n.º 46
0
        private ProtoLanguage.CompileStateTracker CompileCodeSnapshot(AutoCompleteWorkData workData)
        {
            if (null != this.scopeIdentifiers)
            {
                this.scopeIdentifiers.Clear();
                this.scopeIdentifiers = null;
            }

            ProtoLanguage.CompileOptions options = new ProtoLanguage.CompileOptions();
            options.RootModulePathName = workData.ScriptPath;
            ProtoLanguage.CompileStateTracker compileState = new ProtoLanguage.CompileStateTracker(options);

            compileState.CurrentDSFileName = workData.ScriptPath;
            ProtoFFI.DLLFFIHandler.Register(ProtoFFI.FFILanguage.CSharp, new ProtoFFI.CSModuleHelper());

            // Register a message stream if we do have one.
            if (null != this.MessageHandler)
                compileState.BuildStatus.MessageHandler = this.MessageHandler;

            MemoryStream stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(workData.CodeSnapshot));
            ProtoCore.DesignScriptParser.Scanner s = new ProtoCore.DesignScriptParser.Scanner(stream);
            ProtoCore.DesignScriptParser.Parser p = new ProtoCore.DesignScriptParser.Parser(s, compileState);

            try
            {
                p.Parse();
                CoreCodeGen.arrayTypeTable = new ArrayTypeTable();
                AssociativeCodeGen codegen = new AssociativeCodeGen(compileState);

                codegen.Emit(p.root as ProtoCore.AST.AssociativeAST.CodeBlockNode);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception Caught in CodeGen");
                System.Diagnostics.Debug.WriteLine(ex.Message);
                compileState = null;
            }
            finally
            {
                // Do necessary clean-up here.
            }

            return compileState;
        }
Exemplo n.º 47
0
        public static List<SnapshotNode> NodeToCodeBlocks(List<SnapshotNode> inputs, GraphToDSCompiler.GraphCompiler originalGC)
        {
            List<SnapshotNode> codeBlocks = new List<SnapshotNode>();
            GraphToDSCompiler.GraphCompiler newGC = GraphCompiler.CreateInstance();

            newGC.SetCore(compileState);
            GraphToDSCompiler.SynchronizeData newSyncData = new SynchronizeData();
            newSyncData.AddedNodes = inputs;
            newSyncData.ModifiedNodes = new List<SnapshotNode>();
            newSyncData.RemovedNodes = new List<uint>();
            GraphToDSCompiler.GraphBuilder GB = new GraphBuilder(newSyncData, newGC);

            #region fix connection for multi-line CBN
            /*for multi-line code blocks*/
            List<Node> completeList = originalGC.Graph.nodeList;
            List<uint> originalNodeUIDList = new List<uint>();
            foreach (Node oriGcNode in completeList)
            {
                originalNodeUIDList.Add(oriGcNode.Guid);
            }

            GB.AddNodesToAST();

            //List<SnapshotNode> inputsCopy = new List<SnapshotNode>(inputs);
            for (int i = 0; i < inputs.Count; i++)
            {
                SnapshotNode inputSnapshotNode = inputs[i];
                for (int j = 0; j < inputSnapshotNode.InputList.Count; j++)
                {
                    Connection inputConnection = inputSnapshotNode.InputList[j];
                    if (!originalNodeUIDList.Contains(inputConnection.OtherNode))
                    {
                        Connection correctedInputConnection = new Connection();
                        correctedInputConnection.LocalName = inputConnection.LocalName;
                        correctedInputConnection.LocalIndex = inputConnection.LocalIndex;
                        correctedInputConnection.IsImplicit = inputConnection.IsImplicit;
                        correctedInputConnection.OtherIndex = inputConnection.OtherIndex;
                        if (newGC.codeBlockUIDMap.ContainsKey(inputConnection.OtherNode))
                        {
                            correctedInputConnection.OtherNode = newGC.codeBlockUIDMap[inputConnection.OtherNode][inputConnection.OtherIndex];
                        }
                        else
                        {
                            correctedInputConnection.OtherNode = originalGC.codeBlockUIDMap[inputConnection.OtherNode][inputConnection.OtherIndex];
                        }
                        inputSnapshotNode.InputList.Remove(inputConnection);
                        inputSnapshotNode.InputList.Insert(j, correctedInputConnection);
                    }
                }
                for (int j = 0; j < inputSnapshotNode.OutputList.Count; j++)
                {
                    Connection outputConnection = inputSnapshotNode.OutputList[j];
                    if (!originalNodeUIDList.Contains(outputConnection.OtherNode))                       // if the other node is split
                    {
                        Connection correctedInputConnection = new Connection();
                        correctedInputConnection.LocalName = outputConnection.LocalName;
                        correctedInputConnection.LocalIndex = outputConnection.LocalIndex;
                        correctedInputConnection.IsImplicit = outputConnection.IsImplicit;
                        correctedInputConnection.OtherIndex = outputConnection.OtherIndex;
                        if (newGC.codeBlockUIDMap.ContainsKey(outputConnection.OtherNode))
                        {
                            correctedInputConnection.OtherNode = newGC.GetUidOfRHSIdentifierInCodeBlock(
                                outputConnection.OtherNode, outputConnection.OtherIndex, outputConnection.LocalName);
                            //correctedInputConnection.OtherNode = newGC.codeBlockUIDMap[outputConnection.OtherNode][outputConnection.OtherIndex];
                        }
                        else
                        {
                            correctedInputConnection.OtherNode = originalGC.codeBlockUIDMap[outputConnection.OtherNode][outputConnection.OtherIndex];
                        }
                        inputSnapshotNode.OutputList.Remove(outputConnection);
                        inputSnapshotNode.OutputList.Insert(j, correctedInputConnection);
                    }
                }
            }
            GB.nodesToAdd = inputs;
            GB.MakeConnectionsForAddedNodes_NodeToCode(GB.nodesToAdd);
            newGC.PrintGraph();
            #endregion

            //GB.BuildGraphForCodeBlock();

            List<uint> nodesToBeAdded = new List<uint>();
            List<Node> nodesToBeReplaced = new List<Node>();

            //adding children node from the originalGC to the newGC needed for the newGC to generate code
            foreach (Node n in completeList)
            {
                foreach (Node child in n.GetChildren())
                {
                    if (newGC.Graph.GetNode(child.Guid) != null)
                    {
                        if (child.Name != newGC.Graph.GetNode(child.Guid).Name)
                        {
                            nodesToBeReplaced.Add(child);
                        }
                    }
                }
            }

            foreach (uint n in nodesToBeAdded)
            {
                Node n1 = completeList.FirstOrDefault(q => q.Guid == n);
                //n1.children.Clear();
                nodesToBeReplaced.Add(n1);
                //newSyncData.RemovedNodes.Add(n);
            }

            List<uint> nodeToCodeUIDs = new List<uint>();
            foreach (SnapshotNode ssn in inputs)
                nodeToCodeUIDs.Add(ssn.Id);
            newGC.nodeToCodeUIDs = nodeToCodeUIDs;

            /*create output snapshot nodes*/
            List<Connection> inputNodeInputConnections = new List<Connection>();
            List<Connection> inputNodeOutputConnections = new List<Connection>();
            foreach (SnapshotNode ssn in inputs)
            {
                foreach (Connection inputConnection in ssn.InputList)
                {
                    if (!nodeToCodeUIDs.Contains(inputConnection.OtherNode))
                        inputNodeInputConnections.Add(inputConnection);
                }
                foreach (Connection outputConnection in ssn.OutputList)
                {
                    if (!nodeToCodeUIDs.Contains(outputConnection.OtherNode))
                        inputNodeOutputConnections.Add(outputConnection);
                }
            }

            newGC.ReplaceNodesFromAList(nodesToBeReplaced);
            newSyncData.AddedNodes = new List<SnapshotNode>();
            newSyncData.ModifiedNodes = new List<SnapshotNode>();
            newSyncData.RemovedNodes = new List<uint>();
            GB = new GraphBuilder(newSyncData, newGC);
            //string result = GB.BuildGraphDAG();
            List<SnapshotNode> nodeToCodeBlocks = GB.PrintCodeForSelectedNodes(originalGC, inputs);

            /*for now, only connected nodes are supported: return all connections that are not internal connections (connections between the selected nodes)*/
            //uint id = 0;
            //foreach (string content in toCode)
            //{
            //    SnapshotNode ssn = new SnapshotNode();
            //    ssn.Type = SnapshotNodeType.CodeBlock;
            //    ssn.Content = content;
            //    ssn.Id = id++;
            //    ssn.InputList = new List<Connection>();
            //    //stupid stub
            //    foreach (Connection inputConnection in inputNodeInputConnections)
            //    {
            //        Connection newInputConnection = new Connection();
            //        newInputConnection.OtherNode = inputConnection.OtherNode;
            //        newInputConnection.OtherIndex = inputConnection.OtherIndex;
            //        newInputConnection.IsImplicit = inputConnection.IsImplicit;
            //        string[] tokens = newGC.Graph.GetNode(inputConnection.OtherNode).Name.Split('=');
            //        newInputConnection.LocalName = tokens[0];
            //        ssn.InputList.Add(newInputConnection);
            //    }
            //    //ssn.InputList = inputNodeInputConnections;
            //    ssn.OutputList = new List<Connection>();
            //    foreach (Connection outputConnection in inputNodeOutputConnections)
            //    {
            //        Connection newOutputConnection = new Connection();
            //        newOutputConnection.OtherNode = outputConnection.OtherNode;
            //        newOutputConnection.OtherIndex = outputConnection.OtherIndex;
            //        newOutputConnection.IsImplicit = outputConnection.IsImplicit;
            //        //string[] tokens = originalGC.Graph.GetNode(outputConnection.OtherNode).Name.Split('=');
            //        newOutputConnection.LocalName = outputConnection.LocalName;
            //        ssn.OutputList.Add(newOutputConnection);
            //    }
            //    //ssn.OutputList = inputNodeOutputConnections;
            //    codeBlocks.Add(ssn);
            //}

            /*update the original GC*/
            foreach (SnapshotNode inputNode in inputs)
            {
                if (originalNodeUIDList.Contains(inputNode.Id))
                    originalGC.RemoveNodes(inputNode.Id, false);
                else
                {
                    foreach (KeyValuePair<uint, Dictionary<int, uint>> kvp in originalGC.codeBlockUIDMap)
                    {
                        if (kvp.Value.ContainsValue(inputNode.Id))
                        {
                            originalGC.RemoveNodes(kvp.Key, false);
                        }
                    }
                }
            }
            foreach (Node node in newGC.Graph.nodeList)
            {
                node.Name = node.Name.TrimEnd(';') + ";";
            }
            originalGC.Graph.nodeList.Union<Node>(newGC.Graph.nodeList);
            //originalGC = newGC;
            /**/

            return nodeToCodeBlocks;
            //return codeBlocks;
        }

        /// <summary>
        /// This is called to Parse individual assignment statements in Codeblock nodes in GraphUI
        /// and return the resulting ProtoAST node
        /// </summary>
        /// <param name="statement"></param>
        public static ProtoCore.AST.Node Parse(string statement, out ProtoCore.AST.AssociativeAST.CodeBlockNode commentNode)
        {
            commentNode = null;
            BuildCompileState(true);

            Validity.Assert(compileState != null);
            Validity.Assert(statement != null);

            if (string.IsNullOrEmpty(statement))
                return null;

            System.IO.MemoryStream memstream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(statement));
            ProtoCore.DesignScriptParser.Scanner s = new ProtoCore.DesignScriptParser.Scanner(memstream);
            ProtoCore.DesignScriptParser.Parser p = new ProtoCore.DesignScriptParser.Parser(s, compileState);

            p.Parse();
            commentNode = p.commentNode;

            return p.root;
        }

        public static List<ProtoCore.AST.Node> ParseCodeBlock(string code)
        {
            Validity.Assert(code != null);

            if (string.IsNullOrEmpty(code))
                return null;

            // TODO: Change the logic to ignore Import statements in this case using parser - pratapa
            // Check if this will work with modifier blocks as well
            /*string[] stmts = code.Split(';');
            string source = "";
            for (int i=0; i < stmts.Length; ++i)
            {
                if (!stmts[i].Contains("import"))
                    source += stmts[i] + ";";
            }*/

            ProtoLanguage.CompileOptions options = new ProtoLanguage.CompileOptions();
            ProtoLanguage.CompileStateTracker compileState = new ProtoLanguage.CompileStateTracker(options);

            //compileState.Executives.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Executive(compileState));
            //compileState.Executives.Add(ProtoCore.Language.kImperative, new ProtoImperative.Executive(compileState));

            System.IO.MemoryStream memstream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(code));
            ProtoCore.DesignScriptParser.Scanner s = new ProtoCore.DesignScriptParser.Scanner(memstream);
            ProtoCore.DesignScriptParser.Parser p = new ProtoCore.DesignScriptParser.Parser(s, compileState);

            p.Parse();
            ProtoCore.AST.AssociativeAST.CodeBlockNode cbn = p.root as ProtoCore.AST.AssociativeAST.CodeBlockNode;

            Validity.Assert(cbn != null);
            return p.GetParsedASTList(cbn);
        }
Exemplo n.º 48
0
        public static void CleanUp()
        {
            if (compileState != null)
            {
                compileState.Cleanup();
            }
            compileState = null;

            numBuiltInMethods = 0;
            builtInMethods = null;
            importedAssemblies.Clear();
            rootModulePath = string.Empty;
        }
Exemplo n.º 49
0
        //public BuildStatus(Core core, bool LogWarnings, bool logErrors, bool displayBuildResult, System.IO.TextWriter writer = null)
        //{
        //    this.core = core;
        //    this.LogWarnings = LogWarnings;
        //    this.logErrors = logErrors;
        //    this.displayBuildResult = displayBuildResult;

        //    //this.errorCount = 0;
        //    //this.warningCount = 0;
        //    warnings = new List<BuildData.WarningEntry>();

        //    errors = new List<BuildData.ErrorEntry>();

        //    if (writer != null)
        //    {
        //        consoleOut = System.Console.Out;
        //        System.Console.SetOut(writer);
        //    }

        //    // Create a default console output stream, and this can 
        //    // be overwritten in IDE by assigning it a different value.
        //    this.MessageHandler = new ConsoleOutputStream();
        //}      

        public BuildStatus(ProtoLanguage.CompileStateTracker compilestate, bool LogWarnings, bool logErrors, bool displayBuildResult, System.IO.TextWriter writer = null)
        {
            this.compileState = compilestate;
            this.LogWarnings = LogWarnings;
            this.logErrors = logErrors;
            this.displayBuildResult = displayBuildResult;

            //this.errorCount = 0;
            //this.warningCount = 0;
            warnings = new List<BuildData.WarningEntry>();
            
            errors = new List<BuildData.ErrorEntry>();

            if (writer != null)
            {
                consoleOut = System.Console.Out;
                System.Console.SetOut(writer);
            }

            // Create a default console output stream, and this can 
            // be overwritten in IDE by assigning it a different value.
            this.MessageHandler = new ConsoleOutputStream();
        }
Exemplo n.º 50
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;
        }
Exemplo n.º 51
0
 protected MirrorObject(ProtoCore.Core core, ProtoLanguage.CompileStateTracker compileState = null)
 {
     this.core = core;
     MirrorObject.staticcompileState = compileState;
 }
Exemplo n.º 52
0
 public CoreDataProvider(ProtoLanguage.CompileStateTracker compileState)
 {
     this.compileState = compileState;
 }
Exemplo n.º 53
0
 private bool CompileAndExecute(string code)
 {
     // TODO Jun: Revisit all the Compile functions and remove the blockId out argument
     int blockId = ProtoCore.DSASM.Constants.kInvalidIndex;
     compileState = Compile(code, out blockId);
     Validity.Assert(null != compileState);
     if (compileState.compileSucceeded)
     {
         runnerCore.RunningBlock = blockId;
         vmState = Execute();
     }
     return compileState.compileSucceeded;
 }
Exemplo n.º 54
0
 private ContextDataManager(ProtoLanguage.CompileStateTracker compileState)
 {
     this.compileState = compileState;
     mCoreDataProvider = new CoreDataProvider(compileState);
 }
Exemplo n.º 55
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;
        }
Exemplo n.º 56
0
 public DependencyGraph(ProtoLanguage.CompileStateTracker compileState)
 {
     this.compileState = compileState;
     graphList = new List<GraphNode>();
     graphNodeMap = new Dictionary<ulong, List<GraphNode>>();
 }
Exemplo n.º 57
0
 public void SetCore(ProtoLanguage.CompileStateTracker compileState)
 {
     Validity.Assert(null == this.compileState);
     this.compileState = compileState;
 }