From 1c6a6965e65bdf4ce1121e62f9305ea14aa0419c Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Wed, 22 Nov 2023 17:13:31 -0500 Subject: [PATCH] ooooooo wwweeeeee --- include/bf_interpreter.h | 19 ++++++++++--------- include/bf_mips_codegen.h | 2 +- include/bf_tokenizer.h | 8 ++------ libraries/BLT | 2 +- src/bf_interpreter.cpp | 5 +++++ src/bf_mips_codegen.cpp | 2 +- src/bf_tokenizer.cpp | 6 +++--- src/main.cpp | 2 +- 8 files changed, 24 insertions(+), 22 deletions(-) diff --git a/include/bf_interpreter.h b/include/bf_interpreter.h index 2706833..14d3045 100644 --- a/include/bf_interpreter.h +++ b/include/bf_interpreter.h @@ -11,6 +11,7 @@ #include #include #include +#include class brainfuck_interpreter { @@ -25,27 +26,26 @@ class brainfuck_interpreter brainfuck_interpreter(): _size(30000), _dp(0), _data(new char[_size]) {std::memset(_data, 0, _size);} - void increment_dp() + void increment_dp(size_t amount = 1) { - _dp++; + _dp += amount; } - void decrement_dp() + void decrement_dp(size_t amount = 1) { - if (_dp != 0) - _dp--; + _dp -= amount; } - void increment() + void increment(char amount = 1) { check_size(); - _data[_dp]++; + _data[_dp] += amount; } - void decrement() + void decrement(char amount = 1) { check_size(); - _data[_dp]--; + _data[_dp] -= amount; } template @@ -70,5 +70,6 @@ class brainfuck_interpreter }; void interpret_bf(const std::string& program); +void interpret_bf(bf_tokenizer& tokenizer); #endif //BRAINFUCK_MISC_BF_INTERPRETER_H diff --git a/include/bf_mips_codegen.h b/include/bf_mips_codegen.h index 3d81314..3d20b1d 100644 --- a/include/bf_mips_codegen.h +++ b/include/bf_mips_codegen.h @@ -11,6 +11,6 @@ #include #include -void codegen(tokenizer& tokenizer, std::ostream& out); +void codegen(bf_tokenizer& tokenizer, std::ostream& out); #endif //BRAINFUCK_MISC_BF_MIPS_CODEGEN_H diff --git a/include/bf_tokenizer.h b/include/bf_tokenizer.h index 266aa55..a89e02c 100644 --- a/include/bf_tokenizer.h +++ b/include/bf_tokenizer.h @@ -32,13 +32,9 @@ struct token_t explicit token_t(bf_token type, int64_t offset = 1): type(type), offset(offset) {} - - }; -typedef std::optional> optional_token; - -class tokenizer +class bf_tokenizer { private: std::vector tokens; @@ -50,7 +46,7 @@ class tokenizer void bf_name(); public: - explicit tokenizer(const std::string& program) + explicit bf_tokenizer(const std::string& program) { tokenize(program); bf_name(); diff --git a/libraries/BLT b/libraries/BLT index 06f87c9..b4a7ee4 160000 --- a/libraries/BLT +++ b/libraries/BLT @@ -1 +1 @@ -Subproject commit 06f87c973415f8344fcc56b5f13bc12e46984aa9 +Subproject commit b4a7ee403560f2413dc4983cf56dae74c14e926f diff --git a/src/bf_interpreter.cpp b/src/bf_interpreter.cpp index c922ec8..bdf614d 100644 --- a/src/bf_interpreter.cpp +++ b/src/bf_interpreter.cpp @@ -63,6 +63,11 @@ void interpret_bf(const std::string& program) } } +void interpret_bf(bf_tokenizer& tokenizer) +{ + +} + void brainfuck_interpreter::check_size() { if (_dp >= _size) diff --git a/src/bf_mips_codegen.cpp b/src/bf_mips_codegen.cpp index 5fe8567..1a0df4b 100644 --- a/src/bf_mips_codegen.cpp +++ b/src/bf_mips_codegen.cpp @@ -24,7 +24,7 @@ bf: void process_print(const std::vector& tokens, size_t index); -void codegen(tokenizer& tokenizer, std::ostream& out) +void codegen(bf_tokenizer& tokenizer, std::ostream& out) { out << preamble; if (!tokenizer.hasNext()) diff --git a/src/bf_tokenizer.cpp b/src/bf_tokenizer.cpp index c016ecf..35e4247 100644 --- a/src/bf_tokenizer.cpp +++ b/src/bf_tokenizer.cpp @@ -55,7 +55,7 @@ class characterizer } }; -void tokenizer::tokenize(const std::string& program) +void bf_tokenizer::tokenize(const std::string& program) { characterizer tk{program}; while (tk.hasNext()) @@ -95,7 +95,7 @@ void tokenizer::tokenize(const std::string& program) } } -void tokenizer::bf_name() +void bf_tokenizer::bf_name() { size_t search_index = 0; while (search_index < tokens.size()) @@ -127,7 +127,7 @@ inline void tabulate(signed long long v) std::cout << '\t'; } -void tokenizer::print(size_t index) +void bf_tokenizer::print(size_t index) { signed long long sp = 0; while (index < tokens.size()) diff --git a/src/main.cpp b/src/main.cpp index 5242e2c..1e89b75 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,7 +16,7 @@ int main(int argc, const char** argv) std::ofstream out{"../mips2.asm"}; - tokenizer tokenizer(program); + bf_tokenizer tokenizer(program); codegen(tokenizer, out); //interpret_bf(program);