diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..74d994a --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,28 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + + { + "name": "(gdb) Launch", + "type": "cppdbg", + "request": "launch", + "program": "/usr/bin/marble", + "args": ["~/Desktop/test.marble"], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": true, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/include/config.h b/include/config.h index 1d329c1..c647e66 100755 --- a/include/config.h +++ b/include/config.h @@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // Marble versioning information #define MARBLE_MAJOR_CODENAME "Clearies" -#define MARBLE_VERSION "0.6.2" +#define MARBLE_VERSION "0.7.0" #define MAX_KEYWORD_SIZE 15 #define MAX_OPERATORS_SIZE 3 diff --git a/include/function.h b/include/function.h index 575950a..a57dff0 100755 --- a/include/function.h +++ b/include/function.h @@ -55,6 +55,11 @@ class Function // Is this a private, protected or public variable? MODIFIER_ACCESS access; + /** + * Returns this function in a string format. + * E.g function print(string) : void + */ + virtual std::string toString() = 0; // An empty static function used for when a native programmer wants to create a function that points to nothing. static void Blank(Interpreter* interpreter, std::vector values, Value* return_value, std::shared_ptr object, Scope* caller_scope); diff --git a/include/groupedfunction.h b/include/groupedfunction.h index 7993d1c..f6065ec 100755 --- a/include/groupedfunction.h +++ b/include/groupedfunction.h @@ -80,6 +80,9 @@ class GroupedFunction : public Function // Assists in sorting functions based on type. This had to be done as otherwise std::sort requires a static function we need access to this instance bool sort_comparator(SystemHandler* calling_handler, SingleFunction* f1, SingleFunction* f2); + virtual std::string toString(); + + /** The SystemHandler related to this function */ SystemHandler* sys_handler; diff --git a/include/singlefunction.h b/include/singlefunction.h index 21bb87b..cc997b8 100755 --- a/include/singlefunction.h +++ b/include/singlefunction.h @@ -32,6 +32,7 @@ class SingleFunction : public Function public: SingleFunction(FUNCTION_TYPE type, std::string name, std::vector argument_types, VarType return_type); virtual ~SingleFunction(); + virtual std::string toString(); std::vector argument_types; VarType return_type; }; diff --git a/src/system/fcnode.cpp b/src/system/fcnode.cpp index 9e2a074..1a3934b 100755 --- a/src/system/fcnode.cpp +++ b/src/system/fcnode.cpp @@ -104,7 +104,10 @@ void FunctionCallNode::test(Validator *validator, struct extras extra) { throw TestError("The function \"" + this->name->value + "\" has not been declared"); } - throw TestError("The function \"" + this->name->value + "\" has not been declared that takes the given arguments"); + + Function* function = function_sys->getFunctionByName(this->name->value); + std::string possible_candidates = "Possible candidates: \n==============\n\n" + function->toString() + "\n=============="; + throw TestError("The function \"" + this->name->value + "\" has not been declared that takes the given arguments\n" + possible_candidates); } SingleFunction *function = (SingleFunction *)function_sys->getFunctionByNameAndArguments(this->name->value, types, NULL, true, validator); diff --git a/src/system/groupedfunction.cpp b/src/system/groupedfunction.cpp index 4f46e77..589a3a1 100755 --- a/src/system/groupedfunction.cpp +++ b/src/system/groupedfunction.cpp @@ -70,6 +70,18 @@ bool GroupedFunction::sort_comparator(SystemHandler* calling_handler, SingleFunc return true; } +std::string GroupedFunction::toString() +{ + std::string result = ""; + for (int i = 0; i < this->functions.size(); i++) + { + Function* function = this->functions.at(i).get(); + result += function->toString() + "\n"; + } + + return result; +} + Function* GroupedFunction::getFunctionForValues(std::vector values, SystemHandler* calling_handler) { std::vector possible_functions; diff --git a/src/system/singlefunction.cpp b/src/system/singlefunction.cpp index fc20c85..a76e373 100755 --- a/src/system/singlefunction.cpp +++ b/src/system/singlefunction.cpp @@ -19,7 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "singlefunction.h" - +#include "misc.h" SingleFunction::SingleFunction(FUNCTION_TYPE type, std::string name, std::vector argument_types, VarType return_type) : Function(type, name) { this->argument_types = argument_types; @@ -30,3 +30,14 @@ SingleFunction::~SingleFunction() { } +std::string SingleFunction::toString() +{ + std::string result = "function " + this->name + "("; + for(VarType vtype : this->argument_types) + { + result += vtype.value + ","; + } + result = trim_right(result, ","); + result += ") : " + this->return_type.value + ";"; + return result; +}