mirror of
https://github.com/odin-lang/Odin.git
synced 2026-03-01 14:18:19 +00:00
Fix slicing bug on dynamic arrays
This commit is contained in:
@@ -47,6 +47,7 @@ GetProcAddress :: proc(name: string) -> proc() #cc_c {
|
||||
GenBuffers: proc(count: i32, buffers: ^u32) #cc_c;
|
||||
GenVertexArrays: proc(count: i32, buffers: ^u32) #cc_c;
|
||||
GenSamplers: proc(count: i32, buffers: ^u32) #cc_c;
|
||||
DeleteBuffers: proc(count: i32, buffers: ^u32) #cc_c;
|
||||
BindBuffer: proc(target: i32, buffer: u32) #cc_c;
|
||||
BindVertexArray: proc(buffer: u32) #cc_c;
|
||||
BindSampler: proc(position: i32, sampler: u32) #cc_c;
|
||||
@@ -108,6 +109,7 @@ init :: proc() {
|
||||
set_proc_address(^GenBuffers, "glGenBuffers\x00");
|
||||
set_proc_address(^GenVertexArrays, "glGenVertexArrays\x00");
|
||||
set_proc_address(^GenSamplers, "glGenSamplers\x00");
|
||||
set_proc_address(^DeleteBuffers, "glDeleteBuffers\x00");
|
||||
set_proc_address(^BindBuffer, "glBindBuffer\x00");
|
||||
set_proc_address(^BindSampler, "glBindSampler\x00");
|
||||
set_proc_address(^BindVertexArray, "glBindVertexArray\x00");
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#import win32 "sys/windows.odin";
|
||||
#import fmt "fmt.odin";
|
||||
|
||||
Handle :: int;
|
||||
File_Time :: u64;
|
||||
|
||||
@@ -51,8 +51,17 @@ Glyph_Metrics_Float :: struct #ordered {
|
||||
cell_inc_y: f32,
|
||||
}
|
||||
|
||||
Create_Context_Attribs_ARB_Type :: #type proc(hdc: Hdc, hshareContext: rawptr, attribList: ^i32) -> Hglrc;
|
||||
Choose_Pixel_Format_ARB_Type :: #type proc(hdc: Hdc, attrib_i_list: ^i32, attrib_f_list: ^f32, max_formats: u32, formats: ^i32, num_formats : ^u32) -> Bool #cc_c;
|
||||
CreateContextAttribsARB_Type :: #type proc(hdc: Hdc, h_share_context: rawptr, attribList: ^i32) -> Hglrc;
|
||||
ChoosePixelFormatARB_Type :: #type proc(hdc: Hdc, attrib_i_list: ^i32, attrib_f_list: ^f32, max_formats: u32, formats: ^i32, num_formats : ^u32) -> Bool #cc_c;
|
||||
SwapIntervalEXT_Type :: #type proc(interval : i32) -> bool #cc_c;
|
||||
GetExtensionsStringARB_Type :: #type proc(Hdc) -> ^byte #cc_c;
|
||||
|
||||
|
||||
CreateContextAttribsARB: CreateContextAttribsARB_Type;
|
||||
ChoosePixelFormatARB: ChoosePixelFormatARB_Type;
|
||||
SwapIntervalEXT: SwapIntervalEXT_Type;
|
||||
GetExtensionsStringARB: GetExtensionsStringARB_Type;
|
||||
|
||||
|
||||
|
||||
CreateContext :: proc(hdc: Hdc) -> Hglrc #foreign opengl32 "wglCreateContext";
|
||||
|
||||
@@ -5619,6 +5619,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
|
||||
|
||||
case Type_DynamicArray:
|
||||
valid = true;
|
||||
o->type = make_type_slice(c->allocator, t->DynamicArray.elem);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
27
src/ir.c
27
src/ir.c
@@ -1945,13 +1945,15 @@ irValue *ir_emit_arith(irProcedure *proc, TokenKind op, irValue *left, irValue *
|
||||
case Token_Shl:
|
||||
case Token_Shr:
|
||||
left = ir_emit_conv(proc, left, type);
|
||||
if (!is_type_unsigned(ir_type(right))) {
|
||||
Type *t = t_u64;
|
||||
if (build_context.word_size == 32) {
|
||||
t = t_u32;
|
||||
}
|
||||
right = ir_emit_conv(proc, right, t);
|
||||
}
|
||||
// if (!is_type_unsigned(ir_type(right))) {
|
||||
// Type *t = t_u64;
|
||||
// if (build_context.word_size == 32) {
|
||||
// t = t_u32;
|
||||
// }
|
||||
// right = ir_emit_conv(proc, right, t);
|
||||
// }
|
||||
right = ir_emit_conv(proc, right, type);
|
||||
|
||||
break;
|
||||
|
||||
case Token_AndNot: {
|
||||
@@ -3792,7 +3794,7 @@ irValue *ir_build_expr(irProcedure *proc, AstNode *expr) {
|
||||
|
||||
irValue *array = ir_add_local_generated(proc, type);
|
||||
irValue **args = gb_alloc_array(a, irValue *, 5);
|
||||
args[0] = array;
|
||||
args[0] = ir_emit_conv(proc, array, t_rawptr);
|
||||
args[1] = ir_const_int(a, type_size_of(a, elem_type));
|
||||
args[2] = ir_const_int(a, type_align_of(a, elem_type));;
|
||||
args[3] = len;
|
||||
@@ -4860,17 +4862,18 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
|
||||
}
|
||||
|
||||
case Type_DynamicArray: {
|
||||
Type *dynamic_array = type;
|
||||
Type *elem_type = type->DynamicArray.elem;
|
||||
Type *slice_type = make_type_slice(a, elem_type);
|
||||
|
||||
if (high == NULL) high = ir_dynamic_array_count(proc, base);
|
||||
if (max == NULL) max = ir_dynamic_array_capacity(proc, base);
|
||||
if (max == NULL) max = ir_dynamic_array_capacity(proc, base);
|
||||
|
||||
ir_emit_slice_bounds_check(proc, se->open, low, high, max, false);
|
||||
|
||||
irValue *elem = ir_emit_ptr_offset(proc, ir_dynamic_array_elem(proc, base), low);
|
||||
irValue *len = ir_emit_arith(proc, Token_Sub, high, low, t_int);
|
||||
irValue *cap = ir_emit_arith(proc, Token_Sub, max, low, t_int);
|
||||
irValue *slice = ir_add_local_generated(proc, dynamic_array);
|
||||
irValue *slice = ir_add_local_generated(proc, slice_type);
|
||||
ir_fill_slice(proc, slice, elem, len, cap);
|
||||
return ir_addr(slice);
|
||||
}
|
||||
@@ -5617,7 +5620,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
|
||||
|
||||
irValue *value = ir_value_type_name(proc->module->allocator,
|
||||
name, e->type);
|
||||
map_string_set(&proc->module->entity_names, hash_pointer(e->type), name);
|
||||
map_string_set(&proc->module->entity_names, hash_pointer(e), name);
|
||||
ir_gen_global_type_name(proc->module, e, name);
|
||||
} break;
|
||||
case Entity_Procedure: {
|
||||
|
||||
Reference in New Issue
Block a user