mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 14:48:47 +00:00
Allow map indices to be referenced &m[key] and return a valid pointer if it exists otherwise nil
This commit is contained in:
+4
-1
@@ -1648,8 +1648,11 @@ bool check_is_not_addressable(CheckerContext *c, Operand *o) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if (o->mode == Addressing_MapIndex) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (o->mode != Addressing_Variable) {
|
if (o->mode != Addressing_Variable) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-1
@@ -3929,7 +3929,20 @@ irValue *ir_addr_get_ptr(irProcedure *proc, irAddr const &addr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (addr.kind) {
|
switch (addr.kind) {
|
||||||
case irAddr_Map:
|
case irAddr_Map: {
|
||||||
|
Type *map_type = base_type(addr.map_type);
|
||||||
|
irValue *h = ir_gen_map_header(proc, addr.addr, map_type);
|
||||||
|
irValue *key = ir_gen_map_key(proc, addr.map_key, map_type->Map.key);
|
||||||
|
|
||||||
|
auto args = array_make<irValue *>(ir_allocator(), 2);
|
||||||
|
args[0] = h;
|
||||||
|
args[1] = key;
|
||||||
|
|
||||||
|
irValue *ptr = ir_emit_runtime_call(proc, "__dynamic_map_get", args);
|
||||||
|
return ir_emit_conv(proc, ptr, alloc_type_pointer(map_type->Map.value));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
case irAddr_BitField: {
|
case irAddr_BitField: {
|
||||||
irValue *v = ir_addr_load(proc, addr);
|
irValue *v = ir_addr_load(proc, addr);
|
||||||
return ir_address_from_load_or_generate_local(proc, v);
|
return ir_address_from_load_or_generate_local(proc, v);
|
||||||
|
|||||||
Reference in New Issue
Block a user