From 703e1aa2bcf6bb059a3dd0e12a02cf02ed5449cf Mon Sep 17 00:00:00 2001 From: Ginger Bill Date: Sat, 7 Jan 2017 11:44:42 +0000 Subject: [PATCH] Fix core library; Disable adding entity definitions for blank identifiers --- build.bat | 3 +- code/demo.odin | 71 +++------------------------------------ core/_preload.odin | 2 +- core/mem.odin | 33 ++++--------------- core/os_windows.odin | 77 ++++++++++++++++++++++--------------------- core/sys/windows.odin | 2 +- src/build.c | 2 +- src/checker/checker.c | 3 ++ 8 files changed, 56 insertions(+), 137 deletions(-) diff --git a/build.bat b/build.bat index 60d4ff79b..86c81eb3f 100644 --- a/build.bat +++ b/build.bat @@ -4,8 +4,7 @@ set exe_name=odin.exe :: Debug = 0, Release = 1 -set release_mode=1 - +set release_mode=0 set compiler_flags= -nologo -Oi -TC -fp:fast -fp:except- -Gm- -MP -FC -GS- -EHsc- -GR- if %release_mode% EQU 0 ( rem Debug diff --git a/code/demo.odin b/code/demo.odin index 4beb0b2a4..420ce5533 100644 --- a/code/demo.odin +++ b/code/demo.odin @@ -1,70 +1,7 @@ -#foreign_system_library "winmm" when ODIN_OS == "windows"; -#import win32 "sys/windows.odin" when ODIN_OS == "windows"; #import "fmt.odin"; -timeGetTime :: proc() -> u32 #foreign #dll_import -GetSystemTimeAsFileTime :: proc(SystemTimeAsFileTime : ^win32.FILETIME) #foreign #dll_import - -GetCommandLineArguments :: proc() -> []string { - argString := win32.GetCommandLineA(); - fullArgString := to_odin_string(argString); - // Count Spaces - for r : fullArgString { - fmt.println(r); - } -} - -to_odin_string :: proc(c: ^byte) -> string { - s: string; - s.data = c; - while (c + s.count)^ != 0 { - s.count += 1; - } - return s; -} -//("Hellope!\x00" as string).data - -MAGIC_VALUE :: 0xCA5E713F; - -timing_file_header :: struct #ordered { - MagicValue : u32; -} - -timing_file_date :: struct #ordered { - E : [2]u32; -} - -timing_file_entry_flag :: enum { - Complete = 0x1, - NoErrors = 0x2, -} - -timing_file_entry :: struct #ordered { - StarDate : timing_file_date; - Flags : u32; - MillisecondsElapsed : u32; -} - -timing_entry_array :: struct #ordered { - Entries : []timing_file_entry; -} - -GetClock :: proc () -> u32 { - return timeGetTime(); -} - -GetDate :: proc() -> timing_file_date { - Result : timing_file_date; - FileTime : win32.FILETIME; - GetSystemTimeAsFileTime(^FileTime); - - Result.E[0] = FileTime.lo; - Result.E[1] = FileTime.hi; - - return Result; -} - -main :: proc () { - EntryClock := GetClock(); - GetCommandLineArguments(); +main :: proc() { + x := "-stats"; + y := "-begin"; + fmt.println(x == y); } diff --git a/core/_preload.odin b/core/_preload.odin index d65f3d8e4..0d73e5462 100644 --- a/core/_preload.odin +++ b/core/_preload.odin @@ -308,7 +308,7 @@ __bounds_check_error :: proc(file: string, line, column: int, index, count: int) if 0 <= index && index < count { return; } - fmt.fprintf(os.stderr, "%(%:%) Index % is out of bounds range [0, %)\n", + fmt.fprintf(os.stderr, "%(%:%) Index % is out of bounds range 0..<%\n", file, line, column, index, count); __debug_trap(); } diff --git a/core/mem.odin b/core/mem.odin index f163a219f..ee358fef4 100644 --- a/core/mem.odin +++ b/core/mem.odin @@ -26,37 +26,16 @@ copy_non_overlapping :: proc(dst, src: rawptr, len: int) -> rawptr #link_name "_ } compare :: proc(dst, src: rawptr, n: int) -> int #link_name "__mem_compare" { - // Translation of http://mgronhol.github.io/fast-strcmp/ a := slice_ptr(dst as ^byte, n); b := slice_ptr(src as ^byte, n); - - fast := n/size_of(int) + 1; - offset := (fast-1)*size_of(int); - curr_block := 0; - if n <= size_of(int) { - fast = 0; - } - - la := slice_ptr(^a[0] as ^int, fast); - lb := slice_ptr(^b[0] as ^int, fast); - - for _ : curr_block ..< fast { - if (la[curr_block] ~ lb[curr_block]) != 0 { - for pos : curr_block*size_of(int) ..< n { - if (a[pos] ~ b[pos]) != 0 { - return a[pos] as int - b[pos] as int; - } - } - } - - } - - for _ : offset ..< n { - if (a[offset] ~ b[offset]) != 0 { - return a[offset] as int - b[offset] as int; + for i : 0.. b[i]: + return +1; } } - return 0; } diff --git a/core/os_windows.odin b/core/os_windows.odin index e63d3d8a7..8836504ce 100644 --- a/core/os_windows.odin +++ b/core/os_windows.odin @@ -2,11 +2,11 @@ #import "fmt.odin"; -Handle :: uint; +Handle :: int; File_Time :: u64; -Error :: int; +Errno :: int; -INVALID_HANDLE: Handle : ~(0 as Handle); +INVALID_HANDLE: Handle : -1; O_RDONLY :: 0x00000; @@ -22,37 +22,37 @@ O_SYNC :: 0x01000; O_ASYNC :: 0x02000; O_CLOEXEC :: 0x80000; -ERROR_NONE: Error : 0; -ERROR_FILE_NOT_FOUND: Error : 2; -ERROR_PATH_NOT_FOUND: Error : 3; -ERROR_ACCESS_DENIED: Error : 5; -ERROR_NO_MORE_FILES: Error : 18; -ERROR_HANDLE_EOF: Error : 38; -ERROR_NETNAME_DELETED: Error : 64; -ERROR_FILE_EXISTS: Error : 80; -ERROR_BROKEN_PIPE: Error : 109; -ERROR_BUFFER_OVERFLOW: Error : 111; -ERROR_INSUFFICIENT_BUFFER: Error : 122; -ERROR_MOD_NOT_FOUND: Error : 126; -ERROR_PROC_NOT_FOUND: Error : 127; -ERROR_DIR_NOT_EMPTY: Error : 145; -ERROR_ALREADY_EXISTS: Error : 183; -ERROR_ENVVAR_NOT_FOUND: Error : 203; -ERROR_MORE_DATA: Error : 234; -ERROR_OPERATION_ABORTED: Error : 995; -ERROR_IO_PENDING: Error : 997; -ERROR_NOT_FOUND: Error : 1168; -ERROR_PRIVILEGE_NOT_HELD: Error : 1314; -WSAEACCES: Error : 10013; -WSAECONNRESET: Error : 10054; +ERROR_NONE: Errno : 0; +ERROR_FILE_NOT_FOUND: Errno : 2; +ERROR_PATH_NOT_FOUND: Errno : 3; +ERROR_ACCESS_DENIED: Errno : 5; +ERROR_NO_MORE_FILES: Errno : 18; +ERROR_HANDLE_EOF: Errno : 38; +ERROR_NETNAME_DELETED: Errno : 64; +ERROR_FILE_EXISTS: Errno : 80; +ERROR_BROKEN_PIPE: Errno : 109; +ERROR_BUFFER_OVERFLOW: Errno : 111; +ERROR_INSUFFICIENT_BUFFER: Errno : 122; +ERROR_MOD_NOT_FOUND: Errno : 126; +ERROR_PROC_NOT_FOUND: Errno : 127; +ERROR_DIR_NOT_EMPTY: Errno : 145; +ERROR_ALREADY_EXISTS: Errno : 183; +ERROR_ENVVAR_NOT_FOUND: Errno : 203; +ERROR_MORE_DATA: Errno : 234; +ERROR_OPERATION_ABORTED: Errno : 995; +ERROR_IO_PENDING: Errno : 997; +ERROR_NOT_FOUND: Errno : 1168; +ERROR_PRIVILEGE_NOT_HELD: Errno : 1314; +WSAEACCES: Errno : 10013; +WSAECONNRESET: Errno : 10054; // Windows reserves errors >= 1<<29 for application use -ERROR_FILE_IS_PIPE: Error : 1<<29 + 0; +ERROR_FILE_IS_PIPE: Errno : 1<<29 + 0; -open :: proc(path: string, mode: int, perm: u32) -> (Handle, Error) { +open :: proc(path: string, mode: int, perm: u32) -> (Handle, Errno) { using win32; if path.count == 0 { return INVALID_HANDLE, ERROR_FILE_NOT_FOUND; @@ -98,37 +98,38 @@ open :: proc(path: string, mode: int, perm: u32) -> (Handle, Error) { copy(buf[:], path as []byte); handle := CreateFileA(^buf[0], access, share_mode, sa, create_mode, FILE_ATTRIBUTE_NORMAL, nil) as Handle; - if handle == INVALID_HANDLE { + if handle != INVALID_HANDLE { return handle, ERROR_NONE; } err := GetLastError(); - return INVALID_HANDLE, err as Error; + return INVALID_HANDLE, err as Errno; } close :: proc(fd: Handle) { win32.CloseHandle(fd as win32.HANDLE); } -write :: proc(fd: Handle, data: []byte) -> (int, Error) { +write :: proc(fd: Handle, data: []byte) -> (int, Errno) { bytes_written: i32; e := win32.WriteFile(fd as win32.HANDLE, data.data, data.count as i32, ^bytes_written, nil); - if e != 0 { - return 0, e as Error; + if e == win32.FALSE { + err := win32.GetLastError(); + return 0, err as Errno; } return bytes_written as int, ERROR_NONE; } -read :: proc(fd: Handle, data: []byte) -> (int, Error) { +read :: proc(fd: Handle, data: []byte) -> (int, Errno) { bytes_read: i32; e := win32.ReadFile(fd as win32.HANDLE, data.data, data.count as u32, ^bytes_read, nil); - if e != win32.FALSE { + if e == win32.FALSE { err := win32.GetLastError(); - return 0, err as Error; + return 0, err as Errno; } return bytes_read as int, ERROR_NONE; } -seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Error) { +seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) { using win32; w: u32; match whence { @@ -145,7 +146,7 @@ seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Error) { dw_ptr := SetFilePointer(fd as HANDLE, lo, ^hi, w); if dw_ptr == INVALID_SET_FILE_POINTER { err := GetLastError(); - return 0, err as Error; + return 0, err as Errno; } return (hi as i64)<<32 + (dw_ptr as i64), ERROR_NONE; } diff --git a/core/sys/windows.odin b/core/sys/windows.odin index 09b3eb68e..c5355b91c 100644 --- a/core/sys/windows.odin +++ b/core/sys/windows.odin @@ -175,7 +175,7 @@ CreateFileA :: proc(filename: ^u8, desired_access, share_mode: u32, security: rawptr, creation, flags_and_attribs: u32, template_file: HANDLE) -> HANDLE #foreign #dll_import ReadFile :: proc(h: HANDLE, buf: rawptr, to_read: u32, bytes_read: ^i32, overlapped: rawptr) -> BOOL #foreign #dll_import -WriteFile :: proc(h: HANDLE, buf: rawptr, len: i32, written_result: ^i32, overlapped: rawptr) -> i32 #foreign #dll_import +WriteFile :: proc(h: HANDLE, buf: rawptr, len: i32, written_result: ^i32, overlapped: rawptr) -> BOOL #foreign #dll_import GetFileSizeEx :: proc(file_handle: HANDLE, file_size: ^i64) -> BOOL #foreign #dll_import GetFileAttributesExA :: proc(filename: ^u8, info_level_id: GET_FILEEX_INFO_LEVELS, file_info: rawptr) -> BOOL #foreign #dll_import diff --git a/src/build.c b/src/build.c index f0fe02d77..6db7dcd6b 100644 --- a/src/build.c +++ b/src/build.c @@ -148,7 +148,7 @@ String get_filepath_extension(String path) { void init_build_context(BuildContext *bc) { bc->ODIN_VENDOR = str_lit("odin"); - bc->ODIN_VERSION = str_lit("0.0.5d"); + bc->ODIN_VERSION = str_lit("0.0.5e"); bc->ODIN_ROOT = odin_root_dir(); #if defined(GB_SYSTEM_WINDOWS) diff --git a/src/checker/checker.c b/src/checker/checker.c index cef1a606d..436a89391 100644 --- a/src/checker/checker.c +++ b/src/checker/checker.c @@ -722,6 +722,9 @@ void add_type_and_value(CheckerInfo *i, AstNode *expression, AddressingMode mode void add_entity_definition(CheckerInfo *i, AstNode *identifier, Entity *entity) { GB_ASSERT(identifier != NULL); if (identifier->kind == AstNode_Ident) { + if (str_eq(identifier->Ident.string, str_lit("_"))) { + return; + } HashKey key = hash_pointer(identifier); map_entity_set(&i->definitions, key, entity); } else {