diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-08-13 02:28:14 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-08-13 02:28:14 -0400 |
| commit | 25519d243485ab1906304adc99d400684b04ef5b (patch) | |
| tree | ef041872fd695d4b6d218791fbab3b90575e3532 /structs.c | |
| parent | 80af2ea5476e6bc93fe3d7d2c297c021aa29b497 (diff) | |
Fixing up more stuff
Diffstat (limited to 'structs.c')
| -rw-r--r-- | structs.c | 26 |
1 files changed, 18 insertions, 8 deletions
@@ -47,7 +47,13 @@ static CORD compile_compare_method(env_t *env, ast_t *ast) for (arg_ast_t *field = def->fields; field; field = field->next) { type_t *field_type = get_arg_ast_type(env, field); switch (field_type->tag) { - case BoolType: case IntType: case NumType: case PointerType: case FunctionType: + case IntType: + if (Match(field_type, IntType)->bits == 0) + cmp_func = CORD_all(cmp_func, "diff = Int$compare_value(x->$", field->name, ", y->$", field->name, ");"); + else + cmp_func = CORD_all(cmp_func, "diff = (x->$", field->name, " > y->$", field->name, ") - (x->$", field->name, " < y->$", field->name, ");"); + break; + case BoolType: case NumType: case PointerType: case FunctionType: cmp_func = CORD_all(cmp_func, "diff = (x->$", field->name, " > y->$", field->name, ") - (x->$", field->name, " < y->$", field->name, ");"); break; case TextType: @@ -77,7 +83,13 @@ static CORD compile_equals_method(env_t *env, ast_t *ast) condition = CORD_all(condition, " && "); type_t *field_type = get_arg_ast_type(env, field); switch (field_type->tag) { - case BoolType: case IntType: case NumType: case PointerType: case FunctionType: + case IntType: + if (Match(field_type, IntType)->bits == 0) + condition = CORD_all(condition, "Int$equal_value(x->$", field->name, ", y->$", field->name, ")"); + else + condition = CORD_all(condition, "(x->$", field->name, " == y->$", field->name, ")"); + break; + case BoolType: case NumType: case PointerType: case FunctionType: condition = CORD_all(condition, "(x->$", field->name, " == y->$", field->name, ")"); break; case TextType: @@ -132,13 +144,11 @@ void compile_struct_def(env_t *env, ast_t *ast) if (struct_->fields && !struct_->fields->next) { // Single member, can just use its methods type_t *member_t = struct_->fields->type; switch (member_t->tag) { - case TextType: - typeinfo = CORD_all(typeinfo, ".hash=(void*)", type_to_cord(member_t), "$hash", ", "); - // fallthrough - case IntType: case NumType: - typeinfo = CORD_all(typeinfo, ".compare=(void*)", type_to_cord(member_t), "$compare, " + case TextType: case IntType: case NumType: + typeinfo = CORD_all(typeinfo, ".hash=(void*)", type_to_cord(member_t), "$hash", ", ", + ".compare=(void*)", type_to_cord(member_t), "$compare, " ".equal=(void*)", type_to_cord(member_t), "$equal, "); - // fallthrough + goto got_methods; case BoolType: goto got_methods; default: break; } |
