Ejemplo n.º 1
0
 public static ProtoCore.AST.AssociativeAST.IdentifierNode BuildAssocIdentifier(ProtoLanguage.CompileStateTracker compileState, string name, ProtoCore.PrimitiveType type = ProtoCore.PrimitiveType.kTypeVar)
 {
     var ident = new ProtoCore.AST.AssociativeAST.IdentifierNode();
     ident.Name = ident.Value = name;
     ident.datatype = TypeSystem.BuildPrimitiveTypeObject(type, false);
     return ident;
 }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
0
        public ImperativeCodeGen(ProtoLanguage.CompileStateTracker compileState, ProtoCore.DSASM.CodeBlock parentBlock = null)
            : base(compileState, parentBlock)
        {
            //  dumpbytecode is optionally enabled
            //
            astNodes = new List<ImperativeNode>();

            SetCompileOptions();

            // Create a new symboltable for this block
            // Set the new symbol table's parent
            // Set the new table as a child of the parent table

            codeBlock = new ProtoCore.DSASM.CodeBlock(
                ProtoCore.DSASM.CodeBlockType.kLanguage,
                ProtoCore.Language.kImperative,
                compileState.CodeBlockIndex,
                new ProtoCore.DSASM.SymbolTable("imperative lang block", compileState.RuntimeTableIndex),
                new ProtoCore.DSASM.ProcedureTable(compileState.RuntimeTableIndex));

            ++compileState.CodeBlockIndex;
            ++compileState.RuntimeTableIndex;

            compileState.CodeBlockList.Add(codeBlock);
            if (null != parentBlock)
            {
                // This is a nested block
                parentBlock.children.Add(codeBlock);
                codeBlock.parent = parentBlock;
            }

            blockScope = 0;
        }
Ejemplo n.º 5
0
        public static ContextDataManager GetInstance(ProtoLanguage.CompileStateTracker compileState)
        {
            if (compileState.ContextDataManager != null)
                return compileState.ContextDataManager;

            compileState.ContextDataManager = new ContextDataManager(compileState);
            return compileState.ContextDataManager;
        }
        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; ;
        }
Ejemplo n.º 7
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;
 }
Ejemplo n.º 8
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));
			}
		}
    }
Ejemplo n.º 9
0
        public CodeGen(ProtoLanguage.CompileStateTracker coreObj, ProtoCore.DSASM.CodeBlock parentBlock = null)
            : base(coreObj, parentBlock)
        {
            //  dumpbytecode is optionally enabled
            //
            astNodes = new List<ImperativeNode>();

            SetCompileOptions();

            // Create a new symboltable for this block
            // Set the new symbol table's parent
            // Set the new table as a child of the parent table

            codeBlock = new ProtoCore.DSASM.CodeBlock(
                ProtoCore.DSASM.CodeBlockType.kLanguage,
                ProtoCore.Language.kImperative,
                compileStateTracker.CodeBlockIndex,
                new ProtoCore.DSASM.SymbolTable("imperative lang block", compileStateTracker.RuntimeTableIndex),
                new ProtoCore.DSASM.ProcedureTable(compileStateTracker.RuntimeTableIndex),
                false,
                compileStateTracker);

            ++compileStateTracker.CodeBlockIndex;
            ++compileStateTracker.RuntimeTableIndex;

            if (null == parentBlock)
            {
                // This is a top level block
                compileStateTracker.CodeBlockList.Add(codeBlock);
            }
            else
            {
                // This is a nested block
                parentBlock.children.Add(codeBlock);
                codeBlock.parent = parentBlock;
            }
            compileStateTracker.CompleteCodeBlockList.Add(codeBlock);
            blockScope = 0;

            // Bouncing to this language codeblock from a function should immediatlet se the first instruction as the entry point
            if (ProtoCore.DSASM.Constants.kGlobalScope != globalProcIndex)
            {
                isEntrySet = true;
                codeBlock.instrStream.entrypoint = 0;
            }

            backpatchMap = new BackpatchMap();

            nodeBuilder = new NodeBuilder(compileStateTracker);
        }
Ejemplo n.º 10
0
        static void Main(/*string[] args*/)
        {
            var langs = new ProtoLanguage[]
            {
                new ProtoLanguage {
                    Index = 0, Name0 = "a", Name1 = "B", TextId = "a", Translations = new Dictionary <uint, string>
                    {
                        { 0, "a" }, { 1, "z" }, { 2, "a" }, { 3, "v" }
                    }
                },
                new ProtoLanguage {
                    Index = 1, Name0 = "a", Name1 = "B", TextId = "b", Translations = new Dictionary <uint, string>
                    {
                        { 0, "s" }, { 1, "d" }, { 2, "d" }, { 3, "v" }
                    }
                },
                new ProtoLanguage {
                    Index = 2, Name0 = "a", Name1 = "B", TextId = "c", Translations = new Dictionary <uint, string>
                    {
                        { 0, "a" }, { 1, "x" }, { 2, "s" }, { 3, "f" }
                    }
                },
                new ProtoLanguage {
                    Index = 3, Name0 = "a", Name1 = "B", TextId = "d", Translations = new Dictionary <uint, string>
                    {
                        { 0, "x" }, { 1, "r" }, { 2, "x" }, { 3, "z" }
                    }
                },
                new ProtoLanguage {
                    Index = 4, Name0 = "a", Name1 = "B", TextId = "e", Translations = new Dictionary <uint, string>
                    {
                        { 0, "x" }, { 1, "f" }, { 2, "l" }, { 3, "f" }
                    }
                }
            };
            var transIds = new Dictionary <string, uint>
            {
                { "w", 0 }, { "x", 1 }, { "y", 2 }, { "z", 3 }
            };
            var langMod = new LanguageFirstModel(langs, transIds);
            var json    = langMod.JsonSerialize();

            using (var fs = File.OpenWrite(@"..\..\..\a.json"))
                using (var stream = new StreamWriter(fs))
                    using (var jsonTextWriter = new JsonTextWriter(stream))
                    {
                        json.WriteTo(jsonTextWriter);
                    }
        }
