Fixing up more stuff
This commit is contained in:
parent
80af2ea547
commit
25519d2434
@ -70,7 +70,7 @@ public bool Int$equal_value(const Int_t x, const Int_t y) {
|
||||
return x.small == y.small || (__builtin_expect(((x.small & y.small) & 1) == 0, 0) && mpz_cmp(*x.big, *y.big) == 0);
|
||||
}
|
||||
|
||||
public bool Int$hash(const Int_t *x, const TypeInfo *type) {
|
||||
public uint32_t Int$hash(const Int_t *x, const TypeInfo *type) {
|
||||
(void)type;
|
||||
uint32_t hash;
|
||||
if (__builtin_expect(x->small & 1, 1)) {
|
||||
|
@ -46,6 +46,7 @@ DEFINE_INT_TYPE(int8_t, Int8);
|
||||
#define Int8$abs(...) I8(abs(__VA_ARGS__))
|
||||
|
||||
CORD Int$as_text(const Int_t *i, bool colorize, const TypeInfo *type);
|
||||
uint32_t Int$hash(const Int_t *x, const TypeInfo *type);
|
||||
int32_t Int$compare(const Int_t *x, const Int_t *y, const TypeInfo *type);
|
||||
int32_t Int$compare_value(const Int_t x, const Int_t y);
|
||||
bool Int$equal(const Int_t *x, const Int_t *y, const TypeInfo *type);
|
||||
|
26
structs.c
26
structs.c
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user