예제 #1
0
        public override int Emit(ProtoCore.AST.Node codeBlockNode, ProtoCore.AssociativeGraph.GraphNode graphNode = null)
        {
            compileStateTracker.startPC = this.pc;
            if (compileStateTracker.ExecMode == ProtoCore.DSASM.InterpreterMode.kExpressionInterpreter)
            {
                return EmitExpressionInterpreter(codeBlockNode);
            }

            this.localCodeBlockNode = codeBlockNode;
            ProtoCore.AST.ImperativeAST.CodeBlockNode codeblock = codeBlockNode as ProtoCore.AST.ImperativeAST.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.ImperativeCompilePass.kGlobalFuncSig;
            }

            bool hasReturnStatement = false;
            ProtoCore.Type type = new ProtoCore.Type();
            while (ProtoCore.DSASM.ImperativeCompilePass.kDone != compilePass)
            {
                foreach (ImperativeNode node in codeblock.Body)
                {
                    type = new ProtoCore.Type();
                    type.UID = (int)PrimitiveType.kTypeVar;
                    type.IsIndexable = false;

                    if (node is LanguageBlockNode)
                    {
                        // Build a binary node with a temporary lhs for every stand-alone language block
                        var iNode = nodeBuilder.BuildIdentfier(compileStateTracker.GenerateTempLangageVar());
                        var langBlockNode = nodeBuilder.BuildBinaryExpression(iNode, node);
                        DfsTraverse(langBlockNode, ref type, false, graphNode);
                    }
                    else
                    {
                        DfsTraverse(node, ref type, false, graphNode);
                    }

                    if (ProtoCore.Utils.NodeUtils.IsReturnExpressionNode(node))
                        hasReturnStatement = true;
                }
                if (compilePass == ProtoCore.DSASM.ImperativeCompilePass.kGlobalScope && !hasReturnStatement)
                {
                    EmitReturnNull();
                }

                compilePass++;
            }

            compileStateTracker.InferedType = type;

            if (compileStateTracker.AsmOutput != Console.Out)
            {
                compileStateTracker.AsmOutput.Flush();
            }

            this.localCodeBlockNode = null;
            return codeBlock.codeBlockId;
        }
예제 #2
0
        private int EmitExpressionInterpreter(ProtoCore.AST.Node codeBlockNode)
        {
            compileStateTracker.startPC = this.pc;
            compilePass = ProtoCore.DSASM.ImperativeCompilePass.kGlobalScope;
            ProtoCore.AST.ImperativeAST.CodeBlockNode codeblock = codeBlockNode as ProtoCore.AST.ImperativeAST.CodeBlockNode;

            ProtoCore.Type inferedType = new ProtoCore.Type();
            foreach (ImperativeNode node in codeblock.Body)
            {
                inferedType = new ProtoCore.Type();
                inferedType.UID = (int)ProtoCore.PrimitiveType.kTypeVar;
                inferedType.IsIndexable = false;

                DfsTraverse(node, ref inferedType);

                BinaryExpressionNode binaryNode = node as BinaryExpressionNode;
            }
            compileStateTracker.InferedType = inferedType;

            this.pc = compileStateTracker.startPC;

            return codeBlock.codeBlockId;
        }
예제 #3
0
        private int EmitExpressionInterpreter(ProtoCore.AST.Node codeBlockNode)
        {
            core.startPC = this.pc;
            compilePass = ProtoCore.DSASM.ImperativeCompilePass.kGlobalScope;
            ProtoCore.AST.ImperativeAST.CodeBlockNode codeblock = codeBlockNode as ProtoCore.AST.ImperativeAST.CodeBlockNode;

            ProtoCore.Type inferedType = new ProtoCore.Type();
            foreach (ImperativeNode node in codeblock.Body)
            {
                inferedType = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeVar, 0);

                DfsTraverse(node, ref inferedType);

                BinaryExpressionNode binaryNode = node as BinaryExpressionNode;
            }
            core.InferedType = inferedType;

            this.pc = core.startPC;

            return codeBlock.codeBlockId;
        }