aboutsummaryrefslogtreecommitdiff
path: root/typecheck.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-02-17 21:04:35 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-02-17 21:04:35 -0500
commit8f451d0271659ea57c4960f858ea61ea7a10598d (patch)
treed6706ec0a298bd52fcef4fdc130c627cc7c59a4e /typecheck.c
parent26723deea26f76670f8de07702b3be221d8503fa (diff)
Custom tostring functions working
Diffstat (limited to 'typecheck.c')
-rw-r--r--typecheck.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/typecheck.c b/typecheck.c
index 37a222fe..488d9107 100644
--- a/typecheck.c
+++ b/typecheck.c
@@ -104,7 +104,17 @@ void bind_statement(env_t *env, ast_t *statement)
}
case StructDef: {
auto def = Match(statement, StructDef);
- type_t *type = Table_str_get(env->types, def->name);
+ arg_t *fields = NULL;
+ type_t *type = Type(StructType, .name=def->name, .fields=fields); // placeholder
+ for (arg_ast_t *field_ast = def->fields; field_ast; field_ast = field_ast->next) {
+ type_t *field_t = parse_type_ast(env, field_ast->type);
+ fields = new(arg_t, .name=field_ast->name, .type=field_t, .default_val=field_ast->default_val, .next=fields);
+ }
+ REVERSE_LIST(fields);
+ type->__data.StructType.fields = fields; // populate placeholder
+ Table_str_set(env->types, def->name, type);
+
+ if (!type) code_err(statement, "I couldn't get this type");
type_t *constructor_t = Type(FunctionType, .args=Match(type, StructType)->fields, .ret=type);
set_binding(env, def->name, new(binding_t, .type=constructor_t));
break;