summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/ast-tree.c23
-rw-r--r--src/compiler/ast-tree.h2
-rw-r--r--src/compiler/code-generator.c4
3 files changed, 17 insertions, 12 deletions
diff --git a/src/compiler/ast-tree.c b/src/compiler/ast-tree.c
index c38a4b8..097e45b 100644
--- a/src/compiler/ast-tree.c
+++ b/src/compiler/ast-tree.c
@@ -919,18 +919,22 @@ ERROR:
exit(1);
}
-bool isFunction(AstTree *value) {
+AstTreeFunction *getFunction(AstTree *value) {
switch (value->token) {
case AST_TREE_TOKEN_FUNCTION:
- return true;
+ return value->metadata;
case AST_TREE_TOKEN_FUNCTION_CALL: {
AstTreeFunctionCall *metadata = value->metadata;
AstTreeFunction *function = metadata->function->metadata;
- return isFunction(function->returnType);
+ return getFunction(function->returnType);
}
case AST_TREE_TOKEN_VARIABLE: {
AstTreeVariable *metadata = value->metadata;
- return metadata->type->token == AST_TREE_TOKEN_TYPE_FUNCTION;
+ if (metadata->type->token == AST_TREE_TOKEN_TYPE_FUNCTION) {
+ return metadata->value->metadata;
+ } else {
+ return NULL;
+ }
}
case AST_TREE_TOKEN_KEYWORD_PRINT_U64:
case AST_TREE_TOKEN_TYPE_TYPE:
@@ -939,7 +943,7 @@ bool isFunction(AstTree *value) {
case AST_TREE_TOKEN_TYPE_U64:
case AST_TREE_TOKEN_VALUE_U64:
case AST_TREE_TOKEN_VARIABLE_DEFINE:
- return false;
+ return NULL;
case AST_TREE_TOKEN_NONE:
}
printLog("Bad token '%d'", value->token);
@@ -1147,14 +1151,15 @@ bool setTypesFunctionCall(AstTree *tree) {
return false;
}
- if (isFunction(metadata->function)) {
+ if (!setAllTypes(metadata->function)) {
printLog("Type mismatch");
return false;
}
- AstTreeFunction *function = metadata->function->metadata;
- if (function->arguments.size != metadata->parameters_size) {
- printLog("Not yet supported");
+ AstTreeFunction *function = getFunction(metadata->function);
+ if (function == NULL || function->arguments.size != metadata->parameters_size) {
+ printLog("Arguments doesn't match %ld != %ld", function->arguments.size,
+ metadata->parameters_size);
return false;
}
diff --git a/src/compiler/ast-tree.h b/src/compiler/ast-tree.h
index 2e43973..645ef5f 100644
--- a/src/compiler/ast-tree.h
+++ b/src/compiler/ast-tree.h
@@ -140,7 +140,7 @@ AstTree *astTreeParseVariable(ParserNode *parserNode,
size_t variables_size);
bool hasTypeOf(AstTree *value, const AstTree *type);
-bool isFunction(AstTree *value);
+AstTreeFunction* getFunction(AstTree *value);
bool isConst(AstTree *value);
AstTree *makeTypeOf(AstTree *value);
bool typeIsEqual(const AstTree *type0, const AstTree *type1);
diff --git a/src/compiler/code-generator.c b/src/compiler/code-generator.c
index 4ddfe94..24f0699 100644
--- a/src/compiler/code-generator.c
+++ b/src/compiler/code-generator.c
@@ -348,9 +348,9 @@ char *codeGeneratorToFlatASM(const CodeGeneratorCodes *codes) {
CodeGeneratorOperand *metadata = code.metadata;
char *inst;
if (metadata->isReference) {
- asprintf(&inst, "db [%s]\n", metadata->value);
+ asprintf(&inst, "dq [%s]\n", metadata->value);
} else {
- asprintf(&inst, "db %s\n", metadata->value);
+ asprintf(&inst, "dq %s\n", metadata->value);
}
codeGeneratorAppendFlatASMCommand(&fasm, &fasm_size, &fasm_inserted, inst,
strlen(inst));