mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Fix ABI typo bug; Add pop_safe and pop_front_safe
This commit is contained in:
+35
-11
@@ -528,16 +528,6 @@ copy :: proc{copy_slice, copy_from_string};
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@builtin
|
|
||||||
pop :: proc(array: ^$T/[dynamic]$E) -> E {
|
|
||||||
if array == nil do return E{};
|
|
||||||
assert(len(array) > 0);
|
|
||||||
res := #no_bounds_check array[len(array)-1];
|
|
||||||
(^Raw_Dynamic_Array)(array).len -= 1;
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
@builtin
|
@builtin
|
||||||
unordered_remove :: proc(array: ^$D/[dynamic]$T, index: int, loc := #caller_location) {
|
unordered_remove :: proc(array: ^$D/[dynamic]$T, index: int, loc := #caller_location) {
|
||||||
bounds_check_error_loc(loc, index, len(array));
|
bounds_check_error_loc(loc, index, len(array));
|
||||||
@@ -557,8 +547,42 @@ ordered_remove :: proc(array: ^$D/[dynamic]$T, index: int, loc := #caller_locati
|
|||||||
pop(array);
|
pop(array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@builtin
|
@builtin
|
||||||
pop_front :: proc(array: ^$T/[dynamic]$E) -> (E, bool) #no_bounds_check {
|
pop :: proc(array: ^$T/[dynamic]$E) -> E {
|
||||||
|
if len(array) == 0 {
|
||||||
|
return E{};
|
||||||
|
}
|
||||||
|
assert(len(array) > 0);
|
||||||
|
res := #no_bounds_check array[len(array)-1];
|
||||||
|
(^Raw_Dynamic_Array)(array).len -= 1;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@builtin
|
||||||
|
pop_safe :: proc(array: ^$T/[dynamic]$E) -> (E, bool) {
|
||||||
|
if len(array) == 0 {
|
||||||
|
return E{}, false;
|
||||||
|
}
|
||||||
|
res := #no_bounds_check array[len(array)-1];
|
||||||
|
(^Raw_Dynamic_Array)(array).len -= 1;
|
||||||
|
return res, true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@builtin
|
||||||
|
pop_front :: proc(array: ^$T/[dynamic]$E) -> E #no_bounds_check {
|
||||||
|
assert(len(array) > 0);
|
||||||
|
res := array[0];
|
||||||
|
if len(array) > 1 {
|
||||||
|
copy(array[0:], array[1:]);
|
||||||
|
}
|
||||||
|
(^Raw_Dynamic_Array)(array).len -= 1;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
@builtin
|
||||||
|
pop_front_safe :: proc(array: ^$T/[dynamic]$E) -> (E, bool) #no_bounds_check {
|
||||||
if len(array) == 0 {
|
if len(array) == 0 {
|
||||||
return E{}, false;
|
return E{}, false;
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -976,8 +976,8 @@ irValue *ir_value_param(irProcedure *parent, Entity *e, Type *abi_type, i32 inde
|
|||||||
if (e != nullptr && abi_type != e->type) {
|
if (e != nullptr && abi_type != e->type) {
|
||||||
if (is_type_pointer(abi_type)) {
|
if (is_type_pointer(abi_type)) {
|
||||||
GB_ASSERT(e->kind == Entity_Variable);
|
GB_ASSERT(e->kind == Entity_Variable);
|
||||||
Type *av = type_deref(abi_type);
|
Type *av = core_type(type_deref(abi_type));
|
||||||
if (are_types_identical(av, e->type)) {
|
if (are_types_identical(av, core_type(e->type))) {
|
||||||
v->Param.kind = irParamPass_Pointer;
|
v->Param.kind = irParamPass_Pointer;
|
||||||
if (e->flags&EntityFlag_Value) {
|
if (e->flags&EntityFlag_Value) {
|
||||||
v->Param.kind = irParamPass_ConstRef;
|
v->Param.kind = irParamPass_ConstRef;
|
||||||
@@ -3246,8 +3246,8 @@ irValue *ir_emit_call(irProcedure *p, irValue *value, Array<irValue *> const &ar
|
|||||||
array_add(&processed_args, args[i]);
|
array_add(&processed_args, args[i]);
|
||||||
} else if (!are_types_identical(original_type, new_type)) {
|
} else if (!are_types_identical(original_type, new_type)) {
|
||||||
if (is_type_pointer(new_type) && !is_type_pointer(original_type)) {
|
if (is_type_pointer(new_type) && !is_type_pointer(original_type)) {
|
||||||
Type *av = type_deref(new_type);
|
Type *av = core_type(type_deref(new_type));
|
||||||
if (are_types_identical(av, original_type)) {
|
if (are_types_identical(av, core_type(original_type))) {
|
||||||
if (e->flags&EntityFlag_ImplicitReference) {
|
if (e->flags&EntityFlag_ImplicitReference) {
|
||||||
array_add(&processed_args, ir_address_from_load_or_generate_local(p, args[i]));
|
array_add(&processed_args, ir_address_from_load_or_generate_local(p, args[i]));
|
||||||
} else if (!is_type_pointer(arg_type)) {
|
} else if (!is_type_pointer(arg_type)) {
|
||||||
|
|||||||
@@ -2273,8 +2273,8 @@ lbValue lb_value_param(lbProcedure *p, Entity *e, Type *abi_type, i32 index, lbP
|
|||||||
if (e != nullptr && !are_types_identical(abi_type, e->type)) {
|
if (e != nullptr && !are_types_identical(abi_type, e->type)) {
|
||||||
if (is_type_pointer(abi_type)) {
|
if (is_type_pointer(abi_type)) {
|
||||||
GB_ASSERT(e->kind == Entity_Variable);
|
GB_ASSERT(e->kind == Entity_Variable);
|
||||||
Type *av = type_deref(abi_type);
|
Type *av = core_type(type_deref(abi_type));
|
||||||
if (are_types_identical(av, e->type)) {
|
if (are_types_identical(av, core_type(e->type))) {
|
||||||
kind = lbParamPass_Pointer;
|
kind = lbParamPass_Pointer;
|
||||||
if (e->flags&EntityFlag_Value) {
|
if (e->flags&EntityFlag_Value) {
|
||||||
kind = lbParamPass_ConstRef;
|
kind = lbParamPass_ConstRef;
|
||||||
@@ -7041,8 +7041,8 @@ lbValue lb_emit_call(lbProcedure *p, lbValue value, Array<lbValue> const &args,
|
|||||||
array_add(&processed_args, args[i]);
|
array_add(&processed_args, args[i]);
|
||||||
} else if (!are_types_identical(original_type, new_type)) {
|
} else if (!are_types_identical(original_type, new_type)) {
|
||||||
if (is_type_pointer(new_type) && !is_type_pointer(original_type)) {
|
if (is_type_pointer(new_type) && !is_type_pointer(original_type)) {
|
||||||
Type *av = type_deref(new_type);
|
Type *av = core_type(type_deref(new_type));
|
||||||
if (are_types_identical(av, arg_type)) {
|
if (are_types_identical(av, core_type(original_type))) {
|
||||||
if (e->flags&EntityFlag_ImplicitReference) {
|
if (e->flags&EntityFlag_ImplicitReference) {
|
||||||
array_add(&processed_args, lb_address_from_load_or_generate_local(p, args[i]));
|
array_add(&processed_args, lb_address_from_load_or_generate_local(p, args[i]));
|
||||||
} else if (!is_type_pointer(arg_type)) {
|
} else if (!is_type_pointer(arg_type)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user