ooooooo wwweeeeee

main
Brett 2023-11-22 17:13:31 -05:00
parent a21a5860f7
commit 1c6a6965e6
8 changed files with 24 additions and 22 deletions

View File

@ -11,6 +11,7 @@
#include <cstdint> #include <cstdint>
#include <cstring> #include <cstring>
#include <string> #include <string>
#include <bf_tokenizer.h>
class brainfuck_interpreter class brainfuck_interpreter
{ {
@ -25,27 +26,26 @@ class brainfuck_interpreter
brainfuck_interpreter(): _size(30000), _dp(0), _data(new char[_size]) brainfuck_interpreter(): _size(30000), _dp(0), _data(new char[_size])
{std::memset(_data, 0, _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 -= amount;
_dp--;
} }
void increment() void increment(char amount = 1)
{ {
check_size(); check_size();
_data[_dp]++; _data[_dp] += amount;
} }
void decrement() void decrement(char amount = 1)
{ {
check_size(); check_size();
_data[_dp]--; _data[_dp] -= amount;
} }
template<typename OutStream> template<typename OutStream>
@ -70,5 +70,6 @@ class brainfuck_interpreter
}; };
void interpret_bf(const std::string& program); void interpret_bf(const std::string& program);
void interpret_bf(bf_tokenizer& tokenizer);
#endif //BRAINFUCK_MISC_BF_INTERPRETER_H #endif //BRAINFUCK_MISC_BF_INTERPRETER_H

View File

@ -11,6 +11,6 @@
#include <bf_tokenizer.h> #include <bf_tokenizer.h>
#include <fstream> #include <fstream>
void codegen(tokenizer& tokenizer, std::ostream& out); void codegen(bf_tokenizer& tokenizer, std::ostream& out);
#endif //BRAINFUCK_MISC_BF_MIPS_CODEGEN_H #endif //BRAINFUCK_MISC_BF_MIPS_CODEGEN_H

View File

@ -32,13 +32,9 @@ struct token_t
explicit token_t(bf_token type, int64_t offset = 1): type(type), offset(offset) explicit token_t(bf_token type, int64_t offset = 1): type(type), offset(offset)
{} {}
}; };
typedef std::optional<std::reference_wrapper<const token_t>> optional_token; class bf_tokenizer
class tokenizer
{ {
private: private:
std::vector<token_t> tokens; std::vector<token_t> tokens;
@ -50,7 +46,7 @@ class tokenizer
void bf_name(); void bf_name();
public: public:
explicit tokenizer(const std::string& program) explicit bf_tokenizer(const std::string& program)
{ {
tokenize(program); tokenize(program);
bf_name(); bf_name();

@ -1 +1 @@
Subproject commit 06f87c973415f8344fcc56b5f13bc12e46984aa9 Subproject commit b4a7ee403560f2413dc4983cf56dae74c14e926f

View File

@ -63,6 +63,11 @@ void interpret_bf(const std::string& program)
} }
} }
void interpret_bf(bf_tokenizer& tokenizer)
{
}
void brainfuck_interpreter::check_size() void brainfuck_interpreter::check_size()
{ {
if (_dp >= _size) if (_dp >= _size)

View File

@ -24,7 +24,7 @@ bf:
void process_print(const std::vector<token_t>& tokens, size_t index); void process_print(const std::vector<token_t>& tokens, size_t index);
void codegen(tokenizer& tokenizer, std::ostream& out) void codegen(bf_tokenizer& tokenizer, std::ostream& out)
{ {
out << preamble; out << preamble;
if (!tokenizer.hasNext()) if (!tokenizer.hasNext())

View File

@ -55,7 +55,7 @@ class characterizer
} }
}; };
void tokenizer::tokenize(const std::string& program) void bf_tokenizer::tokenize(const std::string& program)
{ {
characterizer tk{program}; characterizer tk{program};
while (tk.hasNext()) 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; size_t search_index = 0;
while (search_index < tokens.size()) while (search_index < tokens.size())
@ -127,7 +127,7 @@ inline void tabulate(signed long long v)
std::cout << '\t'; std::cout << '\t';
} }
void tokenizer::print(size_t index) void bf_tokenizer::print(size_t index)
{ {
signed long long sp = 0; signed long long sp = 0;
while (index < tokens.size()) while (index < tokens.size())

View File

@ -16,7 +16,7 @@ int main(int argc, const char** argv)
std::ofstream out{"../mips2.asm"}; std::ofstream out{"../mips2.asm"};
tokenizer tokenizer(program); bf_tokenizer tokenizer(program);
codegen(tokenizer, out); codegen(tokenizer, out);
//interpret_bf(program); //interpret_bf(program);