Skip to content

Commit b0f7b69

Browse files
authored
Merge pull request #9 from nibblebits/dev
Made it so if you use a function but specify the wrong arguments it s…
2 parents 44a0534 + 824611c commit b0f7b69

File tree

8 files changed

+66
-3
lines changed

8 files changed

+66
-3
lines changed

.vscode/launch.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
8+
{
9+
"name": "(gdb) Launch",
10+
"type": "cppdbg",
11+
"request": "launch",
12+
"program": "/usr/bin/marble",
13+
"args": ["~/Desktop/test.marble"],
14+
"stopAtEntry": false,
15+
"cwd": "${workspaceFolder}",
16+
"environment": [],
17+
"externalConsole": true,
18+
"MIMode": "gdb",
19+
"setupCommands": [
20+
{
21+
"description": "Enable pretty-printing for gdb",
22+
"text": "-enable-pretty-printing",
23+
"ignoreFailures": true
24+
}
25+
]
26+
}
27+
]
28+
}

include/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2323

2424
// Marble versioning information
2525
#define MARBLE_MAJOR_CODENAME "Clearies"
26-
#define MARBLE_VERSION "0.6.2"
26+
#define MARBLE_VERSION "0.7.0"
2727

2828
#define MAX_KEYWORD_SIZE 15
2929
#define MAX_OPERATORS_SIZE 3

include/function.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ class Function
5555
// Is this a private, protected or public variable?
5656
MODIFIER_ACCESS access;
5757

58+
/**
59+
* Returns this function in a string format.
60+
* E.g function print(string) : void
61+
*/
62+
virtual std::string toString() = 0;
5863

5964
// An empty static function used for when a native programmer wants to create a function that points to nothing.
6065
static void Blank(Interpreter* interpreter, std::vector<Value> values, Value* return_value, std::shared_ptr<Object> object, Scope* caller_scope);

include/groupedfunction.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ class GroupedFunction : public Function
8080
// 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
8181
bool sort_comparator(SystemHandler* calling_handler, SingleFunction* f1, SingleFunction* f2);
8282

83+
virtual std::string toString();
84+
85+
8386
/** The SystemHandler related to this function */
8487
SystemHandler* sys_handler;
8588

include/singlefunction.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class SingleFunction : public Function
3232
public:
3333
SingleFunction(FUNCTION_TYPE type, std::string name, std::vector<VarType> argument_types, VarType return_type);
3434
virtual ~SingleFunction();
35+
virtual std::string toString();
3536
std::vector<VarType> argument_types;
3637
VarType return_type;
3738
};

src/system/fcnode.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ void FunctionCallNode::test(Validator *validator, struct extras extra)
104104
{
105105
throw TestError("The function \"" + this->name->value + "\" has not been declared");
106106
}
107-
throw TestError("The function \"" + this->name->value + "\" has not been declared that takes the given arguments");
107+
108+
Function* function = function_sys->getFunctionByName(this->name->value);
109+
std::string possible_candidates = "Possible candidates: \n==============\n\n" + function->toString() + "\n==============";
110+
throw TestError("The function \"" + this->name->value + "\" has not been declared that takes the given arguments\n" + possible_candidates);
108111
}
109112

110113
SingleFunction *function = (SingleFunction *)function_sys->getFunctionByNameAndArguments(this->name->value, types, NULL, true, validator);

src/system/groupedfunction.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ bool GroupedFunction::sort_comparator(SystemHandler* calling_handler, SingleFunc
7070
return true;
7171
}
7272

73+
std::string GroupedFunction::toString()
74+
{
75+
std::string result = "";
76+
for (int i = 0; i < this->functions.size(); i++)
77+
{
78+
Function* function = this->functions.at(i).get();
79+
result += function->toString() + "\n";
80+
}
81+
82+
return result;
83+
}
84+
7385
Function* GroupedFunction::getFunctionForValues(std::vector<Value> values, SystemHandler* calling_handler)
7486
{
7587
std::vector<SingleFunction*> possible_functions;

src/system/singlefunction.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1919
*/
2020

2121
#include "singlefunction.h"
22-
22+
#include "misc.h"
2323
SingleFunction::SingleFunction(FUNCTION_TYPE type, std::string name, std::vector<VarType> argument_types, VarType return_type) : Function(type, name)
2424
{
2525
this->argument_types = argument_types;
@@ -30,3 +30,14 @@ SingleFunction::~SingleFunction()
3030
{
3131
}
3232

33+
std::string SingleFunction::toString()
34+
{
35+
std::string result = "function " + this->name + "(";
36+
for(VarType vtype : this->argument_types)
37+
{
38+
result += vtype.value + ",";
39+
}
40+
result = trim_right(result, ",");
41+
result += ") : " + this->return_type.value + ";";
42+
return result;
43+
}

0 commit comments

Comments
 (0)