Exemple #1
0
        public void Emit(List <HRMCode> codes, Dictionary <string, int> vtab, CompileTimeVars ctv)
        {
            HashSet <int> prevBreakJmp    = ctv.BreakLoopJump;
            HashSet <int> prevContinueJmp = ctv.ContinueLoopJump;

            ctv.BreakLoopJump    = new HashSet <int>();
            ctv.ContinueLoopJump = new HashSet <int>();

            if (cond.IsConstantExpression)
            {
                if (cond.ConstantResult)
                {
                    int jmpLab = ctv.JumpLabel++;
                    codes.Add(new HRMCode(HRMInstr.Lab, jmpLab));
                    loop.Emit(codes, vtab, ctv);
                    foreach (var cj in ctv.ContinueLoopJump)
                    {
                        codes.Add(new HRMCode(HRMInstr.Lab, cj));
                    }
                    codes.Add(new HRMCode(HRMInstr.Jmp, jmpLab));
                    foreach (var bkj in ctv.BreakLoopJump)
                    {
                        codes.Add(new HRMCode(HRMInstr.Lab, bkj));
                    }
                }
                else
                {
                    loop.Emit(codes, vtab, ctv);
                    foreach (var cj in ctv.ContinueLoopJump)
                    {
                        codes.Add(new HRMCode(HRMInstr.Lab, cj));
                    }
                    foreach (var bkj in ctv.BreakLoopJump)
                    {
                        codes.Add(new HRMCode(HRMInstr.Lab, bkj));
                    }
                }
            }
            else
            {
                //if (cond.Comparer == "==" || cond.Comparer == "!=")
                //    EmitEqu(codes, vtab, ctv);
                //else
                //    EmitRel(codes, vtab, ctv);
            }

            ctv.BreakLoopJump    = prevBreakJmp;
            ctv.ContinueLoopJump = prevContinueJmp;
        }
        public List <HRMCode> Emit()
        {
            List <HRMCode> codes = new List <HRMCode>();

            block.Emit(codes, varTab, ctv);
            return(codes);
        }
 public void Emit(List <HRMCode> codes, Dictionary <string, int> vtab, CompileTimeVars ctv)
 {
     if (cond.IsConstantExpression)
     {
         if (cond.ConstantResult)
         {
             ifBlock?.Emit(codes, vtab, ctv);
         }
         else
         {
             elseBlock?.Emit(codes, vtab, ctv);
         }
     }
     else if (cond.Comparer == "==" || cond.Comparer == "!=")
     {
         EmitEqu(codes, vtab, ctv);
     }
     else
     {
         EmitRel(codes, vtab, ctv);
     }
 }