Ejemplo n.º 11
0
 public static void InsertPredefinedAndBuiltinMethods(ProtoLanguage.CompileStateTracker compileState, ProtoCore.AST.Node root, bool builtinMethodsLoaded)
 {
     if (DSASM.InterpreterMode.kNormal == compileState.ExecMode)
     {
         if (!builtinMethodsLoaded)
         {
             InsertDotMethod(compileState, root);
         }
         if (compileState.Options.AssocOperatorAsMethod)
         {
             ProtoCore.Utils.CoreUtils.InsertPredefinedMethod(compileState, root, builtinMethodsLoaded);
         }
         ProtoCore.Utils.CoreUtils.InsertBuiltInMethods(compileState, root, builtinMethodsLoaded);
     }
 }
Ejemplo n.º 12
0
        public CodeBlock(CodeBlockType type, ProtoCore.Language langId, int codeBlockId, SymbolTable symbols, ProcedureTable procTable, bool isBreakableBlock = false, ProtoLanguage.CompileStateTracker compileState = null)
        {
            blockType = type;

            parent = null;
            children = new List<CodeBlock>();

            language = langId;
            this.codeBlockId = codeBlockId;
            instrStream = new InstructionStream(langId, compileState);

            symbolTable = symbols;
            procedureTable = procTable;

            isBreakable = isBreakableBlock;
        }
Ejemplo n.º 13
0
        public static bool Compare(string s1, string s2, ProtoLanguage.CompileStateTracker compileState)
        {
            System.IO.MemoryStream memstream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(s1));
            ProtoCore.DesignScriptParser.Scanner s = new ProtoCore.DesignScriptParser.Scanner(memstream);
            ProtoCore.DesignScriptParser.Parser p = new ProtoCore.DesignScriptParser.Parser(s, compileState);
            p.Parse();
            ProtoCore.AST.Node s1Root = p.root;

            memstream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(s2));
            s = new ProtoCore.DesignScriptParser.Scanner(s2);
            p = new ProtoCore.DesignScriptParser.Parser(s, compileState);
            p.Parse();
            ProtoCore.AST.Node s2Root = p.root;

            bool areEqual = s1Root.Compare(s2Root);
            return areEqual;
        }
Ejemplo n.º 14
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); 
    }
Ejemplo n.º 15
0
        /// <summary>
        /// TODO Jun : Remove me after the tracker + core swap-out
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public static string GetDSFullPathName(string fileName, ProtoLanguage.CompileOptions options = null)
        {
            //1.  First search at .exe module directory, in case files of the same name exists in the following directories.
            //    The .exe module directory is of highest priority.
            //    CodeBase is used here because Assembly.Location does not work quite well when the module is shallow-copied in nunit test.
            if (Path.IsPathRooted(fileName))
            {
                if (File.Exists(fileName))
                    return Path.GetFullPath(fileName);
                fileName = Path.GetFileName(fileName);
            }

            string fullPathName;

            if (GetFullPath(fileName, GetInstallLocation(), out fullPathName))
                return fullPathName;

            //2. Search relative to the .ds file directory
            string rootModulePath = ".";
            if (null != options && !string.IsNullOrEmpty(options.RootModulePathName))
                rootModulePath = options.RootModulePathName;

            if (GetFullPath(fileName, rootModulePath, out fullPathName))
                return fullPathName;

            if (null != options)
            {
                //3. Search at include directories.
                //   This will include the import path.
                foreach (string directory in options.IncludeDirectories)
                {
                    fullPathName = Path.Combine(directory, fileName);
                    if (null != fullPathName && File.Exists(fullPathName))
                        return fullPathName;
                }
            }

            //4. Search the absolute path or relative to the current directory
            if (File.Exists(fileName))
                return Path.GetFullPath(fileName);

            return fileName;
        }
Ejemplo n.º 16
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);
        }
Ejemplo n.º 17
0
        public AssociativeCodeGen(ProtoLanguage.CompileStateTracker compileState, ProtoCore.DSASM.CodeBlock parentBlock = null)
            : base(compileState, parentBlock)
        {
            classOffset = 0;

            //  either of these should set the console to flood
            //
            ignoreRankCheck = false;

            astNodes = new List<AssociativeNode>();
            setConstructorStartPC = false;

            // Create a new symboltable for this block
            // Set the new symbol table's parent
            // Set the new table as a child of the parent table

            codeBlock = new ProtoCore.DSASM.CodeBlock(
                ProtoCore.DSASM.CodeBlockType.kLanguage,
                ProtoCore.Language.kAssociative,
                compileState.CodeBlockIndex,
                new ProtoCore.DSASM.SymbolTable("associative lang block", compileState.RuntimeTableIndex),
                new ProtoCore.DSASM.ProcedureTable(compileState.RuntimeTableIndex),
                false,
                compileState);

            ++compileState.CodeBlockIndex;
            ++compileState.RuntimeTableIndex;

            compileState.CodeBlockList.Add(codeBlock);
            if (null != parentBlock)
            {
                // This is a nested block
                parentBlock.children.Add(codeBlock);
                codeBlock.parent = parentBlock;
            }

            compilePass = ProtoCore.DSASM.AssociativeCompilePass.kClassName;
        }
