Exemplo n.º 1
0
        private static Ast.Macro DoWhileMacro()
        {
            var def   = Macro.GetMacroDefinition(typeof(Macro <int, int, Macro <int, T>, Macro <T, bool>, T>));
            var ind   = Macro.GenUniqueVar(typeof(int), "ind");
            var cont  = Macro.GenUniqueVar(typeof(bool), "cont");
            var start = Ast.MPRef(def.Parameters[0]);
            var cond  = Ast.Op("{0} && {1}",
                               Ast.Op("{0} < {1}", Ast.VRef(ind), Ast.MPRef(def.Parameters[1])), Ast.VRef(cont));
            var incr      = Ast.Op("{0}++", Ast.VRef(ind));
            var body      = (def.Parameters[2] as Ast.MacroDefParam).Definition;
            var whileCond = (def.Parameters[3] as Ast.MacroDefParam).Definition;

            return(Ast.Mac(def.Parameters, def.Result, Ast.Blk(
                               Ast.DeclVar(cont, Ast.Lit("true")),
                               Ast.For(ind, start, cond, incr, Ast.Blk(
                                           Ast.MCall(body, def.Result, Ast.VRef(ind)),
                                           Ast.MCall(whileCond, cont, Ast.VRef(def.Result)))))));
        }