Ejemplo n.º 1
0
        protected internal override void VisitAST(ForStmtAST node)
        {
            this.Visit(node.PreRun); // init
            var(postLabel, endLabel) = OpenLoop();
            var beginLabel = Ins.CreateLabel();

            GenCode.Add(Ins.Label(beginLabel));
            this.Visit(node.InfLoop.Cond);
            // repeat's logic is opposite to for
            if (node.NodeType == ASTType.Repeat)
            {
                GenCode.Add(Ins.Not());
            }
            GenCode.Add(Ins.Fjp(endLabel));
            // body
            this.Visit(node.InfLoop.Body);
            // post run
            GenCode.Add(Ins.Label(postLabel));
            this.Visit(node.PostRun);
            // jump to cond
            GenCode.Add(Ins.Ujp(beginLabel));
            GenCode.Add(Ins.Label(endLabel));

            CloseLoop();
        }
Ejemplo n.º 2
0
        protected internal override void VisitAST(IfStmtAST node)
        {
            var    elseLabel = Ins.CreateLabel();
            var    endLabel  = Ins.CreateLabel();
            Branch ifBranch  = node.Branches.First();

            this.Visit(ifBranch.Cond);
            GenCode.Add(Ins.Fjp(elseLabel));
            this.Visit(ifBranch.Body);

            GenCode.Add(Ins.Ujp(endLabel));
            GenCode.Add(Ins.Label(elseLabel));

            this.Visit(node.ElseBranch?.Body);
            GenCode.Add(Ins.Label(endLabel));
        }
Ejemplo n.º 3
0
        protected internal override void VisitAST(RepeatStmtAST node)
        {
            var(beginLabel, endLabel) = OpenLoop();
            GenCode.Add(Ins.Label(beginLabel));

            this.Visit(node.InfLoop.Body);

            // repeat's logic is opposite to for
            this.Visit(node.InfLoop.Cond);
            GenCode.Add(Ins.Not());

            GenCode.Add(Ins.Fjp(endLabel));
            GenCode.Add(Ins.Ujp(beginLabel));
            GenCode.Add(Ins.Label(endLabel));

            CloseLoop();
        }