mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-13 06:41:26 -07:00
Allow .allocator for dynamic arrays; Add mem.Pool
This commit is contained in:
@@ -2648,6 +2648,9 @@ Entity *check_selector(CheckerContext *c, Operand *operand, AstNode *node, Type
|
||||
|
||||
if (entity == nullptr && selector->kind == AstNode_Ident) {
|
||||
String field_name = selector->Ident.token.string;
|
||||
if (is_type_dynamic_array(type_deref(operand->type))) {
|
||||
init_mem_allocator(c->checker);
|
||||
}
|
||||
sel = lookup_field(operand->type, field_name, operand->mode == Addressing_Type);
|
||||
entity = sel.entity;
|
||||
|
||||
|
||||
+2
-2
@@ -1588,7 +1588,7 @@ void init_core_type_info(Checker *c) {
|
||||
t_type_info_bit_field_ptr = alloc_type_pointer(t_type_info_bit_field);
|
||||
}
|
||||
|
||||
void init_core_allocator(Checker *c) {
|
||||
void init_mem_allocator(Checker *c) {
|
||||
if (t_allocator != nullptr) {
|
||||
return;
|
||||
}
|
||||
@@ -1633,7 +1633,7 @@ void init_core_map_type(Checker *c) {
|
||||
|
||||
void init_preload(Checker *c) {
|
||||
init_core_type_info(c);
|
||||
init_core_allocator(c);
|
||||
init_mem_allocator(c);
|
||||
init_core_context(c);
|
||||
init_core_source_code_location(c);
|
||||
init_core_map_type(c);
|
||||
|
||||
+7
-7
@@ -2631,9 +2631,9 @@ irValue *ir_emit_struct_ep(irProcedure *proc, irValue *s, i32 index) {
|
||||
} else if (is_type_dynamic_array(t)) {
|
||||
switch (index) {
|
||||
case 0: result_type = alloc_type_pointer(alloc_type_pointer(t->DynamicArray.elem)); break;
|
||||
case 1: result_type = t_int_ptr; break;
|
||||
case 2: result_type = t_int_ptr; break;
|
||||
case 3: result_type = t_allocator_ptr; break;
|
||||
case 1: result_type = t_int_ptr; break;
|
||||
case 2: result_type = t_int_ptr; break;
|
||||
case 3: result_type = t_allocator_ptr; break;
|
||||
}
|
||||
} /* else if (is_type_map(t)) {
|
||||
init_map_internal_types(t);
|
||||
@@ -2650,7 +2650,7 @@ irValue *ir_emit_struct_ep(irProcedure *proc, irValue *s, i32 index) {
|
||||
GB_PANIC("TODO(bill): struct_gep type: %s, %d", type_to_string(ir_type(s)), index);
|
||||
}
|
||||
|
||||
GB_ASSERT(result_type != nullptr);
|
||||
GB_ASSERT_MSG(result_type != nullptr, "%s %d", type_to_string(t), index);
|
||||
|
||||
return ir_emit(proc, ir_instr_struct_element_ptr(proc, s, index, result_type));
|
||||
}
|
||||
@@ -2708,9 +2708,9 @@ irValue *ir_emit_struct_ev(irProcedure *proc, irValue *s, i32 index) {
|
||||
case Type_DynamicArray:
|
||||
switch (index) {
|
||||
case 0: result_type = alloc_type_pointer(t->DynamicArray.elem); break;
|
||||
case 1: result_type = t_int; break;
|
||||
case 2: result_type = t_int; break;
|
||||
case 3: result_type = t_allocator; break;
|
||||
case 1: result_type = t_int; break;
|
||||
case 2: result_type = t_int; break;
|
||||
case 3: result_type = t_allocator; break;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
+59
-49
@@ -1611,55 +1611,6 @@ Selection lookup_field_with_selection(Type *type_, String field_name, bool is_ty
|
||||
|
||||
type = base_type(type);
|
||||
|
||||
if (type->kind == Type_Basic) {
|
||||
switch (type->Basic.kind) {
|
||||
case Basic_any: {
|
||||
#if 1
|
||||
// IMPORTANT TODO(bill): Should these members be available to should I only allow them with
|
||||
// `Raw_Any` type?
|
||||
String data_str = str_lit("data");
|
||||
String typeid_str = str_lit("typeid");
|
||||
gb_local_persist Entity *entity__any_data = alloc_entity_field(nullptr, make_token_ident(data_str), t_rawptr, false, 0);
|
||||
gb_local_persist Entity *entity__any_typeid = alloc_entity_field(nullptr, make_token_ident(typeid_str), t_typeid, false, 1);
|
||||
|
||||
if (field_name == data_str) {
|
||||
selection_add_index(&sel, 0);
|
||||
sel.entity = entity__any_data;;
|
||||
return sel;
|
||||
} else if (field_name == typeid_str) {
|
||||
selection_add_index(&sel, 1);
|
||||
sel.entity = entity__any_typeid;
|
||||
return sel;
|
||||
}
|
||||
#endif
|
||||
} break;
|
||||
}
|
||||
|
||||
return sel;
|
||||
} else if (type->kind == Type_Array) {
|
||||
if (type->Array.count <= 4) {
|
||||
// HACK(bill): Memory leak
|
||||
switch (type->Array.count) {
|
||||
#define _ARRAY_FIELD_CASE(_length, _name) \
|
||||
case (_length): \
|
||||
if (field_name == _name) { \
|
||||
selection_add_index(&sel, (_length)-1); \
|
||||
sel.entity = alloc_entity_array_elem(nullptr, make_token_ident(str_lit(_name)), type->Array.elem, (_length)-1); \
|
||||
return sel; \
|
||||
} \
|
||||
/*fallthrough*/
|
||||
|
||||
_ARRAY_FIELD_CASE(4, "w");
|
||||
_ARRAY_FIELD_CASE(3, "z");
|
||||
_ARRAY_FIELD_CASE(2, "y");
|
||||
_ARRAY_FIELD_CASE(1, "x");
|
||||
default: break;
|
||||
|
||||
#undef _ARRAY_FIELD_CASE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (is_type) {
|
||||
switch (type->kind) {
|
||||
case Type_Struct:
|
||||
@@ -1769,6 +1720,65 @@ Selection lookup_field_with_selection(Type *type_, String field_name, bool is_ty
|
||||
return sel;
|
||||
}
|
||||
}
|
||||
} else if (type->kind == Type_Basic) {
|
||||
switch (type->Basic.kind) {
|
||||
case Basic_any: {
|
||||
#if 1
|
||||
// IMPORTANT TODO(bill): Should these members be available to should I only allow them with
|
||||
// `Raw_Any` type?
|
||||
String data_str = str_lit("data");
|
||||
String typeid_str = str_lit("typeid");
|
||||
gb_local_persist Entity *entity__any_data = alloc_entity_field(nullptr, make_token_ident(data_str), t_rawptr, false, 0);
|
||||
gb_local_persist Entity *entity__any_typeid = alloc_entity_field(nullptr, make_token_ident(typeid_str), t_typeid, false, 1);
|
||||
|
||||
if (field_name == data_str) {
|
||||
selection_add_index(&sel, 0);
|
||||
sel.entity = entity__any_data;
|
||||
return sel;
|
||||
} else if (field_name == typeid_str) {
|
||||
selection_add_index(&sel, 1);
|
||||
sel.entity = entity__any_typeid;
|
||||
return sel;
|
||||
}
|
||||
#endif
|
||||
} break;
|
||||
}
|
||||
|
||||
return sel;
|
||||
} else if (type->kind == Type_Array) {
|
||||
if (type->Array.count <= 4) {
|
||||
// HACK(bill): Memory leak
|
||||
switch (type->Array.count) {
|
||||
#define _ARRAY_FIELD_CASE(_length, _name) \
|
||||
case (_length): \
|
||||
if (field_name == _name) { \
|
||||
selection_add_index(&sel, (_length)-1); \
|
||||
sel.entity = alloc_entity_array_elem(nullptr, make_token_ident(str_lit(_name)), type->Array.elem, (_length)-1); \
|
||||
return sel; \
|
||||
} \
|
||||
/*fallthrough*/
|
||||
|
||||
_ARRAY_FIELD_CASE(4, "w");
|
||||
_ARRAY_FIELD_CASE(3, "z");
|
||||
_ARRAY_FIELD_CASE(2, "y");
|
||||
_ARRAY_FIELD_CASE(1, "x");
|
||||
default: break;
|
||||
|
||||
#undef _ARRAY_FIELD_CASE
|
||||
}
|
||||
}
|
||||
} else if (type->kind == Type_DynamicArray) {
|
||||
// IMPORTANT TODO(bill): Should these members be available to should I only allow them with
|
||||
// `Raw_Dynamic_Array` type?
|
||||
GB_ASSERT(t_allocator != nullptr);
|
||||
String allocator_str = str_lit("allocator");
|
||||
gb_local_persist Entity *entity__allocator = alloc_entity_field(nullptr, make_token_ident(allocator_str), t_allocator, false, 0);
|
||||
|
||||
if (field_name == allocator_str) {
|
||||
selection_add_index(&sel, 3);
|
||||
sel.entity = entity__allocator;
|
||||
return sel;
|
||||
}
|
||||
}
|
||||
|
||||
return sel;
|
||||
|
||||
Reference in New Issue
Block a user