<commit_before>package language.statements;

import java.util.List;

import language.Function;
import language.expressions.Storeable;
import model.LabelType;
import util.Toolbox;

public class ForStatement implements Statement {

	public ForStatement(Storeable storeable, int start, int end, int step, SequenceStatement body) {
		this.storeable = storeable;
		this.body = body;
		this.start = start;
		this.end = end;
		this.step = step;
	}
	
	
	private final Storeable storeable;
	private final int start;
	private final int end;
	private final int step;	
	private List<String> labels;
	private final SequenceStatement body;

	
	public Storeable getStoreable() {
		return storeable;
	}
	
	public int getStart() {
		return start;
	}
	
	public int getEnd() {
		return end;
	}
	
	public int getStep() {
		return step;
	}
	
	public List<String> getLabels() {
		return this.labels;
	}

	public SequenceStatement getBody() {
		return body;
	}

	
	public void setLabels(List<String> labels) {
		this.labels = labels;
	}


	
	private Function function;
	
	
	@Override
	public Function getFunction() {
		return function;
	}

	
	@Override
	public void setFunction(Function function) {
		this.function = function;
	}

	
	
	@Override
	public void compile() { // TODO Reread HEAP!
		String label1 = getFunction().requestLabel(LabelType.FOR);
		String label2 = getFunction().requestLabel(LabelType.FOR);
		Toolbox helper = new Toolbox();
		helper.setStatement(this);
		helper.addOutput("HIA R0, " + storeable.evaluate());
		helper.addOutput("BIG " + Integer.toString(start) + ", " + "HEAP"); // TODO Reread HEAP
		helper.addOutput("BST R0");
		helper.addOutput("HIA R0, HEAP");
		helper.addOutput("OPT.w R0, 1");
		helper.addOutput("BIG R0, HEAP");
		helper.addOutput("HST R0");
		helper.addOutput(label1 + ": NWL");
		helper.addOutput("VGL R7"); // TODO Reread HEAP
		helper.addOutput("VSP GRG, " + label2);
		getBody().compile();
		helper.addOutput("HIA R7");
		helper.addOutput("OPT");
		helper.addOutput("BIG R7");
		getFunction().getProgram().addOutput("SPR " + label1);
		helper.addOutput(label2 + ": NWL");
	}
	
}<commit_msg>Fixed for loop implementation.<commit_after>package language.statements;

import java.util.List;

import language.Compound;
import language.Function;
import language.expressions.Expression;
import language.expressions.Storeable;
import model.LabelType;
import util.Toolbox;

public class ForStatement implements Statement {

	public ForStatement(Storeable storeable, Expression start, Expression end, Expression step, Compound condition, 
			SequenceStatement body) {
		this.storeable = storeable;
		this.body = body;
		this.start = start;
		this.end = end;
		this.step = step;
		this.condition = condition;
	}
	
	
	private final Storeable storeable;
	private final Expression start;
	private final Expression end;
	private final Expression step;	
	private final Compound condition;
	private List<String> labels;
	private final SequenceStatement body;

	
	public Storeable getStoreable() {
		return storeable;
	}
	
	public Expression getStart() {
		return start;
	}
	
	public Expression getEnd() {
		return end;
	}
	
	public Expression getStep() {
		return step;
	}
	
	public List<String> getLabels() {
		return this.labels;
	}

	public SequenceStatement getBody() {
		return body;
	}

	
	public void setLabels(List<String> labels) {
		this.labels = labels;
	}


	
	private Function function;
	
	
	@Override
	public Function getFunction() {
		return function;
	}

	
	@Override
	public void setFunction(Function function) {
		this.function = function;
	}

	
	
	@Override
	public void compile() { // TODO Fix this.
		String label1 = getFunction().requestLabel(LabelType.FOR);
		String label2 = getFunction().requestLabel(LabelType.FOR);
		Toolbox helper = new Toolbox();
		helper.setStatement(this);
		helper.addOutput(getStoreable().store(getStart()));
		helper.addOutput(label1 + "BST R0");
		helper.addOutput("HIA R0, " + getStoreable().evaluate());
		helper.addOutput("VGL R0, " + getEnd().evaluate());
		helper.addOutput("HST R0");
		helper.addOutput("VSP " + condition.compile() + label2);
		getBody().compile();
		helper.addOutput("SPR " + label1);
		helper.addOutput(label2 + ": NWL");
	}
	
}
{'fraction_non_alphanumeric': 0.11927910837087977, 'fraction_numerical': 0.006165520512212474, 'mean_word_length': 4.239751552795031, 'pattern_counts': {'":': 3, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7058906', 'n_tokens_mistral': 1448, 'n_tokens_neox': 1306, 'n_words': 339}