mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Also allow comparing SOA pointers against each other
This compares the data pointer *and* the index.
```odin
package scratch
import "core:fmt"
Foo :: struct {a, b: int}
main :: proc() {
a := new(#soa[dynamic]Foo)
a^ = make(#soa[dynamic]Foo, 12, 12)
b := new(#soa[dynamic]Foo)
b^ = make(#soa[dynamic]Foo, 12, 12)
fmt.printfln("&a[0]: %p, &b[0]: %p, Same: %v", &a[0], &b[0], &a[0] == &b[0]) // Same: false
fmt.printfln("&a[0]: %p, &b[0]: %p, Same: %v", &a[0], &b[1], &a[0] == &b[1]) // Same: false
fmt.printfln("&a[0]: %p, &b[0]: %p, Same: %v", &a[0], &b[2], &a[0] == &b[2]) // Same: false
fmt.printfln("&a[0]: %p, &a[1]: %p, Same: %v", &a[0], &a[1], &a[0] == &a[1]) // Same: false
fmt.printfln("&a[1]: %p, &a[2]: %p, Same: %v", &a[1], &a[2], &a[1] == &a[2]) // Same: false
fmt.printfln("&a[2]: %p, &a[3]: %p, Same: %v", &a[2], &a[3], &a[2] == &a[3]) // Same: false
fmt.printfln("&a[0]: %p, &a[0]: %p, Same: %v", &a[0], &a[0], &a[0] == &a[0]) // Same: true
fmt.printfln("&a[1]: %p, &a[1]: %p, Same: %v", &a[1], &a[1], &a[1] == &a[1]) // Same: true
fmt.printfln("&a[2]: %p, &a[2]: %p, Same: %v", &a[2], &a[2], &a[2] == &a[2]) // Same: true
}
```
This commit is contained in:
@@ -2517,7 +2517,7 @@ gb_internal lbValue lb_emit_c_vararg(lbProcedure *p, lbValue arg, Type *type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gb_internal lbValue lb_compare_records(lbProcedure *p, TokenKind op_kind, lbValue left, lbValue right, Type *type) {
|
gb_internal lbValue lb_compare_records(lbProcedure *p, TokenKind op_kind, lbValue left, lbValue right, Type *type) {
|
||||||
GB_ASSERT((is_type_struct(type) || is_type_union(type)) && is_type_comparable(type));
|
GB_ASSERT((is_type_struct(type) || is_type_soa_pointer(type) || is_type_union(type)) && is_type_comparable(type));
|
||||||
lbValue left_ptr = lb_address_from_load_or_generate_local(p, left);
|
lbValue left_ptr = lb_address_from_load_or_generate_local(p, left);
|
||||||
lbValue right_ptr = lb_address_from_load_or_generate_local(p, right);
|
lbValue right_ptr = lb_address_from_load_or_generate_local(p, right);
|
||||||
lbValue res = {};
|
lbValue res = {};
|
||||||
@@ -2902,6 +2902,7 @@ gb_internal lbValue lb_emit_comp(lbProcedure *p, TokenKind op_kind, lbValue left
|
|||||||
is_type_proc(a) ||
|
is_type_proc(a) ||
|
||||||
is_type_enum(a)) {
|
is_type_enum(a)) {
|
||||||
LLVMIntPredicate pred = {};
|
LLVMIntPredicate pred = {};
|
||||||
|
|
||||||
if (is_type_unsigned(left.type)) {
|
if (is_type_unsigned(left.type)) {
|
||||||
switch (op_kind) {
|
switch (op_kind) {
|
||||||
case Token_Gt: pred = LLVMIntUGT; break;
|
case Token_Gt: pred = LLVMIntUGT; break;
|
||||||
@@ -3025,6 +3026,9 @@ gb_internal lbValue lb_emit_comp(lbProcedure *p, TokenKind op_kind, lbValue left
|
|||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
|
} else if (is_type_soa_pointer(a)) {
|
||||||
|
// NOTE(Jeroen): Compare data pointer and index tag as if it were a simple struct.
|
||||||
|
return lb_compare_records(p, op_kind, left, right, a);
|
||||||
} else {
|
} else {
|
||||||
GB_PANIC("Unhandled comparison kind %s (%s) %.*s %s (%s)", type_to_string(left.type), type_to_string(base_type(left.type)), LIT(token_strings[op_kind]), type_to_string(right.type), type_to_string(base_type(right.type)));
|
GB_PANIC("Unhandled comparison kind %s (%s) %.*s %s (%s)", type_to_string(left.type), type_to_string(base_type(left.type)), LIT(token_strings[op_kind]), type_to_string(right.type), type_to_string(base_type(right.type)));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user