Ejemplo n.º 18
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);
            }
        }
Ejemplo n.º 19
0
        // This constructor is only called for Preloading of assemblies and
        // precompilation of CodeBlockNode nodes in GraphUI for global language blocks - pratapa
        public CodeGen(ProtoLanguage.CompileStateTracker compileState)
            : base(compileState)
        {
            Validity.Assert(compileStateTracker.IsParsingPreloadedAssembly || compileStateTracker.IsParsingCodeBlockNode);

            classOffset = 0;

            //  either of these should set the console to flood
            //
            ignoreRankCheck = false;
            emitReplicationGuide = false;

            astNodes = new List<AssociativeNode>();
            globalInstanceProcList = new List<GlobalInstanceProc>();
            setConstructorStartPC = false;

            // Re-use the existing procedureTable and symbolTable to access the built-in and predefined functions
            ProcedureTable procTable = compileStateTracker.CodeBlockList[0].procedureTable;
            codeBlock = BuildNewCodeBlock(procTable);

            // Remove global symbols from existing symbol table for subsequent run in Graph UI
            //SymbolTable sTable = core.CodeBlockList[0].symbolTable;
            //sTable.RemoveGlobalSymbols();
            //codeBlock = core.CodeBlockList[0];

            compilePass = ProtoCore.DSASM.AssociativeCompilePass.kClassName;

            // Bouncing to this language codeblock from a function should immediately set the first instruction as the entry point
            if (ProtoCore.DSASM.Constants.kGlobalScope != globalProcIndex)
            {
                isEntrySet = true;
                codeBlock.instrStream.entrypoint = 0;
            }

            nodeBuilder = new NodeBuilder(compileStateTracker);
            unPopulatedClasses = new Dictionary<int, ClassDeclNode>();
        }
Ejemplo n.º 20
0
        // The following methods are used to insert methods to the bottom of the AST and convert operator to these method calls
        // to support replication on operators
        private static void InsertUnaryOperationMethod(ProtoLanguage.CompileStateTracker compileState, ProtoCore.AST.Node root, UnaryOperator op, PrimitiveType r, PrimitiveType operand)
        {
            ProtoCore.AST.AssociativeAST.FunctionDefinitionNode funcDefNode = new ProtoCore.AST.AssociativeAST.FunctionDefinitionNode();
            funcDefNode.access = ProtoCore.DSASM.AccessSpecifier.kPublic;
            funcDefNode.IsAssocOperator = true;
            funcDefNode.IsBuiltIn = true;
            funcDefNode.Name = Op.GetUnaryOpFunction(op);
            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, "%param"),
            ArgumentType = new ProtoCore.Type { Name = compileState.TypeSystem.GetType((int)operand), UID = (int)operand }
            });
            funcDefNode.Singnature = args;

            ProtoCore.AST.AssociativeAST.CodeBlockNode body = new ProtoCore.AST.AssociativeAST.CodeBlockNode();
            ProtoCore.AST.AssociativeAST.IdentifierNode _return = BuildAssocIdentifier(compileState, ProtoCore.DSDefinitions.Keyword.Return, ProtoCore.PrimitiveType.kTypeReturn);
            ProtoCore.AST.AssociativeAST.IdentifierNode param = BuildAssocIdentifier(compileState, "%param");
            body.Body.Add(new ProtoCore.AST.AssociativeAST.BinaryExpressionNode() { LeftNode = _return, Optr = ProtoCore.DSASM.Operator.assign, RightNode = new ProtoCore.AST.AssociativeAST.UnaryExpressionNode() { Expression = param, Operator = op } });
            funcDefNode.FunctionBody = body;
            (root as ProtoCore.AST.AssociativeAST.CodeBlockNode).Body.Add(funcDefNode);
        }
