<commit_before>/*
 * File:   Sfuck.cpp
 * Author: <NAME> <<EMAIL>>
 *
 * Created on September 14, 2015, 6:25 PM
 */

#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <time.h>
#include <vector>

using namespace std;

struct store {
    vector< vector<int>  > intBank;
    int index, vindex;
    int sizeX, sizeY;
    bool printAsChar;
    bool notFlaged;
    string storedLoop;

    store() : store(1024, 1024) {}

    store(int sizeX, int sizeY) {
        for (int i = 0; i < sizeY; i++) {
	    vector<int> row;
            for (int j = 0; j < sizeX; j++) {
                row.push_back(0);
            }
	    intBank.push_back(row);
        }
	this->sizeX = sizeX;
	this->sizeY = sizeY;
        index = 0;
        vindex = 0;
        printAsChar = true;
    }

    void getCommand(istream & inputStream);
    void getCommand(char c);
};

void store::getCommand(istream & inputStream) {

    char c = inputStream.get();

    switch (c) {
        case '+':
            intBank[vindex][index]++;
            break;
        case '-':
            intBank[vindex][index]--;
            break;
        case '>':
            if (index == sizeX-1) {
                index = 0;
            } else {
                index++;
            }
            break;
        case '<':
            if (index == 0) {
                index = sizeX-1;
            } else {
                index--;
            }
            break;
        case '^':
            if (vindex == sizeY-1) {
                vindex = 0;
            } else {
                vindex++;
            }
            break;
        case '\\':
            if (vindex == 0) {
                vindex = sizeY-1;
            } else {
                vindex--;
            }
            break;
        case '#':
            index = vindex = 0;
            break;
        case ',':
            intBank[vindex][index] = (int) cin.get();
            break;
        case '.':
            if (printAsChar) {
                cout << (char) intBank[vindex][index];
            } else {
                cout << intBank[vindex][index];
            }
            break;
        case '=':
            if (intBank[vindex][index] == (int) 'x') {
                intBank[vindex][index] = 1;
            } else {
                intBank[vindex][index] = 0;
            }
            break;
        case '?':
            intBank[vindex][index] = rand();
            break;
        case '@':
            printAsChar = !printAsChar;
            break;
        case '~':
            notFlaged = false;
            break;
        case '|':
            if (vindex < sizeY) {
                intBank[vindex][index] = intBank[vindex + 1][index];
            } else {
                intBank[vindex][index] = intBank[0][index];
            }
            break;
        case '}':
            if (index > 0) {
                intBank[vindex][index] = intBank[vindex][index - 1];
            } else {
                intBank[vindex][index] = intBank[vindex][sizeX-1];
            }
            break;
        case '[':
            if (intBank[vindex][index] != 0) {
                while (inputStream.peek() != ']') {
                    storedLoop += inputStream.get();
                }
            } else {
                while (inputStream.get() != ']') {

                }
            }
            break;
        case ']':
            while (intBank[vindex][index] != 0) {
                for (char c : storedLoop) {
                    this->getCommand(c);
                }
            }
            storedLoop = "";
            break;

    }
}

void store::getCommand(char c) {

    switch (c) {
        case '+':
            intBank[vindex][index]++;
            break;
        case '-':
            intBank[vindex][index]--;
            break;
        case '>':
            if (index == sizeX-1) {
                index = 0;
            } else {
                index++;
            }
            break;
        case '<':
            if (index == 0) {
                index = sizeX-1;
            } else {
                index--;
            }
            break;
        case '^':
            if (vindex == sizeY-1) {
                vindex = 0;
            } else {
                vindex++;
            }
            break;
        case '\\':
            if (vindex == 0) {
                vindex = sizeY-1;
            } else {
                vindex--;
            }
            break;
        case '#':
            index = vindex = 0;
            break;
        case ',':
            intBank[vindex][index] = (int) cin.get();
            break;
        case '.':
            if (printAsChar) {
                cout << (char) intBank[vindex][index];
            } else {
                cout << intBank[vindex][index];
            }
            break;
        case '=':
            if (intBank[vindex][index] == (int) 'x') {
                intBank[vindex][index] = 1;
            } else {
                intBank[vindex][index] = 0;
            }
            break;
        case '&':
            if (intBank[vindex][index] == (int) 'x') {
                intBank[vindex][index] = intBank[vindex][index]/2*'x'*'x'+'c';
            } else {
                intBank[vindex][index] = intBank[vindex][index]/2*'x'+'c';
            }
            break;
        case '?':
            intBank[vindex][index] = rand();
            break;
        case '@':
            printAsChar = !printAsChar;
            break;
        case '~':
            notFlaged = false;
            break;
        case '|':
            if (vindex < sizeY-1) {
                intBank[vindex][index] = intBank[vindex + 1][index];
            } else {
                intBank[vindex][index] = intBank[0][index];
            }
            break;
        case '}':
            if (index > 0) {
                intBank[vindex][index] = intBank[vindex][index - 1];
            } else {
                intBank[vindex][index] = intBank[vindex][sizeX-1];
            }
            break;

    }
}

