mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-20 05:20:28 +00:00
Fix ABI typo bug; Add pop_safe and pop_front_safe
This commit is contained in:
@@ -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
|
||||
unordered_remove :: proc(array: ^$D/[dynamic]$T, index: int, loc := #caller_location) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@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 {
|
||||
return E{}, false;
|
||||
}
|
||||
|
||||
@@ -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 (is_type_pointer(abi_type)) {
|
||||
GB_ASSERT(e->kind == Entity_Variable);
|
||||
Type *av = type_deref(abi_type);
|
||||
if (are_types_identical(av, e->type)) {
|
||||
Type *av = core_type(type_deref(abi_type));
|
||||
if (are_types_identical(av, core_type(e->type))) {
|
||||
v->Param.kind = irParamPass_Pointer;
|
||||
if (e->flags&EntityFlag_Value) {
|
||||
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]);
|
||||
} else if (!are_types_identical(original_type, new_type)) {
|
||||
if (is_type_pointer(new_type) && !is_type_pointer(original_type)) {
|
||||
Type *av = type_deref(new_type);
|
||||
if (are_types_identical(av, original_type)) {
|
||||
Type *av = core_type(type_deref(new_type));
|
||||
if (are_types_identical(av, core_type(original_type))) {
|
||||
if (e->flags&EntityFlag_ImplicitReference) {
|
||||
array_add(&processed_args, ir_address_from_load_or_generate_local(p, args[i]));
|
||||
} 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 (is_type_pointer(abi_type)) {
|
||||
GB_ASSERT(e->kind == Entity_Variable);
|
||||
Type *av = type_deref(abi_type);
|
||||
if (are_types_identical(av, e->type)) {
|
||||
Type *av = core_type(type_deref(abi_type));
|
||||
if (are_types_identical(av, core_type(e->type))) {
|
||||
kind = lbParamPass_Pointer;
|
||||
if (e->flags&EntityFlag_Value) {
|
||||
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]);
|
||||
} else if (!are_types_identical(original_type, new_type)) {
|
||||
if (is_type_pointer(new_type) && !is_type_pointer(original_type)) {
|
||||
Type *av = type_deref(new_type);
|
||||
if (are_types_identical(av, arg_type)) {
|
||||
Type *av = core_type(type_deref(new_type));
|
||||
if (are_types_identical(av, core_type(original_type))) {
|
||||
if (e->flags&EntityFlag_ImplicitReference) {
|
||||
array_add(&processed_args, lb_address_from_load_or_generate_local(p, args[i]));
|
||||
} else if (!is_type_pointer(arg_type)) {
|
||||
|
||||
Reference in New Issue
Block a user