Ejemplo n.º 21
0
        private static void InsertPredefinedMethod(ProtoLanguage.CompileStateTracker compileState, ProtoCore.AST.Node root, bool builtinMethodsLoaded)
        {
            if (!builtinMethodsLoaded)
            {
            InsertBinaryOperationMethod(compileState, root, Operator.add, PrimitiveType.kTypeInt, PrimitiveType.kTypeInt, PrimitiveType.kTypeInt);
            InsertBinaryOperationMethod(compileState, root, Operator.add, PrimitiveType.kTypeDouble, PrimitiveType.kTypeDouble, PrimitiveType.kTypeInt);
            InsertBinaryOperationMethod(compileState, root, Operator.add, PrimitiveType.kTypeDouble, PrimitiveType.kTypeInt, PrimitiveType.kTypeDouble);
            InsertBinaryOperationMethod(compileState, root, Operator.add, PrimitiveType.kTypeDouble, PrimitiveType.kTypeDouble, PrimitiveType.kTypeDouble);
            InsertBinaryOperationMethod(compileState, root, Operator.add, PrimitiveType.kTypeString, PrimitiveType.kTypeChar, PrimitiveType.kTypeChar);

            InsertBinaryOperationMethod(compileState, root, Operator.add, PrimitiveType.kTypeString, PrimitiveType.kTypeString, PrimitiveType.kTypeString);
            InsertBinaryOperationMethod(compileState, root, Operator.add, PrimitiveType.kTypeVar, PrimitiveType.kTypeString, PrimitiveType.kTypeChar);
            InsertBinaryOperationMethod(compileState, root, Operator.add, PrimitiveType.kTypeVar, PrimitiveType.kTypeChar, PrimitiveType.kTypeString);
            //			InsertBinaryOperationMethod(core, root, Operator.add, PrimitiveType.kTypeString, PrimitiveType.kTypeString, PrimitiveType.kTypeVar);
            //          InsertBinaryOperationMethod(core, root, Operator.add, PrimitiveType.kTypeString, PrimitiveType.kTypeVar, PrimitiveType.kTypeString);
            InsertBinaryOperationMethod(compileState, root, Operator.add, PrimitiveType.kTypeString, PrimitiveType.kTypeString, PrimitiveType.kTypeVar, 0, 0, ProtoCore.DSASM.Constants.kArbitraryRank);
            InsertBinaryOperationMethod(compileState, root, Operator.add, PrimitiveType.kTypeString, PrimitiveType.kTypeVar, PrimitiveType.kTypeString, 0, ProtoCore.DSASM.Constants.kArbitraryRank, 0);

            InsertBinaryOperationMethod(compileState, root, Operator.sub, PrimitiveType.kTypeInt, PrimitiveType.kTypeInt, PrimitiveType.kTypeInt);
            InsertBinaryOperationMethod(compileState, root, Operator.sub, PrimitiveType.kTypeDouble, PrimitiveType.kTypeDouble, PrimitiveType.kTypeInt);
            InsertBinaryOperationMethod(compileState, root, Operator.sub, PrimitiveType.kTypeDouble, PrimitiveType.kTypeInt, PrimitiveType.kTypeDouble);
            InsertBinaryOperationMethod(compileState, root, Operator.sub, PrimitiveType.kTypeDouble, PrimitiveType.kTypeDouble, PrimitiveType.kTypeDouble);
            //InsertBinaryOperationMethod(core, root, Operator.div, PrimitiveType.kTypeInt, PrimitiveType.kTypeInt, PrimitiveType.kTypeInt);
            //InsertBinaryOperationMethod(core, root, Operator.div, PrimitiveType.kTypeDouble, PrimitiveType.kTypeDouble, PrimitiveType.kTypeInt);
            //InsertBinaryOperationMethod(core, root, Operator.div, PrimitiveType.kTypeDouble, PrimitiveType.kTypeInt, PrimitiveType.kTypeDouble);
            InsertBinaryOperationMethod(compileState, root, Operator.div, PrimitiveType.kTypeDouble, PrimitiveType.kTypeDouble, PrimitiveType.kTypeDouble);
            InsertBinaryOperationMethod(compileState, root, Operator.mul, PrimitiveType.kTypeInt, PrimitiveType.kTypeInt, PrimitiveType.kTypeInt);
            InsertBinaryOperationMethod(compileState, root, Operator.mul, PrimitiveType.kTypeDouble, PrimitiveType.kTypeDouble, PrimitiveType.kTypeInt);
            InsertBinaryOperationMethod(compileState, root, Operator.mul, PrimitiveType.kTypeDouble, PrimitiveType.kTypeInt, PrimitiveType.kTypeDouble);
            InsertBinaryOperationMethod(compileState, root, Operator.mul, PrimitiveType.kTypeDouble, PrimitiveType.kTypeDouble, PrimitiveType.kTypeDouble);
            InsertBinaryOperationMethod(compileState, root, Operator.mod, PrimitiveType.kTypeInt, PrimitiveType.kTypeInt, PrimitiveType.kTypeInt);

            InsertBinaryOperationMethod(compileState, root, Operator.bitwiseand, PrimitiveType.kTypeInt, PrimitiveType.kTypeInt, PrimitiveType.kTypeInt);
            InsertBinaryOperationMethod(compileState, root, Operator.bitwiseand, PrimitiveType.kTypeBool, PrimitiveType.kTypeBool, PrimitiveType.kTypeBool);
            InsertBinaryOperationMethod(compileState, root, Operator.bitwiseor, PrimitiveType.kTypeInt, PrimitiveType.kTypeInt, PrimitiveType.kTypeInt);
            InsertBinaryOperationMethod(compileState, root, Operator.bitwiseor, PrimitiveType.kTypeBool, PrimitiveType.kTypeBool, PrimitiveType.kTypeBool);
            InsertBinaryOperationMethod(compileState, root, Operator.bitwisexor, PrimitiveType.kTypeInt, PrimitiveType.kTypeInt, PrimitiveType.kTypeInt);
            InsertBinaryOperationMethod(compileState, root, Operator.bitwisexor, PrimitiveType.kTypeBool, PrimitiveType.kTypeBool, PrimitiveType.kTypeBool);

            InsertBinaryOperationMethod(compileState, root, Operator.eq, PrimitiveType.kTypeBool, PrimitiveType.kTypeInt, PrimitiveType.kTypeInt);
            InsertBinaryOperationMethod(compileState, root, Operator.eq, PrimitiveType.kTypeBool, PrimitiveType.kTypeDouble, PrimitiveType.kTypeDouble);
            InsertBinaryOperationMethod(compileState, root, Operator.eq, PrimitiveType.kTypeBool, PrimitiveType.kTypeString, PrimitiveType.kTypeString);
            InsertBinaryOperationMethod(compileState, root, Operator.eq, PrimitiveType.kTypeBool, PrimitiveType.kTypeBool, PrimitiveType.kTypeBool);
            InsertBinaryOperationMethod(compileState, root, Operator.eq, PrimitiveType.kTypeBool, PrimitiveType.kTypeBool, PrimitiveType.kTypeVar);
            InsertBinaryOperationMethod(compileState, root, Operator.eq, PrimitiveType.kTypeBool, PrimitiveType.kTypeVar, PrimitiveType.kTypeBool);

            InsertBinaryOperationMethod(compileState, root, Operator.nq, PrimitiveType.kTypeBool, PrimitiveType.kTypeInt, PrimitiveType.kTypeInt);
            InsertBinaryOperationMethod(compileState, root, Operator.nq, PrimitiveType.kTypeBool, PrimitiveType.kTypeDouble, PrimitiveType.kTypeDouble);
            InsertBinaryOperationMethod(compileState, root, Operator.nq, PrimitiveType.kTypeBool, PrimitiveType.kTypeString, PrimitiveType.kTypeString);
            InsertBinaryOperationMethod(compileState, root, Operator.nq, PrimitiveType.kTypeBool, PrimitiveType.kTypeBool, PrimitiveType.kTypeBool);
            InsertBinaryOperationMethod(compileState, root, Operator.nq, PrimitiveType.kTypeBool, PrimitiveType.kTypeBool, PrimitiveType.kTypeVar);
            InsertBinaryOperationMethod(compileState, root, Operator.nq, PrimitiveType.kTypeBool, PrimitiveType.kTypeVar, PrimitiveType.kTypeBool);

            InsertBinaryOperationMethod(compileState, root, Operator.ge, PrimitiveType.kTypeBool, PrimitiveType.kTypeInt, PrimitiveType.kTypeInt);
            InsertBinaryOperationMethod(compileState, root, Operator.ge, PrimitiveType.kTypeBool, PrimitiveType.kTypeDouble, PrimitiveType.kTypeDouble);
            InsertBinaryOperationMethod(compileState, root, Operator.gt, PrimitiveType.kTypeBool, PrimitiveType.kTypeInt, PrimitiveType.kTypeInt);
            InsertBinaryOperationMethod(compileState, root, Operator.gt, PrimitiveType.kTypeBool, PrimitiveType.kTypeDouble, PrimitiveType.kTypeDouble);
            InsertBinaryOperationMethod(compileState, root, Operator.le, PrimitiveType.kTypeBool, PrimitiveType.kTypeInt, PrimitiveType.kTypeInt);
            InsertBinaryOperationMethod(compileState, root, Operator.le, PrimitiveType.kTypeBool, PrimitiveType.kTypeDouble, PrimitiveType.kTypeDouble);
            InsertBinaryOperationMethod(compileState, root, Operator.lt, PrimitiveType.kTypeBool, PrimitiveType.kTypeDouble, PrimitiveType.kTypeDouble);
            InsertBinaryOperationMethod(compileState, root, Operator.lt, PrimitiveType.kTypeBool, PrimitiveType.kTypeInt, PrimitiveType.kTypeInt);
            InsertBinaryOperationMethod(compileState, root, Operator.and, PrimitiveType.kTypeBool, PrimitiveType.kTypeInt, PrimitiveType.kTypeInt);
            InsertBinaryOperationMethod(compileState, root, Operator.or, PrimitiveType.kTypeBool, PrimitiveType.kTypeInt, PrimitiveType.kTypeInt);

            InsertUnaryOperationMethod(compileState, root, UnaryOperator.Neg, PrimitiveType.kTypeInt, PrimitiveType.kTypeInt);
            InsertUnaryOperationMethod(compileState, root, UnaryOperator.Neg, PrimitiveType.kTypeDouble, PrimitiveType.kTypeDouble);
            InsertUnaryOperationMethod(compileState, root, UnaryOperator.Negate, PrimitiveType.kTypeInt, PrimitiveType.kTypeInt);
            InsertUnaryOperationMethod(compileState, root, UnaryOperator.Negate, PrimitiveType.kTypeDouble, PrimitiveType.kTypeDouble);
            InsertUnaryOperationMethod(compileState, root, UnaryOperator.Not, PrimitiveType.kTypeBool, PrimitiveType.kTypeBool);

            InsertBinaryOperationMethod(compileState, root, Operator.and, PrimitiveType.kTypeBool, PrimitiveType.kTypeBool, PrimitiveType.kTypeBool);
            InsertBinaryOperationMethod(compileState, root, Operator.or, PrimitiveType.kTypeBool, PrimitiveType.kTypeBool, PrimitiveType.kTypeBool);

            InsertUnaryOperationMethod(compileState, root, UnaryOperator.Decrement, PrimitiveType.kTypeInt, PrimitiveType.kTypeInt);
            InsertUnaryOperationMethod(compileState, root, UnaryOperator.Increment, PrimitiveType.kTypeInt, PrimitiveType.kTypeInt);
            }
        }
