From dbd06388538b3ba38ab4e5d03c4bc695854f5ff0 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Thu, 14 Feb 2019 11:11:05 +0000 Subject: Fix untyped ternary string IR conversion --- core/mem/allocators.odin | 2 ++ 1 file changed, 2 insertions(+) (limited to 'core/mem') diff --git a/core/mem/allocators.odin b/core/mem/allocators.odin index af6ed329a..6dafe18c0 100644 --- a/core/mem/allocators.odin +++ b/core/mem/allocators.odin @@ -381,6 +381,8 @@ small_stack_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode, return nil; } + alignment = clamp(alignment, 1, 8*size_of(Stack_Allocation_Header{}.padding)/2); + raw_alloc :: proc(s: ^Small_Stack, size, alignment: int) -> rawptr { curr_addr := uintptr(&s.data[0]) + uintptr(s.offset); padding := calc_padding_with_header(curr_addr, uintptr(alignment), size_of(Small_Stack_Allocation_Header)); -- cgit v1.2.3 From 79b585ada897169c56c7183806a9a811c96c3140 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Thu, 21 Feb 2019 21:45:33 +0000 Subject: Add minor additions to mem, sync, and sys/win32 --- core/mem/mem.odin | 8 ++++++++ core/sync/sync_windows.odin | 28 +++++++++++++++++++++++++++ core/sys/win32/kernel32.odin | 45 ++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 79 insertions(+), 2 deletions(-) (limited to 'core/mem') diff --git a/core/mem/mem.odin b/core/mem/mem.odin index 4bb94ba0f..47591437f 100644 --- a/core/mem/mem.odin +++ b/core/mem/mem.odin @@ -183,6 +183,14 @@ align_forward_uintptr :: proc(ptr, align: uintptr) -> uintptr { return uintptr(p); } + +align_forward_int :: inline proc(ptr, align: int) -> int { + return int(align_forward_uintptr(uintptr(ptr), uintptr(align))); +} +align_forward_uint :: inline proc(ptr, align: uint) -> uint { + return uint(align_forward_uintptr(uintptr(ptr), uintptr(align))); +} + context_from_allocator :: proc(a: Allocator) -> type_of(context) { context.allocator = a; return context; diff --git a/core/sync/sync_windows.odin b/core/sync/sync_windows.odin index 3854f6807..b0a9d944c 100644 --- a/core/sync/sync_windows.odin +++ b/core/sync/sync_windows.odin @@ -2,6 +2,11 @@ package sync import "core:sys/win32" +foreign { + @(link_name="llvm.x86.sse2.pause") + yield_processor :: proc() --- +} + Semaphore :: struct { _handle: win32.Handle, } @@ -14,6 +19,12 @@ Condition :: struct { event: win32.Handle, } +Ticket_Mutex :: struct { + ticket: u64, + serving: u64, +} + + current_thread_id :: proc() -> i32 { return i32(win32.get_current_thread_id()); } @@ -81,3 +92,20 @@ condition_destroy :: proc(using c: ^Condition) { win32.close_handle(event); } } + + +ticket_mutex_init :: proc(m: ^Ticket_Mutex) { + atomic_store(&m.ticket, 0, Ordering.Relaxed); + atomic_store(&m.serving, 0, Ordering.Relaxed); +} + +ticket_mutex_lock :: inline proc(m: ^Ticket_Mutex) { + ticket := atomic_add(&m.ticket, 1, Ordering.Relaxed); + for ticket != m.serving { + yield_processor(); + } +} + +ticket_mutex_unlock :: inline proc(m: ^Ticket_Mutex) { + atomic_add(&m.serving, 1, Ordering.Relaxed); +} diff --git a/core/sys/win32/kernel32.odin b/core/sys/win32/kernel32.odin index a41fe32de..6f9390cc4 100644 --- a/core/sys/win32/kernel32.odin +++ b/core/sys/win32/kernel32.odin @@ -56,8 +56,8 @@ foreign kernel32 { @(link_name="GetFileSizeEx") get_file_size_ex :: proc(file_handle: Handle, file_size: ^i64) -> Bool ---; @(link_name="GetFileAttributesA") get_file_attributes_a :: proc(filename: cstring) -> u32 ---; @(link_name="GetFileAttributesW") get_file_attributes_w :: proc(filename: Wstring) -> u32 ---; - @(link_name="GetFileAttributesExA") get_file_attributes_ex_a :: proc(filename: cstring, info_level_id: GET_FILEEX_INFO_LEVELS, file_info: rawptr) -> Bool ---; - @(link_name="GetFileAttributesExW") get_file_attributes_ex_w :: proc(filename: Wstring, info_level_id: GET_FILEEX_INFO_LEVELS, file_info: rawptr) -> Bool ---; + @(link_name="GetFileAttributesExA") get_file_attributes_ex_a :: proc(filename: cstring, info_level_id: GET_FILEEX_INFO_LEVELS, file_info: ^File_Attribute_Data) -> Bool ---; + @(link_name="GetFileAttributesExW") get_file_attributes_ex_w :: proc(filename: Wstring, info_level_id: GET_FILEEX_INFO_LEVELS, file_info: ^File_Attribute_Data) -> Bool ---; @(link_name="GetFileInformationByHandle") get_file_information_by_handle :: proc(file_handle: Handle, file_info: ^By_Handle_File_Information) -> Bool ---; @(link_name="CreateDirectoryA") create_directory_a :: proc(path: cstring, security_attributes: ^Security_Attributes) -> Bool ---; @@ -168,3 +168,44 @@ foreign kernel32 { @(link_name="GetProcAddress") get_proc_address :: proc(h: Hmodule, c_str: cstring) -> rawptr ---; } + +Memory_Basic_Information :: struct { + base_address: rawptr, + allocation_base: rawptr, + allocation_protect: u32, + region_size: uint, + state: u32, + protect: u32, + type: u32, +} + +@(default_calling_convention = "std") +foreign kernel32 { + @(link_name="VirtualAlloc") virtual_alloc :: proc(address: rawptr, size: uint, allocation_type: u32, protect: u32) -> rawptr --- + @(link_name="VirtualAllocEx") virtual_alloc_ex :: proc(process: Handle, address: rawptr, size: uint, allocation_type: u32, protect: u32) -> rawptr --- + @(link_name="VirtualFree") virtual_free :: proc(address: rawptr, size: uint, free_type: u32) -> Bool --- + @(link_name="VirtualLock") virtual_lock :: proc(address: rawptr, size: uint) -> Bool --- + @(link_name="VirtualProtect") virtual_protect :: proc(address: rawptr, size: uint, new_protect: u32, old_protect: ^u32) -> Bool --- + @(link_name="VirtualQuery") virtual_query :: proc(address: rawptr, buffer: ^Memory_Basic_Information, length: uint) -> uint --- +} + +MEM_COMMIT :: 0x00001000; +MEM_RESERVE :: 0x00002000; +MEM_DECOMMIT :: 0x00004000; +MEM_RELEASE :: 0x00008000; +MEM_RESET :: 0x00080000; +MEM_RESET_UNDO :: 0x01000000; + +MEM_LARGE_PAGES :: 0x20000000; +MEM_PHYSICAL :: 0x00400000; +MEM_TOP_DOWN :: 0x00100000; +MEM_WRITE_WATCH :: 0x00200000; + +PAGE_NOACCESS :: 0x01; +PAGE_READONLY :: 0x02; +PAGE_READWRITE :: 0x04; +PAGE_WRITECOPY :: 0x08; +PAGE_EXECUTE :: 0x10; +PAGE_EXECUTE_READ :: 0x20; +PAGE_EXECUTE_READWRITE :: 0x40; +PAGE_EXECUTE_WRITECOPY :: 0x80; -- cgit v1.2.3 From c67ea9784560d3e56febe8acd6270d4cfa6daa50 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 6 Mar 2019 19:08:37 +0000 Subject: Add implicit selector expressions for in/notin --- core/mem/allocators.odin | 28 ++++++++++++---------------- core/strconv/strconv.odin | 6 +++--- src/check_expr.cpp | 14 +++++++++++++- 3 files changed, 28 insertions(+), 20 deletions(-) (limited to 'core/mem') diff --git a/core/mem/allocators.odin b/core/mem/allocators.odin index 6dafe18c0..77cc0abf1 100644 --- a/core/mem/allocators.odin +++ b/core/mem/allocators.odin @@ -47,12 +47,10 @@ arena_allocator :: proc(arena: ^Arena) -> Allocator { arena_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode, size, alignment: int, old_memory: rawptr, old_size: int, flags: u64, location := #caller_location) -> rawptr { - using Allocator_Mode; arena := cast(^Arena)allocator_data; - switch mode { - case Alloc: + case .Alloc: total_size := size + alignment; if arena.offset + total_size > len(arena.data) { @@ -66,14 +64,14 @@ arena_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode, arena.peak_used = max(arena.peak_used, arena.offset); return zero(ptr, size); - case Free: + case .Free: // NOTE(bill): Free all at once // Use Arena_Temp_Memory if you want to free a block - case Free_All: + case .Free_All: arena.offset = 0; - case Resize: + case .Resize: return default_resize_align(old_memory, old_size, size, alignment, arena_allocator(arena)); } @@ -227,7 +225,6 @@ stack_allocator :: proc(stack: ^Stack) -> Allocator { stack_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode, size, alignment: int, old_memory: rawptr, old_size: int, flags: u64, location := #caller_location) -> rawptr { - using Allocator_Mode; s := cast(^Stack)allocator_data; if s.data == nil { @@ -256,9 +253,9 @@ stack_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode, } switch mode { - case Alloc: + case .Alloc: return raw_alloc(s, size, alignment); - case Free: + case .Free: if old_memory == nil { return nil; } @@ -288,11 +285,11 @@ stack_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode, s.prev_offset = int(header.prev_offset); - case Free_All: + case .Free_All: s.prev_offset = 0; s.curr_offset = 0; - case Resize: + case .Resize: if old_memory == nil { return raw_alloc(s, size, alignment); } @@ -374,7 +371,6 @@ small_stack_allocator :: proc(stack: ^Small_Stack) -> Allocator { small_stack_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode, size, alignment: int, old_memory: rawptr, old_size: int, flags: u64, location := #caller_location) -> rawptr { - using Allocator_Mode; s := cast(^Small_Stack)allocator_data; if s.data == nil { @@ -403,9 +399,9 @@ small_stack_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode, } switch mode { - case Alloc: + case .Alloc: return raw_alloc(s, size, alignment); - case Free: + case .Free: if old_memory == nil { return nil; } @@ -428,10 +424,10 @@ small_stack_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode, s.offset = int(old_offset); - case Free_All: + case .Free_All: s.offset = 0; - case Resize: + case .Resize: if old_memory == nil { return raw_alloc(s, size, alignment); } diff --git a/core/strconv/strconv.odin b/core/strconv/strconv.odin index 0526a65ba..d509d7b6a 100644 --- a/core/strconv/strconv.odin +++ b/core/strconv/strconv.odin @@ -475,7 +475,7 @@ append_bits :: proc(buf: []byte, u: u64, base: int, is_signed: bool, bit_size: i } i-=1; a[i] = digits[u % b]; - if Int_Flag.Prefix in flags { + if .Prefix in flags { ok := true; switch base { case 2: i-=1; a[i] = 'b'; @@ -493,9 +493,9 @@ append_bits :: proc(buf: []byte, u: u64, base: int, is_signed: bool, bit_size: i switch { case neg: i-=1; a[i] = '-'; - case Int_Flag.Plus in flags: + case .Plus in flags: i-=1; a[i] = '+'; - case Int_Flag.Space in flags: + case .Space in flags: i-=1; a[i] = ' '; } diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 4c921f484..532b79969 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -2144,8 +2144,20 @@ void check_binary_expr(CheckerContext *c, Operand *x, Ast *node, bool use_lhs_as case Token_in: case Token_notin: - check_expr(c, x, be->left); + // IMPORTANT NOTE(bill): This uses right-left evaluation in type checking only no in + check_expr(c, y, be->right); + + if (is_type_bit_set(y->type)) { + Type *elem = base_type(y->type)->BitSet.elem; + check_expr_with_type_hint(c, x, be->left, elem); + } else if (is_type_map(y->type)) { + Type *key = base_type(y->type)->Map.key; + check_expr_with_type_hint(c, x, be->left, key); + } else { + check_expr(c, x, be->left); + } + if (x->mode == Addressing_Invalid) { return; } -- cgit v1.2.3