summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2023-12-03 03:15:56 -0500
committerKyle Gunger <kgunger12@gmail.com>2023-12-03 03:15:56 -0500
commitc2f53476e9595693297f5b68eb5426fb3d9d5200 (patch)
tree5654953e21b2c5f9de5705013a2123e0fb18188e
parent3e3a1a277b5ad5f08087427ec79e0ce6673bdac1 (diff)
function type resolution for inputs and outputs
-rw-r--r--compiler.c55
1 files changed, 54 insertions, 1 deletions
diff --git a/compiler.c b/compiler.c
index e9dbb3e..3498dce 100644
--- a/compiler.c
+++ b/compiler.c
@@ -1678,6 +1678,7 @@ void p1_size_type (Module *root, Type *t) {
if (n_end == NULL) {
printf("COMPILER ERROR: Did not properly assure type %s had all members with both name and RTN\n\n", t->name);
+ p1_error = true;
sum = -2;
break;
}
@@ -1691,15 +1692,17 @@ void p1_size_type (Module *root, Type *t) {
Type *mt = mod_find_type(root, &rta);
art_end(&rta);
- if(t == NULL) {
+ if(mt == NULL) {
// Could not find type
char *rtn = art_to_str(&rta, '.');
printf("ERROR: Could not find type %s when parsing type %s.\n\n", rtn, t->name);
+ p1_error = true;
free(rtn);
break;
} else if (mt->size == -1) {
// Cycle in type definition
printf("ERROR: Cyclical type definition %s -> %s\n\n", mt->name, t->name);
+ p1_error = true;
sum = -1;
break;
} else if (mt->size == 0 && mt->module != NULL) {
@@ -1715,6 +1718,56 @@ void p1_size_type (Module *root, Type *t) {
}
void p1_resolve_func_types(Module *root, Function *func) {
+ for (size_t i = 0; i < func->outputs.count; i++) {
+ Variable *var = vect_get(&func->outputs, i);
+ Artifact rtn = art_from_str(var->name, '.');
+ Type *t = mod_find_type(root, &rtn);
+
+ if(t == NULL) {
+ char *rt = art_to_str(&rtn, '.');
+ printf("ERROR: Could not find type %s for function %s\n\n", rt, func->name);
+ free(rt);
+ art_end(&rtn);
+ break;
+ }
+
+ art_end(&rtn);
+
+ Vector name = vect_from_string(t->name);
+ free(var->name);
+ var->name = vect_as_string(&name);
+ var->type = t;
+ }
+
+ for (size_t i = 0; i < func->inputs.count; i++) {
+ Variable *var = vect_get(&func->inputs, i);
+ char *n_end = strchr(var->name, ' ');
+
+ if (n_end == NULL) {
+ printf("COMPILER ERROR: Did not properly assure function %s had all parameters with both name and RTN\n\n", func->name);
+ p1_error = true;
+ break;
+ }
+
+ Artifact rtn = art_from_str(n_end + 1, '.');
+ Type *t = mod_find_type(root, &rtn);
+
+ if(t == NULL) {
+ char *rt = art_to_str(&rtn, '.');
+ printf("ERROR: Could not find type %s for function %s\n\n", rt, func->name);
+ free(rt);
+ art_end(&rtn);
+ break;
+ }
+
+ art_end(&rtn);
+
+ *n_end = 0;
+ Vector name = vect_from_string(var->name);
+ free(var->name);
+ var->name = vect_as_string(&name);
+ var->type = t;
+ }
}
void p1_resolve_types(Module *root) {