Ejemplo n.º 22
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.Keyword.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);
        }
Ejemplo n.º 23
0
 private static void InsertDotMethod(ProtoLanguage.CompileStateTracker compileState, ProtoCore.AST.Node root)
 {
     InsertDotMemFuncMethod(compileState, root);
 }
Ejemplo n.º 24
0
        public static ProtoCore.AST.AssociativeAST.FunctionDotCallNode GenerateCallDotNode(ProtoCore.AST.AssociativeAST.AssociativeNode lhs, 
            ProtoCore.AST.AssociativeAST.FunctionCallNode rhsCall, ProtoLanguage.CompileStateTracker compileState = null)
        {
            // The function name to call
            string rhsName = rhsCall.Function.Name;
            int argNum = rhsCall.FormalArguments.Count;
            ProtoCore.AST.AssociativeAST.ExprListNode argList = new ProtoCore.AST.AssociativeAST.ExprListNode();
            foreach (ProtoCore.AST.AssociativeAST.AssociativeNode arg in rhsCall.FormalArguments)
            {
                // The function arguments
                argList.list.Add(arg);
            }

            ProtoCore.AST.AssociativeAST.FunctionCallNode funCallNode = new ProtoCore.AST.AssociativeAST.FunctionCallNode();
            ProtoCore.AST.AssociativeAST.IdentifierNode funcName = new ProtoCore.AST.AssociativeAST.IdentifierNode { Value = ProtoCore.DSASM.Constants.kDotArgMethodName, Name = ProtoCore.DSASM.Constants.kDotArgMethodName };
            funCallNode.Function = funcName;
            funCallNode.Name = ProtoCore.DSASM.Constants.kDotArgMethodName;
            NodeUtils.CopyNodeLocation(funCallNode, lhs);
            int rhsIdx = ProtoCore.DSASM.Constants.kInvalidIndex;
            string lhsName = null;
            if (lhs is ProtoCore.AST.AssociativeAST.IdentifierNode)
            {
                lhsName = (lhs as ProtoCore.AST.AssociativeAST.IdentifierNode).Name;
                if (lhsName == ProtoCore.DSDefinitions.Keyword.This)
                {
                    lhs = new ProtoCore.AST.AssociativeAST.ThisPointerNode();
                }
            }

            if (compileState != null)
            {
                if (argNum >= 0)
                {
                    ProtoCore.DSASM.DynamicFunctionNode dynamicFunctionNode = new ProtoCore.DSASM.DynamicFunctionNode(rhsName, new List<ProtoCore.Type>());
                    compileState.DynamicFunctionTable.functionTable.Add(dynamicFunctionNode);
                    rhsIdx = compileState.DynamicFunctionTable.functionTable.Count - 1;
                }
                else
                {
                    DSASM.DyanmicVariableNode dynamicVariableNode = new DSASM.DyanmicVariableNode(rhsName);
                    compileState.DynamicVariableTable.variableTable.Add(dynamicVariableNode);
                    rhsIdx = compileState.DynamicVariableTable.variableTable.Count - 1;
                }
            }

            // The first param to the dot arg (the pointer or the class name)
            ProtoCore.AST.AssociativeAST.IntNode rhs = new ProtoCore.AST.AssociativeAST.IntNode() { value = rhsIdx.ToString() };
            funCallNode.FormalArguments.Add(lhs);

            // The second param which is the dynamic table index of the function to call
            funCallNode.FormalArguments.Add(rhs);

            // The array dimensions
            ProtoCore.AST.AssociativeAST.ExprListNode arrayDimExperList = new ProtoCore.AST.AssociativeAST.ExprListNode();
            int dimCount = 0;
            if (rhsCall.Function is ProtoCore.AST.AssociativeAST.IdentifierNode)
            {
                // Number of dimensions
                ProtoCore.AST.AssociativeAST.IdentifierNode fIdent = rhsCall.Function as ProtoCore.AST.AssociativeAST.IdentifierNode;
                if (fIdent.ArrayDimensions != null)
                {
                    arrayDimExperList = ProtoCore.Utils.CoreUtils.BuildArrayExprList(fIdent.ArrayDimensions);
                    dimCount = arrayDimExperList.list.Count;
                }
                else if (rhsCall.ArrayDimensions != null)
                {
                    arrayDimExperList = ProtoCore.Utils.CoreUtils.BuildArrayExprList(rhsCall.ArrayDimensions);
                    dimCount = arrayDimExperList.list.Count;
                }
                else
                {
                    arrayDimExperList = new ProtoCore.AST.AssociativeAST.ExprListNode();
                }
            }

            funCallNode.FormalArguments.Add(arrayDimExperList);

            // Number of dimensions
            ProtoCore.AST.AssociativeAST.IntNode dimNode = new ProtoCore.AST.AssociativeAST.IntNode() { value = dimCount.ToString() };
            funCallNode.FormalArguments.Add(dimNode);

            if (argNum >= 0)
            {
                funCallNode.FormalArguments.Add(argList);
                funCallNode.FormalArguments.Add(new ProtoCore.AST.AssociativeAST.IntNode() { value = argNum.ToString() });
            }

            ProtoCore.AST.AssociativeAST.FunctionDotCallNode funDotCallNode = new ProtoCore.AST.AssociativeAST.FunctionDotCallNode(rhsCall);
            funDotCallNode.DotCall = funCallNode;
            funDotCallNode.FunctionCall.Function = rhsCall.Function;

            // Consider the case of "myClass.Foo(a, b)", we will have "DotCall" being
            // equal to "myClass" (in terms of its starting line/column), and "rhsCall"
            // matching with the location of "Foo(a, b)". For execution cursor to cover
            // this whole statement, the final "DotCall" function call node should
            // range from "lhs.col" to "rhs.col".
            //
            NodeUtils.SetNodeEndLocation(funDotCallNode.DotCall, rhsCall);
            NodeUtils.CopyNodeLocation(funDotCallNode, funDotCallNode.DotCall);

            return funDotCallNode;
        }
