diff options
| author | Ginger Bill <bill@gingerbill.org> | 2017-06-19 18:49:11 +0100 |
|---|---|---|
| committer | Ginger Bill <bill@gingerbill.org> | 2017-06-19 18:49:11 +0100 |
| commit | 35c102137f9a097584bf1af39e9809064293a0a3 (patch) | |
| tree | 581cb5f135c5b8be5a3c574fea156b44a1f51aec | |
| parent | 5427d144163af7353b91219a762a5cf4ea17968d (diff) | |
Compiler compiles for x86 (doesn't work properly)
| -rw-r--r-- | core/_preload.odin | 38 | ||||
| -rw-r--r-- | core/fmt.odin | 4 | ||||
| -rw-r--r-- | core/sys/windows.odin | 198 | ||||
| -rw-r--r-- | misc/shell.bat | 4 | ||||
| -rw-r--r-- | src/check_expr.cpp | 25 | ||||
| -rw-r--r-- | src/checker.cpp | 4 | ||||
| -rw-r--r-- | src/ir.cpp | 91 | ||||
| -rw-r--r-- | src/ir_opt.cpp | 3 | ||||
| -rw-r--r-- | src/ir_print.cpp | 2 |
9 files changed, 208 insertions, 161 deletions
diff --git a/core/_preload.odin b/core/_preload.odin index 6d796dbeb..e4df6bc87 100644 --- a/core/_preload.odin +++ b/core/_preload.odin @@ -17,7 +17,7 @@ import ( // Local Variables: snake_case // Constant Variables: SCREAMING_SNAKE_CASE -// IMPORTANT NOTE(bill): `type_info` & `type_info_val` cannot be used within a +// IMPORTANT NOTE(bill): `type_info` cannot be used within a // #shared_global_scope due to the internals of the compiler. // This could change at a later date if the all these data structures are // implemented within the compiler rather than in this "preload" file @@ -407,24 +407,42 @@ proc __string_decode_rune(s: string) -> (rune, int) #inline { proc __mem_set(data: rawptr, value: i32, len: int) -> rawptr { - foreign __llvm_core proc llvm_memset_64bit(dst: rawptr, val: u8, len: int, align: i32, is_volatile: bool) #link_name "llvm.memset.p0i8.i64"; - llvm_memset_64bit(data, u8(value), len, 1, false); - return data; + when size_of(rawptr) == 8 { + foreign __llvm_core proc llvm_memset_64bit(dst: rawptr, val: u8, len: int, align: i32, is_volatile: bool) #link_name "llvm.memset.p0i8.i64"; + llvm_memset_64bit(data, u8(value), len, 1, false); + return data; + } else { + foreign __llvm_core proc llvm_memset_32bit(dst: rawptr, val: u8, len: int, align: i32, is_volatile: bool) #link_name "llvm.memset.p0i8.i32"; + llvm_memset_32bit(data, u8(value), len, 1, false); + return data; + } } proc __mem_zero(data: rawptr, len: int) -> rawptr { return __mem_set(data, 0, len); } proc __mem_copy(dst, src: rawptr, len: int) -> rawptr { // NOTE(bill): This _must_ be implemented like C's memmove - foreign __llvm_core proc llvm_memmove_64bit(dst, src: rawptr, len: int, align: i32, is_volatile: bool) #link_name "llvm.memmove.p0i8.p0i8.i64"; - llvm_memmove_64bit(dst, src, len, 1, false); - return dst; + when size_of(rawptr) == 8 { + foreign __llvm_core proc llvm_memmove_64bit(dst, src: rawptr, len: int, align: i32, is_volatile: bool) #link_name "llvm.memmove.p0i8.p0i8.i64"; + llvm_memmove_64bit(dst, src, len, 1, false); + return dst; + } else { + foreign __llvm_core proc llvm_memmove_32bit(dst, src: rawptr, len: int, align: i32, is_volatile: bool) #link_name "llvm.memmove.p0i8.p0i8.i32"; + llvm_memmove_32bit(dst, src, len, 1, false); + return dst; + } } proc __mem_copy_non_overlapping(dst, src: rawptr, len: int) -> rawptr { // NOTE(bill): This _must_ be implemented like C's memcpy - foreign __llvm_core proc llvm_memcpy_64bit(dst, src: rawptr, len: int, align: i32, is_volatile: bool) #link_name "llvm.memcpy.p0i8.p0i8.i64"; - llvm_memcpy_64bit(dst, src, len, 1, false); - return dst; + when size_of(rawptr) == 8 { + foreign __llvm_core proc llvm_memcpy_64bit(dst, src: rawptr, len: int, align: i32, is_volatile: bool) #link_name "llvm.memcpy.p0i8.p0i8.i64"; + llvm_memcpy_64bit(dst, src, len, 1, false); + return dst; + } else { + foreign __llvm_core proc llvm_memcpy_32bit(dst, src: rawptr, len: int, align: i32, is_volatile: bool) #link_name "llvm.memcpy.p0i8.p0i8.i32"; + llvm_memcpy_32bit(dst, src, len, 1, false); + return dst; + } } proc __mem_compare(a, b: ^u8, n: int) -> int { diff --git a/core/fmt.odin b/core/fmt.odin index 4d0ea9e98..c1841a7ef 100644 --- a/core/fmt.odin +++ b/core/fmt.odin @@ -1087,6 +1087,7 @@ proc sbprintf(b: ^StringBuffer, fmt: string, args: ..any) -> string { was_prev_index = false; fi: FmtInfo; ) + for var i = 0; i < end; /**/ { fi = FmtInfo{buf = b, good_arg_index = true}; @@ -1104,8 +1105,7 @@ proc sbprintf(b: ^StringBuffer, fmt: string, args: ..any) -> string { // Process a "verb" i++; - prefix_loop: - for ; i < end; i++ { + prefix_loop: for ; i < end; i++ { match fmt[i] { case '+': fi.plus = true; diff --git a/core/sys/windows.odin b/core/sys/windows.odin index 1b64de1e2..ccad3c2b5 100644 --- a/core/sys/windows.odin +++ b/core/sys/windows.odin @@ -285,164 +285,164 @@ const ( ) foreign kernel32 { - proc get_last_error () -> i32 #cc_c #link_name "GetLastError"; - proc exit_process (exit_code: u32) #cc_c #link_name "ExitProcess"; - proc get_module_handle_a(module_name: ^u8) -> Hinstance #cc_c #link_name "GetModuleHandleA"; - proc sleep(ms: i32) -> i32 #cc_c #link_name "Sleep"; - proc query_performance_frequency(result: ^i64) -> i32 #cc_c #link_name "QueryPerformanceFrequency"; - proc query_performance_counter (result: ^i64) -> i32 #cc_c #link_name "QueryPerformanceCounter"; - proc output_debug_string_a(c_str: ^u8) #cc_c #link_name "OutputDebugStringA"; - - proc get_command_line_a () -> ^u8 #cc_c #link_name "GetCommandLineA"; - proc get_command_line_w () -> ^u16 #cc_c #link_name "GetCommandLineW"; - proc get_system_metrics (index: i32) -> i32 #cc_c #link_name "GetSystemMetrics"; - proc get_current_thread_id () -> u32 #cc_c #link_name "GetCurrentThreadId"; - - proc get_system_time_as_file_time(system_time_as_file_time: ^Filetime) #cc_c #link_name "GetSystemTimeAsFileTime"; - proc file_time_to_local_file_time(file_time: ^Filetime, local_file_time: ^Filetime) -> Bool #cc_c #link_name "FileTimeToLocalFileTime"; - proc file_time_to_system_time (file_time: ^Filetime, system_time: ^Systemtime) -> Bool #cc_c #link_name "FileTimeToSystemTime"; - proc system_time_to_file_time (system_time: ^Systemtime, file_time: ^Filetime) -> Bool #cc_c #link_name "SystemTimeToFileTime"; - - proc close_handle (h: Handle) -> i32 #cc_c #link_name "CloseHandle"; - proc get_std_handle(h: i32) -> Handle #cc_c #link_name "GetStdHandle"; + proc get_last_error () -> i32 #cc_std #link_name "GetLastError"; + proc exit_process (exit_code: u32) #cc_std #link_name "ExitProcess"; + proc get_module_handle_a(module_name: ^u8) -> Hinstance #cc_std #link_name "GetModuleHandleA"; + proc sleep(ms: i32) -> i32 #cc_std #link_name "Sleep"; + proc query_performance_frequency(result: ^i64) -> i32 #cc_std #link_name "QueryPerformanceFrequency"; + proc query_performance_counter (result: ^i64) -> i32 #cc_std #link_name "QueryPerformanceCounter"; + proc output_debug_string_a(c_str: ^u8) #cc_std #link_name "OutputDebugStringA"; + + proc get_command_line_a () -> ^u8 #cc_std #link_name "GetCommandLineA"; + proc get_command_line_w () -> ^u16 #cc_std #link_name "GetCommandLineW"; + proc get_system_metrics (index: i32) -> i32 #cc_std #link_name "GetSystemMetrics"; + proc get_current_thread_id () -> u32 #cc_std #link_name "GetCurrentThreadId"; + + proc get_system_time_as_file_time(system_time_as_file_time: ^Filetime) #cc_std #link_name "GetSystemTimeAsFileTime"; + proc file_time_to_local_file_time(file_time: ^Filetime, local_file_time: ^Filetime) -> Bool #cc_std #link_name "FileTimeToLocalFileTime"; + proc file_time_to_system_time (file_time: ^Filetime, system_time: ^Systemtime) -> Bool #cc_std #link_name "FileTimeToSystemTime"; + proc system_time_to_file_time (system_time: ^Systemtime, file_time: ^Filetime) -> Bool #cc_std #link_name "SystemTimeToFileTime"; + + proc close_handle (h: Handle) -> i32 #cc_std #link_name "CloseHandle"; + proc get_std_handle(h: i32) -> Handle #cc_std #link_name "GetStdHandle"; proc create_file_a (filename: ^u8, desired_access, share_mode: u32, security: rawptr, - creation, flags_and_attribs: u32, template_file: Handle) -> Handle #cc_c #link_name "CreateFileA"; - proc read_file (h: Handle, buf: rawptr, to_read: u32, bytes_read: ^i32, overlapped: rawptr) -> Bool #cc_c #link_name "ReadFile"; - proc write_file(h: Handle, buf: rawptr, len: i32, written_result: ^i32, overlapped: rawptr) -> Bool #cc_c #link_name "WriteFile"; + creation, flags_and_attribs: u32, template_file: Handle) -> Handle #cc_std #link_name "CreateFileA"; + proc read_file (h: Handle, buf: rawptr, to_read: u32, bytes_read: ^i32, overlapped: rawptr) -> Bool #cc_std #link_name "ReadFile"; + proc write_file(h: Handle, buf: rawptr, len: i32, written_result: ^i32, overlapped: rawptr) -> Bool #cc_std #link_name "WriteFile"; - proc get_file_size_ex (file_handle: Handle, file_size: ^i64) -> Bool #cc_c #link_name "GetFileSizeEx"; - proc get_file_attributes_a (filename: ^u8) -> u32 #cc_c #link_name "GetFileAttributesA"; - proc get_file_attributes_ex_a (filename: ^u8, info_level_id: GET_FILEEX_INFO_LEVELS, file_info: rawptr) -> Bool #cc_c #link_name "GetFileAttributesExA"; - proc get_file_information_by_handle(file_handle: Handle, file_info: ^ByHandleFileInformation) -> Bool #cc_c #link_name "GetFileInformationByHandle"; + proc get_file_size_ex (file_handle: Handle, file_size: ^i64) -> Bool #cc_std #link_name "GetFileSizeEx"; + proc get_file_attributes_a (filename: ^u8) -> u32 #cc_std #link_name "GetFileAttributesA"; + proc get_file_attributes_ex_a (filename: ^u8, info_level_id: GET_FILEEX_INFO_LEVELS, file_info: rawptr) -> Bool #cc_std #link_name "GetFileAttributesExA"; + proc get_file_information_by_handle(file_handle: Handle, file_info: ^ByHandleFileInformation) -> Bool #cc_std #link_name "GetFileInformationByHandle"; - proc get_file_type (file_handle: Handle) -> u32 #cc_c #link_name "GetFileType"; - proc set_file_pointer(file_handle: Handle, distance_to_move: i32, distance_to_move_high: ^i32, move_method: u32) -> u32 #cc_c #link_name "SetFilePointer"; + proc get_file_type (file_handle: Handle) -> u32 #cc_std #link_name "GetFileType"; + proc set_file_pointer(file_handle: Handle, distance_to_move: i32, distance_to_move_high: ^i32, move_method: u32) -> u32 #cc_std #link_name "SetFilePointer"; - proc set_handle_information(obj: Handle, mask, flags: u32) -> Bool #cc_c #link_name "SetHandleInformation"; + proc set_handle_information(obj: Handle, mask, flags: u32) -> Bool #cc_std #link_name "SetHandleInformation"; - proc find_first_file_a(file_name : ^u8, data : ^FindData) -> Handle #cc_c #link_name "FindFirstFileA"; - proc find_next_file_a (file : Handle, data : ^FindData) -> Bool #cc_c #link_name "FindNextFileA"; - proc find_close (file : Handle) -> Bool #cc_c #link_name "FindClose"; + proc find_first_file_a(file_name : ^u8, data : ^FindData) -> Handle #cc_std #link_name "FindFirstFileA"; + proc find_next_file_a (file : Handle, data : ^FindData) -> Bool #cc_std #link_name "FindNextFileA"; + proc find_close (file : Handle) -> Bool #cc_std #link_name "FindClose"; - proc heap_alloc (h: Handle, flags: u32, bytes: int) -> rawptr #cc_c #link_name "HeapAlloc"; - proc heap_realloc (h: Handle, flags: u32, memory: rawptr, bytes: int) -> rawptr #cc_c #link_name "HeapReAlloc"; - proc heap_free (h: Handle, flags: u32, memory: rawptr) -> Bool #cc_c #link_name "HeapFree"; - proc get_process_heap() -> Handle #cc_c #link_name "GetProcessHeap"; + proc heap_alloc (h: Handle, flags: u32, bytes: int) -> rawptr #cc_std #link_name "HeapAlloc"; + proc heap_realloc (h: Handle, flags: u32, memory: rawptr, bytes: int) -> rawptr #cc_std #link_name "HeapReAlloc"; + proc heap_free (h: Handle, flags: u32, memory: rawptr) -> Bool #cc_std #link_name "HeapFree"; + proc get_process_heap() -> Handle #cc_std #link_name "GetProcessHeap"; - proc create_semaphore_a (attributes: ^Security_Attributes, initial_count, maximum_count: i32, name: ^u8) -> Handle #cc_c #link_name "CreateSemaphoreA"; - proc release_semaphore (semaphore: Handle, release_count: i32, previous_count: ^i32) -> Bool #cc_c #link_name "ReleaseSemaphore"; - proc wait_for_single_object(handle: Handle, milliseconds: u32) -> u32 #cc_c #link_name "WaitForSingleObject"; + proc create_semaphore_a (attributes: ^Security_Attributes, initial_count, maximum_count: i32, name: ^u8) -> Handle #cc_std #link_name "CreateSemaphoreA"; + proc release_semaphore (semaphore: Handle, release_count: i32, previous_count: ^i32) -> Bool #cc_std #link_name "ReleaseSemaphore"; + proc wait_for_single_object(handle: Handle, milliseconds: u32) -> u32 #cc_std #link_name "WaitForSingleObject"; - proc interlocked_compare_exchange (dst: ^i32, exchange, comparand: i32) -> i32 #cc_c #link_name "InterlockedCompareExchange"; - proc interlocked_exchange (dst: ^i32, desired: i32) -> i32 #cc_c #link_name "InterlockedExchange"; - proc interlocked_exchange_add (dst: ^i32, desired: i32) -> i32 #cc_c #link_name "InterlockedExchangeAdd"; - proc interlocked_and (dst: ^i32, desired: i32) -> i32 #cc_c #link_name "InterlockedAnd"; - proc interlocked_or (dst: ^i32, desired: i32) -> i32 #cc_c #link_name "InterlockedOr"; + proc interlocked_compare_exchange (dst: ^i32, exchange, comparand: i32) -> i32 #cc_std #link_name "InterlockedCompareExchange"; + proc interlocked_exchange (dst: ^i32, desired: i32) -> i32 #cc_std #link_name "InterlockedExchange"; + proc interlocked_exchange_add (dst: ^i32, desired: i32) -> i32 #cc_std #link_name "InterlockedExchangeAdd"; + proc interlocked_and (dst: ^i32, desired: i32) -> i32 #cc_std #link_name "InterlockedAnd"; + proc interlocked_or (dst: ^i32, desired: i32) -> i32 #cc_std #link_name "InterlockedOr"; - proc interlocked_compare_exchange64(dst: ^i64, exchange, comparand: i64) -> i64 #cc_c #link_name "InterlockedCompareExchange64"; - proc interlocked_exchange64 (dst: ^i64, desired: i64) -> i64 #cc_c #link_name "InterlockedExchange64"; - proc interlocked_exchange_add64 (dst: ^i64, desired: i64) -> i64 #cc_c #link_name "InterlockedExchangeAdd64"; - proc interlocked_and64 (dst: ^i64, desired: i64) -> i64 #cc_c #link_name "InterlockedAnd64"; - proc interlocked_or64 (dst: ^i64, desired: i64) -> i64 #cc_c #link_name "InterlockedOr64"; + proc interlocked_compare_exchange64(dst: ^i64, exchange, comparand: i64) -> i64 #cc_std #link_name "InterlockedCompareExchange64"; + proc interlocked_exchange64 (dst: ^i64, desired: i64) -> i64 #cc_std #link_name "InterlockedExchange64"; + proc interlocked_exchange_add64 (dst: ^i64, desired: i64) -> i64 #cc_std #link_name "InterlockedExchangeAdd64"; + proc interlocked_and64 (dst: ^i64, desired: i64) -> i64 #cc_std #link_name "InterlockedAnd64"; + proc interlocked_or64 (dst: ^i64, desired: i64) -> i64 #cc_std #link_name "InterlockedOr64"; - proc mm_pause () #cc_c #link_name "_mm_pause"; - proc read_write_barrier() #cc_c #link_name "ReadWriteBarrier"; - proc write_barrier () #cc_c #link_name "WriteBarrier"; - proc read_barrier () #cc_c #link_name "ReadBarrier"; + proc mm_pause () #cc_std #link_name "_mm_pause"; + proc read_write_barrier() #cc_std #link_name "ReadWriteBarrier"; + proc write_barrier () #cc_std #link_name "WriteBarrier"; + proc read_barrier () #cc_std #link_name "ReadBarrier"; - proc load_library_a (c_str: ^u8) -> Hmodule #cc_c #link_name "LoadLibraryA"; - proc free_library (h: Hmodule) #cc_c #link_name "FreeLibrary"; - proc get_proc_address(h: Hmodule, c_str: ^u8) -> Proc #cc_c #link_name "GetProcAddress"; + proc load_library_a (c_str: ^u8) -> Hmodule #cc_std #link_name "LoadLibraryA"; + proc free_library (h: Hmodule) #cc_std #link_name "FreeLibrary"; + proc get_proc_address(h: Hmodule, c_str: ^u8) -> Proc #cc_std #link_name "GetProcAddress"; } foreign user32 { - proc get_desktop_window () -> Hwnd #cc_c #link_name "GetDesktopWindow"; - proc show_cursor (show : Bool) #cc_c #link_name "ShowCursor"; - proc get_cursor_pos (p: ^Point) -> i32 #cc_c #link_name "GetCursorPos"; - proc screen_to_client (h: Hwnd, p: ^Point) -> i32 #cc_c #link_name "ScreenToClient"; - proc post_quit_message (exit_code: i32) #cc_c #link_name "PostQuitMessage"; - proc set_window_text_a (hwnd: Hwnd, c_string: ^u8) -> Bool #cc_c #link_name "SetWindowTextA"; - proc register_class_ex_a (wc: ^WndClassExA) -> i16 #cc_c #link_name "RegisterClassExA"; + proc get_desktop_window () -> Hwnd #cc_std #link_name "GetDesktopWindow"; + proc show_cursor (show : Bool) #cc_std #link_name "ShowCursor"; + proc get_cursor_pos (p: ^Point) -> i32 #cc_std #link_name "GetCursorPos"; + proc screen_to_client (h: Hwnd, p: ^Point) -> i32 #cc_std #link_name "ScreenToClient"; + proc post_quit_message (exit_code: i32) #cc_std #link_name "PostQuitMessage"; + proc set_window_text_a (hwnd: Hwnd, c_string: ^u8) -> Bool #cc_std #link_name "SetWindowTextA"; + proc register_class_ex_a (wc: ^WndClassExA) -> i16 #cc_std #link_name "RegisterClassExA"; proc create_window_ex_a (ex_style: u32, class_name, title: ^u8, style: u32, x, y, w, h: i32, parent: Hwnd, menu: Hmenu, instance: Hinstance, - param: rawptr) -> Hwnd #cc_c #link_name "CreateWindowExA"; + param: rawptr) -> Hwnd #cc_std #link_name "CreateWindowExA"; - proc show_window (hwnd: Hwnd, cmd_show: i32) -> Bool #cc_c #link_name "ShowWindow"; - proc translate_message (msg: ^Msg) -> Bool #cc_c #link_name "TranslateMessage"; - proc dispatch_message_a (msg: ^Msg) -> Lresult #cc_c #link_name "DispatchMessageA"; - proc update_window (hwnd: Hwnd) -> Bool #cc_c #link_name "UpdateWindow"; - proc get_message_a (msg: ^Msg, hwnd: Hwnd, msg_filter_min, msg_filter_max : u32) -> Bool #cc_c #link_name "GetMessageA"; + proc show_window (hwnd: Hwnd, cmd_show: i32) -> Bool #cc_std #link_name "ShowWindow"; + proc translate_message (msg: ^Msg) -> Bool #cc_std #link_name "TranslateMessage"; + proc dispatch_message_a (msg: ^Msg) -> Lresult #cc_std #link_name "DispatchMessageA"; + proc update_window (hwnd: Hwnd) -> Bool #cc_std #link_name "UpdateWindow"; + proc get_message_a (msg: ^Msg, hwnd: Hwnd, msg_filter_min, msg_filter_max : u32) -> Bool #cc_std #link_name "GetMessageA"; proc peek_message_a (msg: ^Msg, hwnd: Hwnd, - msg_filter_min, msg_filter_max, remove_msg: u32) -> Bool #cc_c #link_name "PeekMessageA"; + msg_filter_min, msg_filter_max, remove_msg: u32) -> Bool #cc_std #link_name "PeekMessageA"; - proc post_message (hwnd: Hwnd, msg, wparam, lparam : u32) -> Bool #cc_c #link_name "PostMessageA"; + proc post_message (hwnd: Hwnd, msg, wparam, lparam : u32) -> Bool #cc_std #link_name "PostMessageA"; - proc def_window_proc_a (hwnd: Hwnd, msg: u32, wparam: Wparam, lparam: Lparam) -> Lresult #cc_c #link_name "DefWindowProcA"; + proc def_window_proc_a (hwnd: Hwnd, msg: u32, wparam: Wparam, lparam: Lparam) -> Lresult #cc_std #link_name "DefWindowProcA"; - proc adjust_window_rect (rect: ^Rect, style: u32, menu: Bool) -> Bool #cc_c #link_name "AdjustWindowRect"; - proc get_active_window () -> Hwnd #cc_c #link_name "GetActiveWindow"; + proc adjust_window_rect (rect: ^Rect, style: u32, menu: Bool) -> Bool #cc_std #link_name "AdjustWindowRect"; + proc get_active_window () -> Hwnd #cc_std #link_name "GetActiveWindow"; - proc destroy_window (wnd: Hwnd) -> Bool #cc_c #link_name "DestroyWindow"; - proc describe_pixel_format(dc: Hdc, pixel_format: i32, bytes : u32, pfd: ^PixelFormatDescriptor) -> i32 #cc_c #link_name "DescribePixelFormat"; + proc destroy_window (wnd: Hwnd) -> Bool #cc_std #link_name "DestroyWindow"; + proc describe_pixel_format(dc: Hdc, pixel_format: i32, bytes : u32, pfd: ^PixelFormatDescriptor) -> i32 #cc_std #link_name "DescribePixelFormat"; - proc get_monitor_info_a (monitor: Hmonitor, mi: ^MonitorInfo) -> Bool #cc_c #link_name "GetMonitorInfoA"; - proc monitor_from_window (wnd: Hwnd, flags : u32) -> Hmonitor #cc_c #link_name "MonitorFromWindow"; + proc get_monitor_info_a (monitor: Hmonitor, mi: ^MonitorInfo) -> Bool #cc_std #link_name "GetMonitorInfoA"; + proc monitor_from_window (wnd: Hwnd, flags : u32) -> Hmonitor #cc_std #link_name "MonitorFromWindow"; - proc set_window_pos (wnd: Hwnd, wndInsertAfter: Hwnd, x, y, width, height: i32, flags: u32) #cc_c #link_name "SetWindowPos"; + proc set_window_pos (wnd: Hwnd, wndInsertAfter: Hwnd, x, y, width, height: i32, flags: u32) #cc_std #link_name "SetWindowPos"; - proc get_window_placement (wnd: Hwnd, wndpl: ^WindowPlacement) -> Bool #cc_c #link_name "GetWindowPlacement"; - proc set_window_placement (wnd: Hwnd, wndpl: ^WindowPlacement) -> Bool #cc_c #link_name "SetWindowPlacement"; - proc get_window_rect (wnd: Hwnd, rect: ^Rect) -> Bool #cc_c #link_name "GetWindowRect"; + proc get_window_placement (wnd: Hwnd, wndpl: ^WindowPlacement) -> Bool #cc_std #link_name "GetWindowPlacement"; + proc set_window_placement (wnd: Hwnd, wndpl: ^WindowPlacement) -> Bool #cc_std #link_name "SetWindowPlacement"; + proc get_window_rect (wnd: Hwnd, rect: ^Rect) -> Bool #cc_std #link_name "GetWindowRect"; - proc get_window_long_ptr_a(wnd: Hwnd, index: i32) -> i64 #cc_c #link_name "GetWindowLongPtrA"; - proc set_window_long_ptr_a(wnd: Hwnd, index: i32, new: i64) -> i64 #cc_c #link_name "SetWindowLongPtrA"; + proc get_window_long_ptr_a(wnd: Hwnd, index: i32) -> i64 #cc_std #link_name "GetWindowLongPtrA"; + proc set_window_long_ptr_a(wnd: Hwnd, index: i32, new: i64) -> i64 #cc_std #link_name "SetWindowLongPtrA"; - proc get_window_text (wnd: Hwnd, str: ^u8, maxCount: i32) -> i32 #cc_c #link_name "GetWindowText"; + proc get_window_text (wnd: Hwnd, str: ^u8, maxCount: i32) -> i32 #cc_std #link_name "GetWindowText"; - proc get_client_rect (hwnd: Hwnd, rect: ^Rect) -> Bool #cc_c #link_name "GetClientRect"; + proc get_client_rect (hwnd: Hwnd, rect: ^Rect) -> Bool #cc_std #link_name "GetClientRect"; - proc get_dc (h: Hwnd) -> Hdc #cc_c #link_name "GetDC"; - proc release_dc (wnd: Hwnd, hdc: Hdc) -> i32 #cc_c #link_name "ReleaseDC"; + proc get_dc (h: Hwnd) -> Hdc #cc_std #link_name "GetDC"; + proc release_dc (wnd: Hwnd, hdc: Hdc) -> i32 #cc_std #link_name "ReleaseDC"; - proc map_virtual_key(scancode : u32, map_type : u32) -> u32 #cc_c #link_name "MapVirtualKeyA"; + proc map_virtual_key(scancode : u32, map_type : u32) -> u32 #cc_std #link_name "MapVirtualKeyA"; - proc get_key_state (v_key: i32) -> i16 #cc_c #link_name "GetKeyState"; - proc get_async_key_state(v_key: i32) -> i16 #cc_c #link_name "GetAsyncKeyState"; + proc get_key_state (v_key: i32) -> i16 #cc_std #link_name "GetKeyState"; + proc get_async_key_state(v_key: i32) -> i16 #cc_std #link_name "GetAsyncKeyState"; } foreign gdi32 { - proc get_stock_object(fn_object: i32) -> Hgdiobj #cc_c #link_name "GetStockObject"; + proc get_stock_object(fn_object: i32) -> Hgdiobj #cc_std #link_name "GetStockObject"; proc stretch_dibits( hdc: Hdc, x_dst, y_dst, width_dst, height_dst: i32, x_src, y_src, width_src, header_src: i32, bits: rawptr, bits_info: ^BitmapInfo, usage: u32, - rop: u32) -> i32 #cc_c #link_name "StretchDIBits"; + rop: u32) -> i32 #cc_std #link_name "StretchDIBits"; - proc set_pixel_format (hdc: Hdc, pixel_format: i32, pfd: ^PixelFormatDescriptor) -> Bool #cc_c #link_name "SetPixelFormat"; - proc choose_pixel_format(hdc: Hdc, pfd: ^PixelFormatDescriptor) -> i32 #cc_c #link_name "ChoosePixelFormat"; - proc swap_buffers (hdc: Hdc) -> Bool #cc_c #link_name "SwapBuffers"; + proc set_pixel_format (hdc: Hdc, pixel_format: i32, pfd: ^PixelFormatDescriptor) -> Bool #cc_std #link_name "SetPixelFormat"; + proc choose_pixel_format(hdc: Hdc, pfd: ^PixelFormatDescriptor) -> i32 #cc_std #link_name "ChoosePixelFormat"; + proc swap_buffers (hdc: Hdc) -> Bool #cc_std #link_name "SwapBuffers"; } foreign shell32 { - proc command_line_to_argv_w(cmd_list: ^u16, num_args: ^i32) -> ^^u16 #cc_c #link_name "CommandLineToArgvW"; + proc command_line_to_argv_w(cmd_list: ^u16, num_args: ^i32) -> ^^u16 #cc_std #link_name "CommandLineToArgvW"; } foreign winmm { - proc time_get_time() -> u32 #cc_c #link_name "timeGetTime"; + proc time_get_time() -> u32 #cc_std #link_name "timeGetTime"; } diff --git a/misc/shell.bat b/misc/shell.bat index 8785f82ed..8b7da6f80 100644 --- a/misc/shell.bat +++ b/misc/shell.bat @@ -1,6 +1,8 @@ @echo off -call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64 1> NUL +rem call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86 1> NUL +call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x64 1> NUL +rem call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64 1> NUL rem call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x86 1> NUL set _NO_DEBUG_HEAP=1 diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 92e14fa5b..05096bf52 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -1276,9 +1276,14 @@ Type *type_to_abi_compat_param_type(gbAllocator a, Type *original_type) { // SEE: https://msdn.microsoft.com/en-us/library/zthk2dkh.aspx Type *bt = core_type(original_type); switch (bt->kind) { - // Okay to pass by value + // Okay to pass by value (usually) // Especially the only Odin types - case Type_Basic: break; + case Type_Basic: { + i64 sz = bt->Basic.size; + if (sz > 8 && build_context.word_size < 8) { + new_type = make_type_pointer(a, original_type); + } + } break; case Type_Pointer: break; case Type_Proc: break; // NOTE(bill): Just a pointer @@ -1306,12 +1311,18 @@ Type *type_to_abi_compat_param_type(gbAllocator a, Type *original_type) { } } break; } - } else if (build_context.ODIN_OS == "linux") { + } else if (build_context.ODIN_OS == "linux" || + build_context.ODIN_OS == "osx") { Type *bt = core_type(original_type); switch (bt->kind) { - // Okay to pass by value + // Okay to pass by value (usually) // Especially the only Odin types - case Type_Basic: break; + case Type_Basic: { + i64 sz = bt->Basic.size; + if (sz > 8 && build_context.word_size < 8) { + new_type = make_type_pointer(a, original_type); + } + } break; case Type_Pointer: break; case Type_Proc: break; // NOTE(bill): Just a pointer @@ -1735,9 +1746,7 @@ void check_map_type(Checker *c, Type *type, AstNode *node) { { // NOTE(bill): The preload types may have not been set yet - if (t_map_key == NULL) { - init_preload(c); - } + init_preload(c); GB_ASSERT(t_map_key != NULL); Type *entry_type = make_type_struct(a); diff --git a/src/checker.cpp b/src/checker.cpp index 21265f9dd..eaa38aaa4 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -1206,10 +1206,6 @@ Entity *find_core_entity(Checker *c, String name) { } void init_preload(Checker *c) { - if (c->done_preload) { - return; - } - if (t_type_info == NULL) { Entity *type_info_entity = find_core_entity(c, str_lit("TypeInfo")); diff --git a/src/ir.cpp b/src/ir.cpp index 85fd98147..f5b431ec1 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -198,7 +198,7 @@ struct irProcedure { irValue *true_value; \ irValue *false_value; \ }) \ - IR_INSTR_KIND(Phi, struct { Array<irValue *> edges; Type *type; }) \ + IR_INSTR_KIND(Phi, struct { Array<irValue *> edges; Type *type; })\ IR_INSTR_KIND(Unreachable, i32) \ IR_INSTR_KIND(UnaryOp, struct { \ Type * type; \ @@ -218,26 +218,26 @@ struct irProcedure { isize arg_count; \ }) \ IR_INSTR_KIND(StartupRuntime, i32) \ - IR_INSTR_KIND(BoundsCheck, struct { \ - TokenPos pos; \ - irValue *index; \ - irValue *len; \ - }) \ - IR_INSTR_KIND(SliceBoundsCheck, struct { \ - TokenPos pos; \ - irValue *low; \ - irValue *high; \ - irValue *max; \ - bool is_substring; \ + IR_INSTR_KIND(DebugDeclare, struct { \ + irDebugInfo *debug_info; \ + AstNode * expr; \ + Entity * entity; \ + bool is_addr; \ + irValue * value; \ }) \ - IR_INSTR_KIND(DebugDeclare, struct { \ - irDebugInfo *debug_info; \ - AstNode * expr; \ - Entity * entity; \ - bool is_addr; \ - irValue * value; \ - }) \ +// IR_INSTR_KIND(BoundsCheck, struct { \ +// TokenPos pos; \ +// irValue *index; \ +// irValue *len; \ +// }) \ +// IR_INSTR_KIND(SliceBoundsCheck, struct { \ +// TokenPos pos; \ +// irValue *low; \ +// irValue *high; \ +// irValue *max; \ +// bool is_substring; \ +// }) \ #define IR_CONV_KINDS \ @@ -1011,22 +1011,6 @@ irValue *ir_instr_comment(irProcedure *p, String text) { return v; } -irValue *ir_instr_bounds_check(irProcedure *p, TokenPos pos, irValue *index, irValue *len) { - irValue *v = ir_alloc_instr(p, irInstr_BoundsCheck); - v->Instr.BoundsCheck.pos = pos; - v->Instr.BoundsCheck.index = index; - v->Instr.BoundsCheck.len = len; - return v; -} -irValue *ir_instr_slice_bounds_check(irProcedure *p, TokenPos pos, irValue *low, irValue *high, irValue *max, bool is_substring) { - irValue *v = ir_alloc_instr(p, irInstr_SliceBoundsCheck); - v->Instr.SliceBoundsCheck.pos = pos; - v->Instr.SliceBoundsCheck.low = low; - v->Instr.SliceBoundsCheck.high = high; - v->Instr.SliceBoundsCheck.max = max; - v->Instr.SliceBoundsCheck.is_substring = is_substring; - return v; -} irValue *ir_instr_debug_declare(irProcedure *p, irDebugInfo *debug_info, AstNode *expr, Entity *entity, bool is_addr, irValue *value) { irValue *v = ir_alloc_instr(p, irInstr_DebugDeclare); v->Instr.DebugDeclare.debug_info = debug_info; @@ -3443,7 +3427,21 @@ void ir_emit_bounds_check(irProcedure *proc, Token token, irValue *index, irValu index = ir_emit_conv(proc, index, t_int); len = ir_emit_conv(proc, len, t_int); - ir_emit(proc, ir_instr_bounds_check(proc, token.pos, index, len)); + gbAllocator a = proc->module->allocator; + irValue *file = ir_find_or_add_entity_string(proc->module, token.pos.file); + irValue *line = ir_const_int(a, token.pos.line); + irValue *column = ir_const_int(a, token.pos.column); + + irValue **args = gb_alloc_array(a, irValue *, 5); + args[0] = file; + args[1] = line; + args[2] = column; + args[3] = index; + args[4] = len; + + ir_emit_global_call(proc, "__bounds_check_error", args, 5); + + // ir_emit(proc, ir_instr_bounds_check(proc, token.pos, index, len)); } void ir_emit_slice_bounds_check(irProcedure *proc, Token token, irValue *low, irValue *high, irValue *max, bool is_substring) { @@ -3451,10 +3449,29 @@ void ir_emit_slice_bounds_check(irProcedure *proc, Token token, irValue *low, ir return; } + gbAllocator a = proc->module->allocator; + irValue *file = ir_find_or_add_entity_string(proc->module, token.pos.file); + irValue *line = ir_const_int(a, token.pos.line); + irValue *column = ir_const_int(a, token.pos.column); low = ir_emit_conv(proc, low, t_int); high = ir_emit_conv(proc, high, t_int); - ir_emit(proc, ir_instr_slice_bounds_check(proc, token.pos, low, high, max, is_substring)); + irValue **args = gb_alloc_array(a, irValue *, 6); + args[0] = file; + args[1] = line; + args[2] = column; + args[3] = low; + args[4] = high; + args[5] = max; + + if (is_substring) { + ir_emit_global_call(proc, "__substring_expr_error", args, 5); + } else { + ir_emit_global_call(proc, "__slice_expr_error", args, 6); + } + + + // ir_emit(proc, ir_instr_slice_bounds_check(proc, token.pos, low, high, max, is_substring)); } diff --git a/src/ir_opt.cpp b/src/ir_opt.cpp index c2c952b87..1900d2ed2 100644 --- a/src/ir_opt.cpp +++ b/src/ir_opt.cpp @@ -80,6 +80,8 @@ void ir_opt_add_operands(Array<irValue *> *ops, irInstr *i) { // break; case irInstr_StartupRuntime: break; + + #if 0 case irInstr_BoundsCheck: array_add(ops, i->BoundsCheck.index); array_add(ops, i->BoundsCheck.len); @@ -88,6 +90,7 @@ void ir_opt_add_operands(Array<irValue *> *ops, irInstr *i) { array_add(ops, i->SliceBoundsCheck.low); array_add(ops, i->SliceBoundsCheck.high); break; + #endif } } diff --git a/src/ir_print.cpp b/src/ir_print.cpp index 1328f9f6e..c39fc6acf 100644 --- a/src/ir_print.cpp +++ b/src/ir_print.cpp @@ -1391,6 +1391,7 @@ void ir_print_instr(irFileBuffer *f, irModule *m, irValue *value) { // ir_fprintf(f, "\n"); // } break; + #if 0 case irInstr_BoundsCheck: { irInstrBoundsCheck *bc = &instr->BoundsCheck; ir_fprintf(f, "call void "); @@ -1462,6 +1463,7 @@ void ir_print_instr(irFileBuffer *f, irModule *m, irValue *value) { ir_fprintf(f, ")\n"); } break; + #endif case irInstr_DebugDeclare: { /* irInstrDebugDeclare *dd = &instr->DebugDeclare; |