/*
 * 
 */
int main(int argc, char** argv) {

    int x = 1024, y = 1024;
    bool verbose = false;

    for(int i=1; i<argc; i++){
	if(string(argv[i]) == "-S" && i + 2 < argc){
	    x = stoi(argv[i+1]);
	    y = stoi(argv[i+2]);
	    i+=2;
	}
	if(string(argv[i]) == "-V"){
	    verbose = true;
	}
    }


    srand(time(NULL));

    store s(x,y);
    string choice;

    if(verbose){
	cout << "X:" << s.sizeX << "\nY:" << s.sizeY << endl;
    }

    while (true) {
        cout << "SGFY interpreter v0.1.1\n\n------------------------------------------\n"
                << "Enter filename (cin if live interpret): ";
        cin >> choice;
        cin.clear();


        s.notFlaged = true;

        if (choice == "cin") {
            while (s.notFlaged) {
                s.getCommand(cin);
            }
        } else {
            ifstream stream(choice);
            while (!stream.eof()) {
                s.getCommand(stream);
            }
        }

        cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
    }<commit_msg>Modified tape to be much more efficient.<commit_after>/*
 * File:   Sfuck.cpp
 * Author: <NAME> <<EMAIL>>
 *
 * Created on September 14, 2015, 6:25 PM
 */

#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <time.h>
#include <vector>
#include <string>

using namespace std;

struct store {
    vector< vector<int>  > intBank;
    int index, vindex;
    int sizeX, sizeY;
    bool printAsChar;
    bool notFlaged;
    string storedLoop;

    store() : store(1024, 1024) {}

    store(int sizeX, int sizeY) {
		
		intBank.resize(sizeY);
		
        for (int i = 0; i < sizeY; i++) {
	    vector<int> row;
		row.resize(sizeX);
            for (int j = 0; j < sizeX; j++) {
                row[j] = 0;
            }
	    intBank[i] = row;
        }
	this->sizeX = sizeX;
	this->sizeY = sizeY;
        index = 0;
        vindex = 0;
        printAsChar = true;
    }

    void getCommand(istream & inputStream);
    void getCommand(char c);
};

void store::getCommand(istream & inputStream) {

    char c = inputStream.get();

    switch (c) {
        case '+':
            intBank[vindex][index]++;
            break;
        case '-':
            intBank[vindex][index]--;
            break;
        case '>':
            if (index == sizeX-1) {
                index = 0;
            } else {
                index++;
            }
            break;
        case '<':
            if (index == 0) {
                index = sizeX-1;
            } else {
                index--;
            }
            break;
        case '^':
            if (vindex == sizeY-1) {
                vindex = 0;
            } else {
                vindex++;
            }
            break;
        case '\\':
            if (vindex == 0) {
                vindex = sizeY-1;
            } else {
                vindex--;
            }
            break;
        case '#':
            index = vindex = 0;
            break;
        case ',':
            intBank[vindex][index] = (int) cin.get();
            break;
        case '.':
            if (printAsChar) {
                cout << (char) intBank[vindex][index];
            } else {
                cout << intBank[vindex][index];
            }
            break;
        case '=':
            if (intBank[vindex][index] == (int) 'x') {
                intBank[vindex][index] = 1;
            } else {
                intBank[vindex][index] = 0;
            }
            break;
        case '?':
            intBank[vindex][index] = rand();
            break;
        case '@':
            printAsChar = !printAsChar;
            break;
        case '~':
            notFlaged = false;
            break;
        case '|':
            if (vindex < sizeY) {
                intBank[vindex][index] = intBank[vindex + 1][index];
            } else {
                intBank[vindex][index] = intBank[0][index];
            }
            break;
        case '}':
            if (index > 0) {
                intBank[vindex][index] = intBank[vindex][index - 1];
            } else {
                intBank[vindex][index] = intBank[vindex][sizeX-1];
            }
            break;
        case '[':
            if (intBank[vindex][index] != 0) {
                while (inputStream.peek() != ']') {
                    storedLoop += inputStream.get();
                }
            } else {
                while (inputStream.get() != ']') {

                }
            }
            break;
        case ']':
            while (intBank[vindex][index] != 0) {
                for (char c : storedLoop) {
                    this->getCommand(c);
                }
            }
            storedLoop = "";
            break;

    }
}

void store::getCommand(char c) {

    switch (c) {
        case '+':
            intBank[vindex][index]++;
            break;
        case '-':
            intBank[vindex][index]--;
            break;
        case '>':
            if (index == sizeX-1) {
                index = 0;
            } else {
                index++;
            }
            break;
        case '<':
            if (index == 0) {
                index = sizeX-1;
            } else {
                index--;
            }
            break;
        case '^':
            if (vindex == sizeY-1) {
                vindex = 0;
            } else {
                vindex++;
            }
            break;
        case '\\':
            if (vindex == 0) {
                vindex = sizeY-1;
            } else {
                vindex--;
            }
            break;
        case '#':
            index = vindex = 0;
            break;
        case ',':
            intBank[vindex][index] = (int) cin.get();
            break;
        case '.':
            if (printAsChar) {
                cout << (char) intBank[vindex][index];
            } else {
                cout << intBank[vindex][index];
            }
            break;
        case '=':
            if (intBank[vindex][index] == (int) 'x') {
                intBank[vindex][index] = 1;
            } else {
                intBank[vindex][index] = 0;
            }
            break;
        case '&':
            if (intBank[vindex][index] == (int) 'x') {
                intBank[vindex][index] = intBank[vindex][index]/2*'x'*'x'+'c';
            } else {
                intBank[vindex][index] = intBank[vindex][index]/2*'x'+'c';
            }
            break;
        case '?':
            intBank[vindex][index] = rand();
            break;
        case '@':
            printAsChar = !printAsChar;
            break;
        case '~':
            notFlaged = false;
            break;
        case '|':
            if (vindex < sizeY-1) {
                intBank[vindex][index] = intBank[vindex + 1][index];
            } else {
                intBank[vindex][index] = intBank[0][index];
            }
            break;
        case '}':
            if (index > 0) {
                intBank[vindex][index] = intBank[vindex][index - 1];
            } else {
                intBank[vindex][index] = intBank[vindex][sizeX-1];
            }
            break;

    }
}

/*
 * 
 */
int main(int argc, char** argv) {

    int x = 1024, y = 1024;
    bool verbose = false;

    for(int i=1; i<argc; i++){
	if(string(argv[i]) == "-S" && i + 2 < argc){
	    x = stoi(argv[i+1]);
	    y = stoi(argv[i+2]);
	    i+=2;
	}
	if(string(argv[i]) == "-V"){
	    verbose = true;
	}
    }


    srand(time(NULL));

    store s(x,y);
    string choice;

    if(verbose){
	cout << "X:" << s.sizeX << "\nY:" << s.sizeY << endl;
    }

    while (true) {
        cout << "SGFY interpreter\n\n------------------------------------------\n"
                << "Enter filename (cin if live interpret): ";
        cin >> choice;
        cin.clear();


        s.notFlaged = true;

        if (choice == "cin") {
            while (s.notFlaged) {
                s.getCommand(cin);
            }
        } else {
            ifstream stream(choice);
            while (!stream.eof()) {
                s.getCommand(stream);
            }
        }

        cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
    }
{'fraction_non_alphanumeric': 0.15712290502793297, 'fraction_numerical': 0.01026536312849162, 'mean_word_length': 1.0579106193418595, 'pattern_counts': {'":': 0, '<': 90, '<?xml version=': 0, '>': 44, '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': '5114060', 'n_tokens_mistral': 4655, 'n_tokens_neox': 4397, 'n_words': 849}