Ejemplo n.º 25
0
        private static void InsertBinaryOperationMethod(ProtoLanguage.CompileStateTracker compileState, ProtoCore.AST.Node root, Operator op, PrimitiveType r, PrimitiveType op1, PrimitiveType op2, int retRank = 0, int op1rank = 0, int op2rank = 0)
        {
            ProtoCore.AST.AssociativeAST.FunctionDefinitionNode funcDefNode = new ProtoCore.AST.AssociativeAST.FunctionDefinitionNode();
            funcDefNode.access = ProtoCore.DSASM.AccessSpecifier.kPublic;
            funcDefNode.IsAssocOperator = true;
            funcDefNode.IsBuiltIn = true;
            funcDefNode.Name = Op.GetOpFunction(op);
            funcDefNode.ReturnType = new ProtoCore.Type() { Name = compileState.TypeSystem.GetType((int)r), UID = (int)r, rank = retRank, IsIndexable = (retRank > 0)};
            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)op1), UID = (int)op1, rank = op1rank, IsIndexable = (op1rank > 0)}
            });
            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)op2), UID = (int)op2, rank = op2rank, IsIndexable = (op2rank > 0)}
            });
            funcDefNode.Singnature = args;

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

            ProtoCore.AST.AssociativeAST.IdentifierNode lhs = BuildAssocIdentifier(compileState, ProtoCore.DSASM.Constants.kLHS);
            ProtoCore.AST.AssociativeAST.IdentifierNode rhs = BuildAssocIdentifier(compileState, ProtoCore.DSASM.Constants.kRHS);
            body.Body.Add(new ProtoCore.AST.AssociativeAST.BinaryExpressionNode() { LeftNode = _return, Optr = ProtoCore.DSASM.Operator.assign, RightNode = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode() { LeftNode = lhs, RightNode = rhs, Optr = op } });
            funcDefNode.FunctionBody = body;
            (root as ProtoCore.AST.AssociativeAST.CodeBlockNode).Body.Add(funcDefNode);
        }
