Skip to content

Commit

Permalink
Merge pull request #9 from nibblebits/dev
Browse files Browse the repository at this point in the history
Made it so if you use a function but specify the wrong arguments it s…
  • Loading branch information
nibblebits authored Nov 11, 2018
2 parents 44a0534 + 824611c commit b0f7b69
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 3 deletions.
28 changes: 28 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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
}
]
}
]
}
2 changes: 1 addition & 1 deletion include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions include/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Value> values, Value* return_value, std::shared_ptr<Object> object, Scope* caller_scope);
Expand Down
3 changes: 3 additions & 0 deletions include/groupedfunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions include/singlefunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class SingleFunction : public Function
public:
SingleFunction(FUNCTION_TYPE type, std::string name, std::vector<VarType> argument_types, VarType return_type);
virtual ~SingleFunction();
virtual std::string toString();
std::vector<VarType> argument_types;
VarType return_type;
};
Expand Down
5 changes: 4 additions & 1 deletion src/system/fcnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions src/system/groupedfunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Value> values, SystemHandler* calling_handler)
{
std::vector<SingleFunction*> possible_functions;
Expand Down
13 changes: 12 additions & 1 deletion src/system/singlefunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<VarType> argument_types, VarType return_type) : Function(type, name)
{
this->argument_types = argument_types;
Expand All @@ -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;
}

0 comments on commit b0f7b69

Please sign in to comment.