Exemplo n.º 1
0
        public AssociativeCodeGen(Core coreObj, ProtoCore.DSASM.CodeBlock parentBlock = null)
            : base(coreObj, 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,
                core.CodeBlockIndex,
                new ProtoCore.DSASM.SymbolTable("associative lang block", core.RuntimeTableIndex),
                new ProtoCore.DSASM.ProcedureTable(core.RuntimeTableIndex),
                false,
                core);

            ++core.CodeBlockIndex;
            ++core.RuntimeTableIndex;

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

            compilePass = ProtoCore.DSASM.AssociativeCompilePass.kClassName;
        }
Exemplo n.º 2
0
        public int Emit(CodeBlockNode codeblocknode)
        {
            bool isTopBlock = null == codeBlock.parent;
            if (!isTopBlock)
            {
                // If this is an inner block where there can be no classes, we can start at parsing at the global function state
                compilePass = ProtoCore.DSASM.AssociativeCompilePass.kGlobalFuncSig;
            }

            if (codeBlock.parent != null)
                CodeRangeTable.AddCodeBlockRangeEntry(codeBlock.codeBlockId,
                    codeblocknode.line,
                    codeblocknode.col,
                    codeblocknode.endLine,
                    codeblocknode.endCol,
                    core.CurrentDSFileName);
            else
                CodeRangeTable.AddCodeBlockRangeEntry(codeBlock.codeBlockId,
                    0, 0, int.MaxValue, int.MaxValue, core.CurrentDSFileName);

            ProtoCore.Type inferedType = new ProtoCore.Type();
            while (ProtoCore.DSASM.AssociativeCompilePass.kDone != compilePass)
            {
                foreach (AssociativeNode node in codeblocknode.Body)
                {
                    inferedType = new ProtoCore.Type();
                    inferedType.UID = (int)ProtoCore.PrimitiveType.kTypeVar;
                    inferedType.IsIndexable = false;

                    //
                    // TODO Jun:    Handle stand alone language blocks
                    //              Integrate the subPass into a proper pass
                    //
                    if (node is LanguageBlockNode)
                    {
                        // Build a binaryn node with a temporary lhs for every stand-alone language block
                        IdentifierNode iNode = new IdentifierNode()
                        {
                            Value = ProtoCore.DSASM.Constants.kTempLangBlock,
                            Name = ProtoCore.DSASM.Constants.kTempLangBlock,
                            datatype = core.TypeSystem.BuildTypeObject(PrimitiveType.kTypeVar, false)
                        };
                        BinaryExpressionNode langBlockNode = new BinaryExpressionNode();
                        langBlockNode.LeftNode = iNode;
                        langBlockNode.Optr = ProtoCore.DSASM.Operator.assign;
                        langBlockNode.RightNode = node;

                        DfsTraverse(langBlockNode, ref inferedType, false, null, ProtoCore.DSASM.AssociativeSubCompilePass.kUnboundIdentifier);
                        //DfsTraverse(node, ref inferedType, false, null, ProtoCore.DSASM.AssociativeSubCompilePass.kNone);
                    }
                    else
                    {
                        DfsTraverse(node, ref inferedType, false, null, ProtoCore.DSASM.AssociativeSubCompilePass.kUnboundIdentifier);
                    }
                }
                compilePass++;

                // We have compiled all classes
                if (compilePass == ProtoCore.DSASM.AssociativeCompilePass.kGlobalScope && isTopBlock)
                {
                    EmitFunctionCallToInitStaticProperty(codeblocknode.Body);
                }
            }
            core.InferedType = inferedType;

            return codeBlock.codeBlockId;
        }