Ejemplo n.º 26
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;
 }
Ejemplo n.º 27
0
        public CodeGen(ProtoLanguage.CompileStateTracker compileState, ProtoCore.DSASM.CodeBlock parentBlock = null)
            : base(compileState, parentBlock)
        {
            classOffset = 0;

            //  either of these should set the console to flood
            //
            ignoreRankCheck = false;
            emitReplicationGuide = false;

            astNodes = new List<AssociativeNode>();
            globalInstanceProcList = new List<GlobalInstanceProc>();
            setConstructorStartPC = false;

            // Comment Jun: Get the codeblock to use for this codegenerator
            if (compileStateTracker.Options.IsDeltaExecution)
            {
                codeBlock = GetDeltaCompileCodeBlock();
                pc = compileStateTracker.deltaCompileStartPC;
            }
            else
            {
                codeBlock = BuildNewCodeBlock();
            }

            if (null == parentBlock)
            {
                if (!compileStateTracker.Options.IsDeltaExecution)
                {
                    // This is a top level block
                    compileStateTracker.CodeBlockList.Add(codeBlock);
                }
            }
            else
            {
                // TODO Jun: Handle nested codeblock here when we support scoping in the graph

                // This is a nested block

                // parentBlock == codeBlock happens when the core is in
                // delta exectuion and at the same time we create a dynamic
                // code block (e.g., inline condition)
                if  (parentBlock == codeBlock)
                {
                    codeBlock = BuildNewCodeBlock();
                    pc = 0;
                }
                parentBlock.children.Add(codeBlock);
                codeBlock.parent = parentBlock;
            }

            compileStateTracker.CompleteCodeBlockList.Add(codeBlock);
            compilePass = ProtoCore.DSASM.AssociativeCompilePass.kClassName;

            // Bouncing to this language codeblock from a function should immediately set the first instruction as the entry point
            if (ProtoCore.DSASM.Constants.kGlobalScope != globalProcIndex)
            {
                isEntrySet = true;
                codeBlock.instrStream.entrypoint = 0;
            }

            nodeBuilder = new NodeBuilder(compileStateTracker);
            unPopulatedClasses = new Dictionary<int, ClassDeclNode>();

            // For sub code block, say in inline condition, do we need context?
            /*
            if (core.assocCodegen != null)
            {
                context = core.assocCodegen.context;
            }
            */
        }
Ejemplo n.º 28
0
 public NodeBuilder(ProtoLanguage.CompileStateTracker compileState)
 {
     this.compileState = compileState;
 }
Ejemplo n.º 29
0
        public ExecutionMirror Execute(string code, ProtoCore.Core core, out ProtoLanguage.CompileStateTracker outcompileState, bool isTest = true)
        {
            int blockId = ProtoCore.DSASM.Constants.kInvalidIndex;
            ProtoLanguage.CompileStateTracker compileState = outcompileState = 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);
            }

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

            return null;
        }
Ejemplo n.º 30
0
 public DependencyGraph(ProtoLanguage.CompileStateTracker compileState)
 {
     this.compileState = compileState;
     graphList = new List<GraphNode>();
     graphNodeMap = new Dictionary<ulong, List<GraphNode>>();
 }
