Ejemplo n.º 1
0
        private static void _genChecks(MacroContext context, [InstantHandle] Func<AstGetSet> retVar,
            AstNode contStmt, AstNode breakStmt)
        {
            var inv = context.Invocation;

            //Generate check for continue
            AstCondition checkCont;
            {
                var contCond = _genCompare(context, retVar(), ReturnVariant.Continue);
                checkCont = new AstCondition(inv.Position, context.CurrentBlock, contCond);
                checkCont.IfBlock.Add(contStmt);
            }

            //Generate check for break
            AstCondition checkBreak;
            {
                var breakCond = _genCompare(context, retVar(), ReturnVariant.Break);
                checkBreak = new AstCondition(inv.Position, context.CurrentBlock, breakCond);
                checkBreak.IfBlock.Add(breakStmt);
            }

            //Connect break-check to continue check
            checkCont.ElseBlock.Add(checkBreak);
            context.Block.Add(checkCont);
        }
Ejemplo n.º 2
0
        private bool _optimizeConditionalReturnExpression(CompilerTarget target)
        {
            var cond = Expression as AstConditionalExpression;
            if (cond == null)
                return false;

            //  return  if( cond )
            //              expr1
            //          else
            //              expr2
            var retif = new AstCondition(Position, target.CurrentBlock, cond.Condition, cond.IsNegative);

            var ret1 = new AstReturn(File, Line, Column, ReturnVariant)
                {
                    Expression = cond.IfExpression
                };
            retif.IfBlock.Add(ret1);

            var ret2 = new AstReturn(File, Line, Column, ReturnVariant)
                {
                    Expression = cond.ElseExpression
                };
            //not added to the condition

            retif.EmitEffectCode(target); //  if( cond )
            //      return expr1
            ret2.EmitEffectCode(target); //  return expr2

            //ret1 and ret2 will continue optimizing
            return true;
        }