/*
 * Copyright (c) 2013, Regents of the University of California
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met: 
 * 
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer. 
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution. 
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package edu.uci.python.nodes.loop;

import com.oracle.truffle.api.*;
import com.oracle.truffle.api.dsl.*;
import com.oracle.truffle.api.frame.*;

import edu.uci.python.nodes.*;
import edu.uci.python.nodes.access.*;
import edu.uci.python.runtime.datatype.*;
import edu.uci.python.runtime.exception.*;
import edu.uci.python.runtime.iterator.*;

@NodeChild(value = "iterator", type = GetIteratorNode.class)
public abstract class ForWithLocalTargetNode extends LoopNode {

    @Child protected FrameSlotNode target;

    public ForWithLocalTargetNode(FrameSlotNode target, PNode body) {
        super(body);
        this.target = adoptChild(target);
    }

    protected ForWithLocalTargetNode(ForWithLocalTargetNode previous) {
        this(previous.target, previous.body);
    }

    public PNode getBody() {
        return body;
    }

    public PNode getTarget() {
        return target;
    }

    public abstract PNode getIterator();

    @Specialization
    public Object doPIntegerIterator(VirtualFrame frame, PIntegerIterator iterator) {
        int count = 0;

        try {
            while (true) {
                target.executeWrite(frame, iterator.__nextInt__());
                body.executeVoid(frame);

                if (CompilerDirectives.inInterpreter()) {
                    count++;
                }
            }
        } catch (StopIterationException e) {

        } finally {
            if (CompilerDirectives.inInterpreter()) {
                reportLoopCount(count);
            }
        }

        return PNone.NONE;
    }

    @Specialization
    public Object doPIterator(VirtualFrame frame, PIterator iterator) {
        int count = 0;

        try {
            while (true) {
                target.executeWrite(frame, iterator.__next__());
                body.executeVoid(frame);

                if (CompilerDirectives.inInterpreter()) {
                    count++;
                }
            }
        } catch (StopIterationException e) {

        } finally {
            if (CompilerDirectives.inInterpreter()) {
                reportLoopCount(count);
            }
        }

        return PNone.NONE;
    }

}

@@ -2342,32 +2342,747 @@
  @Specialization
+(order = 0)%0A    public Object doPRange(VirtualFrame frame, PRangeIterator range) %7B%0A        final int start = range.getStart();%0A        final int stop = range.getStop();%0A        final int step = range.getStep();%0A        int count = 0;%0A%0A        try %7B%0A            for (int i = start; i %3C stop; i += step) %7B%0A                target.executeWrite(frame, i);%0A                body.executeVoid(frame);%0A%0A                if (CompilerDirectives.inInterpreter()) %7B%0A                    count++;%0A                %7D%0A            %7D%0A        %7D finally %7B%0A            if (CompilerDirectives.inInterpreter()) %7B%0A                reportLoopCount(count);%0A            %7D%0A        %7D%0A%0A        return PNone.NONE;%0A    %7D%0A%0A    @Specialization(order = 1)
 %0A    public Obje
@@ -3684,16 +3684,27 @@
 lization
+(order = 2)
 %0A    pub

Revert previous change