Ejemplo n.º 31
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 isLangSignValid = compileState.Langverify.Verify(langBlock);

            if (isLangSignValid)
            {
                try
                {
                    ProtoCore.CodeGen oldCodegen = compileState.assocCodegen;

                    if (ProtoCore.DSASM.InterpreterMode.kNormal == compileState.ExecMode)
                    {
                        if ((compileState.IsParsingPreloadedAssembly || compileState.IsParsingCodeBlockNode) && parentBlock == null)
                        {
                            if (compileState.CodeBlockList.Count == 0)
                            {
                                compileState.assocCodegen = new ProtoAssociative.CodeGen(compileState, parentBlock);
                            }
                            else
                            {
                                // We reuse the existing toplevel CodeBlockList's for the procedureTable's
                                // by calling this overloaded constructor - pratapa
                                compileState.assocCodegen = new ProtoAssociative.CodeGen(compileState);
                            }
                        }
                        else
                            compileState.assocCodegen = new ProtoAssociative.CodeGen(compileState, parentBlock);
                    }

                    if (null != compileState.AssocNode)
                    {
                        ProtoCore.AST.AssociativeAST.CodeBlockNode cnode = new ProtoCore.AST.AssociativeAST.CodeBlockNode();
                        cnode.Body.Add(compileState.AssocNode as ProtoCore.AST.AssociativeAST.AssociativeNode);

                        compileState.assocCodegen.context = callContext;

                        blockId = compileState.assocCodegen.Emit((cnode as ProtoCore.AST.AssociativeAST.CodeBlockNode), graphNode);
                    }
                    else
                    {
                        //if not null, Compile has been called from DfsTraverse. No parsing is needed.
                        if (codeBlockNode == null)
                        {
                            System.IO.MemoryStream memstream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(langBlock.body));
                            ProtoCore.DesignScriptParser.Scanner s = new ProtoCore.DesignScriptParser.Scanner(memstream);
                            ProtoCore.DesignScriptParser.Parser p = new ProtoCore.DesignScriptParser.Parser(s, compileState, compileState.builtInsLoaded);
                            p.Parse();

                            // TODO Jun: Set this flag inside a persistent object
                            compileState.builtInsLoaded = true;

                            codeBlockNode = p.root;

                            //compileState.AstNodeList = p.GetParsedASTList(codeBlockNode as ProtoCore.AST.AssociativeAST.CodeBlockNode);
                            List<ProtoCore.AST.Node> astNodes = ProtoCore.Utils.ParserUtils.GetAstNodes(codeBlockNode);
                            compileState.AstNodeList = astNodes;
                        }
                        else
                        {
                            if (!compileState.builtInsLoaded)
                            {
                                // Load the built-in methods manually
                                ProtoCore.Utils.CoreUtils.InsertPredefinedAndBuiltinMethods(compileState, codeBlockNode, false);
                                compileState.builtInsLoaded = true;
                            }
                        }

                        compileState.assocCodegen.context = callContext;

                        //Temporarily change the code block for code gen to the current block, in the case it is an imperative block
                        //CodeGen for ProtoImperative is modified to passing in the core object.
                        ProtoCore.DSASM.CodeBlock oldCodeBlock = compileState.assocCodegen.codeBlock;
                        if (compileState.ExecMode == ProtoCore.DSASM.InterpreterMode.kExpressionInterpreter)
                        {
                            int tempBlockId = compileState.GetCurrentBlockId();

                            ProtoCore.DSASM.CodeBlock tempCodeBlock = compileState.GetCodeBlock(compileState.CodeBlockList, tempBlockId);
                            while (null != tempCodeBlock && tempCodeBlock.blockType != ProtoCore.DSASM.CodeBlockType.kLanguage)
                            {
                                tempCodeBlock = tempCodeBlock.parent;
                            }
                            compileState.assocCodegen.codeBlock = tempCodeBlock;
                        }
                        compileState.assocCodegen.codeBlock.EventSink = sink;
                        if (compileState.BuildStatus.Errors.Count == 0) //if there is syntax error, no build needed
                        {
                             blockId = compileState.assocCodegen.Emit((codeBlockNode as ProtoCore.AST.AssociativeAST.CodeBlockNode), graphNode);
                        }
                        if (compileState.ExecMode == ProtoCore.DSASM.InterpreterMode.kExpressionInterpreter)
                        {
                            blockId = compileState.assocCodegen.codeBlock.codeBlockId;
                            //Restore the code block.
                            compileState.assocCodegen.codeBlock = oldCodeBlock;
                        }
                    }

                    // @keyu: we have to restore asscoCodegen here. It may be
                    // reused later on. Suppose for an inline expression
                    // "x = 1 == 2 ? 3 : 4", we dynamically create assocCodegen
                    // to compile true and false expression in this inline
                    // expression, and if we don't restore assocCodegen, the pc
                    // is totally messed up.
                    //
                    // But if directly replace with old assocCodegen, will it
                    // replace some other useful information? Need to revisit it.
                    //
                    // Also refer to defect IDE-2120.
                    if (oldCodegen != null && compileState.assocCodegen != oldCodegen)
                    {
                        compileState.assocCodegen = oldCodegen;
                    }
                }
                catch (ProtoCore.BuildHaltException e)
                {
            #if DEBUG
                    //compileState.BuildStatus.LogSemanticError(e.errorMsg);
            #endif
                }

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

            return buildSucceeded;
        }