<commit_before>package org.segin.bfinterpreter;

/**
 * Created by Kirn on 7/27/14.
 */
public class Interpreter {
    private Tape tape;
    private int pc;
    private UserIO io;
    public int[] stack;

    public Interpreter() {
        tape = new Tape();
        pc = 0;
    }

    public void setIO (UserIO io) {
        this.io = io;
    }

    public void run(String code) {
        String ocode = optimize(code);

        for (pc = 0; pc < code.length(); pc++) {
            switch(code.charAt(pc)) {
                case '>':
                    tape.forward();
                    break;
                case '<':
                    tape.reverse();
                    break;
                case '+':
                    tape.inc();
                    break;
                case '-':
                    tape.dec();
                    break;
                case '.':
                    tape.set(io.input());
                    break;
                case ',':
                    io.output(tape.get());
                    break;
                case '[':
                    if (tape.get() == 0) {
                        int i = 1;
                        while (i > 0) {
                            char c = code.charAt(++pc);
                            if (c == '[')
                                i++;
                            else if (c == ']')
                                i--;
                        }
                    }
                    break;
                case ']':
                    if (tape.get() == 0) {
                        int i = 1;
                        while (i > 0) {
                            char c = code.charAt(--pc);
                            if (c == '[')
                                i--;
                            else if (c == ']')<commit_msg>Fixed opcodes, more work for upcoming optimizer<commit_after>package org.segin.bfinterpreter;

/**
 * Created by Kirn on 7/27/14.
 */
public class Interpreter {
    private Tape tape;
    private int pc;
    private UserIO io;
    public int[] stack;

    public Interpreter() {
        tape = new Tape();
        pc = 0;
    }

    public void setIO (UserIO io) {
        this.io = io;
    }

    public void run(String code) {
        String ocode = optimize(code);

        for (pc = 0; pc < code.length(); pc++) {
            switch(ocode.charAt(pc)) {
                case '>':
                    tape.forward();
                    break;
                case '<':
                    tape.reverse();
                    break;
                case '+':
                    tape.inc();
                    break;
                case '-':
                    tape.dec();
                    break;
                case ',':
                    tape.set(io.input());
                    break;
                case '.':
                    io.output(tape.get());
                    break;
                case '[':
                    if (tape.get() == 0) {
                        int i = 1;
                        while (i > 0) {
                            char c = ocode.charAt(++pc);
                            if (c == '[')
                                i++;
                            else if (c == ']')
                                i--;
                        }
                    }
                    break;
                case ']':
                    if (tape.get() == 0) {
                        int i = 1;
                        while (i > 0) {
                            char c = ocode.charAt(--pc);
                            if (c == '[')
                                i--;
                            else if (c == ']')
{'fraction_non_alphanumeric': 0.11641791044776119, 'fraction_numerical': 0.007055630936227951, 'mean_word_length': 0.6536563481381785, 'pattern_counts': {'":': 0, '<': 7, '<?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': '254140', 'n_tokens_mistral': 973, 'n_tokens_neox': 890, 'n_words': 222}