From 5916e71d4fec16f03e372dbb1788d7ae42765f4f Mon Sep 17 00:00:00 2001 From: Ginger Bill Date: Tue, 11 Apr 2017 16:00:49 +0100 Subject: [PATCH] Fix slicing bug on dynamic arrays --- core/opengl.odin | 2 ++ core/os_windows.odin | 1 + core/sys/wgl.odin | 13 +++++++++++-- src/check_expr.c | 1 + src/ir.c | 27 +++++++++++++++------------ 5 files changed, 30 insertions(+), 14 deletions(-) diff --git a/core/opengl.odin b/core/opengl.odin index d5c322a17..d08340b5a 100644 --- a/core/opengl.odin +++ b/core/opengl.odin @@ -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"); diff --git a/core/os_windows.odin b/core/os_windows.odin index ab8a26920..d5847c3db 100644 --- a/core/os_windows.odin +++ b/core/os_windows.odin @@ -1,4 +1,5 @@ #import win32 "sys/windows.odin"; +#import fmt "fmt.odin"; Handle :: int; File_Time :: u64; diff --git a/core/sys/wgl.odin b/core/sys/wgl.odin index 57e974a7b..4cca783bc 100644 --- a/core/sys/wgl.odin +++ b/core/sys/wgl.odin @@ -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"; diff --git a/src/check_expr.c b/src/check_expr.c index 0f231b9cf..e1423073b 100644 --- a/src/check_expr.c +++ b/src/check_expr.c @@ -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; } diff --git a/src/ir.c b/src/ir.c index cfbf43ed5..8a7653c9e 100644 --- a/src/ir.c +++ b/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: {