mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-12 06:11:26 -07:00
Change __dynamic_map_get and __dynamic_map_set to use separate parameters rather than take a singular struct
This commit is contained in:
@@ -383,6 +383,21 @@ Type *lb_addr_type(lbAddr const &addr) {
|
||||
return type_deref(addr.addr.type);
|
||||
}
|
||||
|
||||
lbValue lb_internal_dynamic_map_get_ptr(lbProcedure *p, lbValue const &map_ptr, lbValue const &key) {
|
||||
Type *map_type = base_type(type_deref(map_ptr.type));
|
||||
lbValue h = lb_gen_map_header(p, map_ptr, map_type);
|
||||
|
||||
lbValue key_ptr = {};
|
||||
auto args = array_make<lbValue>(permanent_allocator(), 3);
|
||||
args[0] = h;
|
||||
args[1] = lb_gen_map_key_hash(p, key, map_type->Map.key, &key_ptr);
|
||||
args[2] = key_ptr;
|
||||
|
||||
lbValue ptr = lb_emit_runtime_call(p, "__dynamic_map_get", args);
|
||||
|
||||
return lb_emit_conv(p, ptr, alloc_type_pointer(map_type->Map.value));
|
||||
}
|
||||
|
||||
lbValue lb_addr_get_ptr(lbProcedure *p, lbAddr const &addr) {
|
||||
if (addr.addr.value == nullptr) {
|
||||
GB_PANIC("Illegal addr -> nullptr");
|
||||
@@ -390,19 +405,8 @@ lbValue lb_addr_get_ptr(lbProcedure *p, lbAddr const &addr) {
|
||||
}
|
||||
|
||||
switch (addr.kind) {
|
||||
case lbAddr_Map: {
|
||||
Type *map_type = base_type(addr.map.type);
|
||||
lbValue h = lb_gen_map_header(p, addr.addr, map_type);
|
||||
lbValue key = lb_gen_map_hash(p, addr.map.key, map_type->Map.key);
|
||||
|
||||
auto args = array_make<lbValue>(permanent_allocator(), 2);
|
||||
args[0] = h;
|
||||
args[1] = key;
|
||||
|
||||
lbValue ptr = lb_emit_runtime_call(p, "__dynamic_map_get", args);
|
||||
|
||||
return lb_emit_conv(p, ptr, alloc_type_pointer(map_type->Map.value));
|
||||
}
|
||||
case lbAddr_Map:
|
||||
return lb_internal_dynamic_map_get_ptr(p, addr.addr, addr.map.key);
|
||||
|
||||
case lbAddr_RelativePointer: {
|
||||
Type *rel_ptr = base_type(lb_addr_type(addr));
|
||||
@@ -1059,16 +1063,11 @@ lbValue lb_addr_load(lbProcedure *p, lbAddr const &addr) {
|
||||
|
||||
|
||||
} else if (addr.kind == lbAddr_Map) {
|
||||
Type *map_type = base_type(addr.map.type);
|
||||
Type *map_type = base_type(type_deref(addr.addr.type));
|
||||
GB_ASSERT(map_type->kind == Type_Map);
|
||||
lbAddr v = lb_add_local_generated(p, map_type->Map.lookup_result_type, true);
|
||||
lbValue h = lb_gen_map_header(p, addr.addr, map_type);
|
||||
lbValue key = lb_gen_map_hash(p, addr.map.key, map_type->Map.key);
|
||||
|
||||
auto args = array_make<lbValue>(permanent_allocator(), 2);
|
||||
args[0] = h;
|
||||
args[1] = key;
|
||||
|
||||
lbValue ptr = lb_emit_runtime_call(p, "__dynamic_map_get", args);
|
||||
lbValue ptr = lb_internal_dynamic_map_get_ptr(p, addr.addr, addr.map.key);
|
||||
lbValue ok = lb_emit_conv(p, lb_emit_comp_against_nil(p, Token_NotEq, ptr), t_bool);
|
||||
lb_emit_store(p, lb_emit_struct_ep(p, v.addr, 1), ok);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user