From f7015bc23d0741f6c6f4570bbea7cea21a0f1617 Mon Sep 17 00:00:00 2001 From: bubba2k <64813843+bubba2k@users.noreply.github.com> Date: Wed, 17 Nov 2021 19:29:48 +0100 Subject: [PATCH 01/12] Create README.md --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..4a7d9dd --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# The Bisquit Programming Language + +Bisquit is a first attempt at designing and implementing a simple, interpreted language; Drawing inspiration from typical assembly languages and BASIC. +For a quick tour of the language, check the PDF in the /doc/ directory, and check out the the supplied example programs. + +To build the interpreter, go to the root of the project directory and do: + + mkdir build && cd build + cmake .. + make + +The bisquit_interpreter executable will then be built. From 3eaf121c2cc774cefe5b3bb14df5c8428aa41e4c Mon Sep 17 00:00:00 2001 From: bubba2k <64813843+bubba2k@users.noreply.github.com> Date: Wed, 17 Nov 2021 19:35:15 +0100 Subject: [PATCH 02/12] bugfix --- examples/test.bisq | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/test.bisq b/examples/test.bisq index 73e3abc..e7a83d5 100644 --- a/examples/test.bisq +++ b/examples/test.bisq @@ -1,5 +1,5 @@ PRINT "Hello World, this is a number: " 15 -ASSIGN number 15 +ASSIGN 15 number PRINT "Let's double it's value, shall we?" ADD number number number PRINT "There we go: " number From f9dc28173e48e639141149805c86f888b05c4d7b Mon Sep 17 00:00:00 2001 From: Lauchmelder Date: Wed, 24 Nov 2021 14:28:29 +0100 Subject: [PATCH 03/12] Added some visual studio directories --- .gitignore | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 378eac2..007475c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ -build +[Bb]uild/ +[Oo]ut/ +.vs/ + +*.json From 5d6ed9d504fd09a3fde4973f84e00bdecef0fad2 Mon Sep 17 00:00:00 2001 From: Lauchmelder Date: Wed, 24 Nov 2021 14:28:53 +0100 Subject: [PATCH 04/12] added --- src/runtime.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/runtime.cpp b/src/runtime.cpp index afa1024..2980047 100644 --- a/src/runtime.cpp +++ b/src/runtime.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "runtime.hpp" #include "exceptions.hpp" From 44a7ea539dd9db2ca0590b10bcfd324e88721eaf Mon Sep 17 00:00:00 2001 From: Lauchmelder Date: Wed, 24 Nov 2021 14:30:32 +0100 Subject: [PATCH 05/12] fixed class/struct mismatch --- src/common.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common.hpp b/src/common.hpp index 1862394..ee56cb5 100644 --- a/src/common.hpp +++ b/src/common.hpp @@ -20,9 +20,9 @@ enum ValueType // some prototypes struct Token; -class Instruction; +struct Instruction; struct Keyword; -class Runtime; +struct Runtime; const std::string resolve_TokenType_str(enum TokenType); const std::string resolve_ValueType_str(enum ValueType); From d63dbea5fbeb9c1ae9919213a9eec37332b9424c Mon Sep 17 00:00:00 2001 From: Lauchmelder Date: Wed, 24 Nov 2021 14:34:05 +0100 Subject: [PATCH 06/12] fixed conversion warnings --- src/keywords.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/keywords.cpp b/src/keywords.cpp index 65429f3..49d151b 100644 --- a/src/keywords.cpp +++ b/src/keywords.cpp @@ -169,9 +169,9 @@ const std::vector keywords = float condition; if(tokens[0].type == TokenType::LITERAL) - dest = std::floor(tokens[0].val_number); + dest = static_cast(std::floor(tokens[0].val_number)); else - dest = std::floor(rt.resolve_var_num(tokens[0].val_string)); + dest = static_cast(std::floor(rt.resolve_var_num(tokens[0].val_string))); if(tokens[1].type == TokenType::LITERAL) condition = std::floor(tokens[1].val_number); @@ -193,9 +193,9 @@ const std::vector keywords = float condition; if(tokens[0].type == TokenType::LITERAL) - offset = std::floor(tokens[0].val_number); + offset = static_cast(std::floor(tokens[0].val_number)); else - offset = std::floor(rt.resolve_var_num(tokens[0].val_string)); + offset = static_cast(std::floor(rt.resolve_var_num(tokens[0].val_string))); if(tokens[1].type == TokenType::LITERAL) condition = std::floor(tokens[1].val_number); @@ -253,9 +253,9 @@ const std::vector keywords = { int limit; if(tokens[0].type == TokenType::LITERAL) - limit = tokens[0].val_number; + limit = static_cast(tokens[0].val_number); else - limit = rt.resolve_var_num(tokens[0].val_string); + limit = static_cast(rt.resolve_var_num(tokens[0].val_string)); int number = rand() % limit; From f1f0be77aeb1a5db4a6ec9b9a66176e50980fd5a Mon Sep 17 00:00:00 2001 From: Lauchmelder Date: Wed, 24 Nov 2021 14:34:36 +0100 Subject: [PATCH 07/12] fixed jump offset bug --- src/keywords.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/keywords.cpp b/src/keywords.cpp index 49d151b..2ff437f 100644 --- a/src/keywords.cpp +++ b/src/keywords.cpp @@ -202,7 +202,7 @@ const std::vector keywords = else condition = std::floor(rt.resolve_var_num(tokens[1].val_string)); - dest = rt.instruction_counter + dest; + dest = rt.instruction_counter + offset; if(condition > 0.0f) rt.jump_instructions(dest); From 2ab8c2eaee8f3ee830704fd48f4a65e277d32ada Mon Sep 17 00:00:00 2001 From: Lauchmelder Date: Wed, 24 Nov 2021 14:50:20 +0100 Subject: [PATCH 08/12] changed enum to enum class --- src/common.hpp | 8 ++++---- src/exceptions.hpp | 8 ++++---- src/parse.cpp | 2 +- src/util.cpp | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/common.hpp b/src/common.hpp index ee56cb5..530dcd7 100644 --- a/src/common.hpp +++ b/src/common.hpp @@ -3,7 +3,7 @@ #include -enum TokenType +enum class TokenType { KEYWORD, IDENTIFIER, @@ -11,7 +11,7 @@ enum TokenType ID_OR_LIT }; -enum ValueType +enum class ValueType { STRING, NUMBER, @@ -24,8 +24,8 @@ struct Instruction; struct Keyword; struct Runtime; -const std::string resolve_TokenType_str(enum TokenType); -const std::string resolve_ValueType_str(enum ValueType); +std::string resolve_TokenType_str(enum class TokenType); +std::string resolve_ValueType_str(enum class ValueType); #endif //BISCUIT_INTERPRETER_COMMON_HPP diff --git a/src/exceptions.hpp b/src/exceptions.hpp index 48d806c..a6a4ea5 100644 --- a/src/exceptions.hpp +++ b/src/exceptions.hpp @@ -29,9 +29,9 @@ struct WrongArgumentCountExcept : public std::exception struct WrongTokenExcept : public std::exception { - enum TokenType expected, got; + enum class TokenType expected, got; std::string keyword_name, token_str; - inline WrongTokenExcept(const std::string& _keyword_name, const std::string& _token_str, const enum TokenType& _expected, const enum TokenType& _got) + inline WrongTokenExcept(const std::string& _keyword_name, const std::string& _token_str, enum class TokenType _expected, enum class TokenType _got) : expected(_expected), got(_got), keyword_name(_keyword_name), token_str(_token_str) {} }; @@ -39,9 +39,9 @@ struct WrongTokenExcept : public std::exception // Runtime errors struct TypeErrorExcept : public std::exception { - enum ValueType expected, got; + enum class ValueType expected, got; std::string token_str; - inline TypeErrorExcept(const std::string& _token_str, const enum ValueType& _expected, const enum ValueType& _got) + inline TypeErrorExcept(const std::string& _token_str, enum class ValueType _expected, enum class ValueType _got) : expected(_expected), got(_got), token_str(_token_str) {} }; diff --git a/src/parse.cpp b/src/parse.cpp index 7bfdf1f..d9e5010 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -279,7 +279,7 @@ Instruction::Instruction(std::vector& _token_list) // Make sure the keyword gets the number of arguments it needs if(keyword_ptr->expected_num_args != -1 && (keyword_ptr->expected_num_args != tokens.size() - 1)) - throw WrongArgumentCountExcept(keyword_ptr->name, keyword_ptr->expected_num_args, tokens.size() - 1); + throw WrongArgumentCountExcept(keyword_ptr->name, keyword_ptr->expected_num_args, static_cast(tokens.size() - 1)); // Check the arguments supplied are the right kind of tokens for(int i = 0; i < keyword_ptr->expected_num_args; i++) diff --git a/src/util.cpp b/src/util.cpp index 24d4106..69c13f6 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1,7 +1,7 @@ #include "common.hpp" #include -const std::string resolve_TokenType_str(enum TokenType ttype) +std::string resolve_TokenType_str(TokenType ttype) { switch(ttype) { @@ -22,7 +22,7 @@ const std::string resolve_TokenType_str(enum TokenType ttype) return "UNKNOW TOKENTYPE"; } -const std::string resolve_ValueType_str(enum ValueType vtype) +std::string resolve_ValueType_str(ValueType vtype) { switch(vtype) { From f348d4fc08e4e1f9d2e023d923c191c3bfd6f62b Mon Sep 17 00:00:00 2001 From: Lauchmelder Date: Wed, 24 Nov 2021 14:55:50 +0100 Subject: [PATCH 09/12] more conversion warnings --- src/keywords.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/keywords.cpp b/src/keywords.cpp index 2ff437f..69943d3 100644 --- a/src/keywords.cpp +++ b/src/keywords.cpp @@ -259,7 +259,7 @@ const std::vector keywords = int number = rand() % limit; - rt.assign_var_num(tokens[1].val_string, number); + rt.assign_var_num(tokens[1].val_string, static_cast(number)); } }, { From ac3671def5d2b702a8768460408a8f85bde7ec76 Mon Sep 17 00:00:00 2001 From: Lauchmelder Date: Wed, 24 Nov 2021 14:58:03 +0100 Subject: [PATCH 10/12] the return values should be eligible for copy elision --- src/parse.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/parse.cpp b/src/parse.cpp index d9e5010..ada62fc 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -50,7 +50,7 @@ std::vector tokenize_line(const std::string& line) } } - return std::move(tokens); + return tokens; } // Main parsing function @@ -115,7 +115,7 @@ std::vector parse_instructions(const std::string& code_arg) } - return std::move(instructions); + return instructions; } bool is_keyword(std::string str) From 39fdbdf798993597fb1763a88b7b7c56f574284a Mon Sep 17 00:00:00 2001 From: Lauchmelder Date: Wed, 24 Nov 2021 15:00:55 +0100 Subject: [PATCH 11/12] you don't have to request a console on windows --- src/main.cpp | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b12b8cf..06974f7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,3 @@ -#if defined(WIN32) || defined(WIN32) || defined(__WIN32) -#include -#endif - #include #include #include @@ -13,21 +9,6 @@ #include "parse.hpp" #include "runtime.hpp" -bool request_console(); - -// Must request console on Windows -#if defined(WIN32) || defined(WIN32) || defined(__WIN32) -bool request_console() -{ - return AllocConsole(); -} -#else -bool request_console() -{ - return true; -} -#endif - std::ifstream get_infile(int argc, char ** argv) { if(argc != 2) @@ -54,13 +35,6 @@ int main(int argc, char * argv[]) std::stringstream buffer; buffer << infile.rdbuf(); - // On Windows, we have to explicitly request a console - /*if(!request_console()) - { - std::cerr << "Failed to get console!" << std::endl; - exit(EXIT_FAILURE); - }*/ - std::vector instructions = parse_instructions(buffer.str()); Runtime rt(instructions); From bc409bc989641e5c7702c79770e24039ed2f26ab Mon Sep 17 00:00:00 2001 From: Lauchmelder Date: Wed, 24 Nov 2021 15:03:07 +0100 Subject: [PATCH 12/12] prettified enum classes --- src/common.hpp | 4 ++-- src/exceptions.hpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/common.hpp b/src/common.hpp index 530dcd7..5b2fe2d 100644 --- a/src/common.hpp +++ b/src/common.hpp @@ -24,8 +24,8 @@ struct Instruction; struct Keyword; struct Runtime; -std::string resolve_TokenType_str(enum class TokenType); -std::string resolve_ValueType_str(enum class ValueType); +std::string resolve_TokenType_str(TokenType); +std::string resolve_ValueType_str(ValueType); #endif //BISCUIT_INTERPRETER_COMMON_HPP diff --git a/src/exceptions.hpp b/src/exceptions.hpp index a6a4ea5..8ac5dba 100644 --- a/src/exceptions.hpp +++ b/src/exceptions.hpp @@ -29,9 +29,9 @@ struct WrongArgumentCountExcept : public std::exception struct WrongTokenExcept : public std::exception { - enum class TokenType expected, got; + TokenType expected, got; std::string keyword_name, token_str; - inline WrongTokenExcept(const std::string& _keyword_name, const std::string& _token_str, enum class TokenType _expected, enum class TokenType _got) + inline WrongTokenExcept(const std::string& _keyword_name, const std::string& _token_str, TokenType _expected, TokenType _got) : expected(_expected), got(_got), keyword_name(_keyword_name), token_str(_token_str) {} }; @@ -39,9 +39,9 @@ struct WrongTokenExcept : public std::exception // Runtime errors struct TypeErrorExcept : public std::exception { - enum class ValueType expected, got; + ValueType expected, got; std::string token_str; - inline TypeErrorExcept(const std::string& _token_str, enum class ValueType _expected, enum class ValueType _got) + inline TypeErrorExcept(const std::string& _token_str, ValueType _expected, ValueType _got) : expected(_expected), got(_got), token_str(_token_str) {} };