Browse Source

Extra type safety; Fix typos

Ginger Bill 8 years ago
parent
commit
0fae31fb54
17 changed files with 164 additions and 141 deletions
  1. 7 5
      build.bat
  2. 29 29
      core/os_x.odin
  3. 2 2
      src/build_settings.cpp
  4. 15 15
      src/check_expr.cpp
  5. 3 3
      src/check_stmt.cpp
  6. 1 1
      src/checker.cpp
  7. 25 2
      src/common.cpp
  8. 12 12
      src/exact_value.cpp
  9. 7 7
      src/gb/gb.h
  10. 37 37
      src/ir.cpp
  11. 2 2
      src/ir_opt.cpp
  12. 1 1
      src/ir_print.cpp
  13. 1 1
      src/main.cpp
  14. 6 7
      src/parser.cpp
  15. 6 6
      src/ssa.cpp
  16. 4 5
      src/string.cpp
  17. 6 6
      src/types.cpp

+ 7 - 5
build.bat

@@ -17,10 +17,13 @@ if %release_mode% EQU 0 ( rem Debug
 set compiler_warnings= ^
 	-W4 -WX ^
 	-wd4100 -wd4101 -wd4127 -wd4189 ^
-	-wd4201 -wd4204 -wd4244 ^
-	-wd4306 ^
-	-wd4456 -wd4457 -wd4480 ^
-	-wd4505 -wd4512 -wd4550
+	-wd4201 ^
+	-wd4512
+	rem -wd4100 -wd4101 -wd4127 -wd4189 ^
+	rem -wd4201 -wd4204 -wd4244 ^
+	rem -wd4306 ^
+	rem -wd4456 -wd4457 -wd4480 ^
+	rem -wd4505 -wd4512 -wd4550
 
 set compiler_includes=
 set libs= ^
@@ -38,7 +41,6 @@ if %release_mode% EQU 0 ( rem Debug
 set compiler_settings=%compiler_includes% %compiler_flags% %compiler_warnings%
 set linker_settings=%libs% %linker_flags%
 
-
 del *.pdb > NUL 2> NUL
 del *.ilk > NUL 2> NUL
 

+ 29 - 29
core/os_x.odin

@@ -108,13 +108,13 @@ S_ISUID :: 0004000; // Set user id on execution
 S_ISGID :: 0002000; // Set group id on execution
 S_ISVTX :: 0001000; // Directory restrcted delete
 
-S_ISLNK  :: proc(m: u32) -> bool #inline  {return (m & S_IFMT) == S_IFLNK; }
-S_ISREG  :: proc(m: u32) -> bool #inline  {return (m & S_IFMT) == S_IFREG; }
-S_ISDIR  :: proc(m: u32) -> bool #inline  {return (m & S_IFMT) == S_IFDIR; }
-S_ISCHR  :: proc(m: u32) -> bool #inline  {return (m & S_IFMT) == S_IFCHR; }
-S_ISBLK  :: proc(m: u32) -> bool #inline  {return (m & S_IFMT) == S_IFBLK; }
-S_ISFIFO :: proc(m: u32) -> bool #inline  {return (m & S_IFMT) == S_IFIFO; }
-S_ISSOCK :: proc(m: u32) -> bool #inline  {return (m & S_IFMT) == S_IFSOCK;}
+S_ISLNK  :: proc(m: u32) -> bool #inline do return (m & S_IFMT) == S_IFLNK;
+S_ISREG  :: proc(m: u32) -> bool #inline do return (m & S_IFMT) == S_IFREG;
+S_ISDIR  :: proc(m: u32) -> bool #inline do return (m & S_IFMT) == S_IFDIR;
+S_ISCHR  :: proc(m: u32) -> bool #inline do return (m & S_IFMT) == S_IFCHR;
+S_ISBLK  :: proc(m: u32) -> bool #inline do return (m & S_IFMT) == S_IFBLK;
+S_ISFIFO :: proc(m: u32) -> bool #inline do return (m & S_IFMT) == S_IFIFO;
+S_ISSOCK :: proc(m: u32) -> bool #inline do return (m & S_IFMT) == S_IFSOCK;
 
 R_OK :: 4; // Test for read permission
 W_OK :: 2; // Test for write permission
@@ -122,28 +122,28 @@ X_OK :: 1; // Test for execute permission
 F_OK :: 0; // Test for file existance
 
 foreign libc {
-	unix_open    :: proc(path: ^u8, mode: int) -> Handle                              #link_name "open"    ---;
-	unix_close   :: proc(handle: Handle)                                              #link_name "close"   ---;
-	unix_read    :: proc(handle: Handle, buffer: rawptr, count: int) -> int   #link_name "read"    ---;
-	unix_write   :: proc(handle: Handle, buffer: rawptr, count: int) -> int   #link_name "write"   ---;
-	unix_lseek   :: proc(fs: Handle, offset: int, whence: int) -> int #link_name "lseek"   ---;
-	unix_gettid  :: proc() -> u64                                                     #link_name "gettid"  ---;
-	unix_stat    :: proc(path: ^u8, stat: ^Stat) -> int                               #link_name "stat"    ---;
-	unix_access  :: proc(path: ^u8, mask: int) -> int                                 #link_name "access"  ---;
-
-	unix_malloc  :: proc(size: int) -> rawptr                                         #link_name "malloc"  ---;
-	unix_free    :: proc(ptr: rawptr)                                                 #link_name "free"    ---;
-	unix_realloc :: proc(ptr: rawptr, size: int) -> rawptr                            #link_name "realloc" ---;
-	unix_getenv  :: proc(^u8) -> ^u8                                                  #link_name "getenv"  ---;
-
-	unix_exit    :: proc(status: int)                                                 #link_name "exit"    ---;
+	unix_open    :: proc(path: ^u8, mode: int) -> Handle                    #link_name "open"    ---;
+	unix_close   :: proc(handle: Handle)                                    #link_name "close"   ---;
+	unix_read    :: proc(handle: Handle, buffer: rawptr, count: int) -> int #link_name "read"    ---;
+	unix_write   :: proc(handle: Handle, buffer: rawptr, count: int) -> int #link_name "write"   ---;
+	unix_lseek   :: proc(fs: Handle, offset: int, whence: int) -> int       #link_name "lseek"   ---;
+	unix_gettid  :: proc() -> u64                                           #link_name "gettid"  ---;
+	unix_stat    :: proc(path: ^u8, stat: ^Stat) -> int                     #link_name "stat"    ---;
+	unix_access  :: proc(path: ^u8, mask: int) -> int                       #link_name "access"  ---;
+
+	unix_malloc  :: proc(size: int) -> rawptr                               #link_name "malloc"  ---;
+	unix_free    :: proc(ptr: rawptr)                                       #link_name "free"    ---;
+	unix_realloc :: proc(ptr: rawptr, size: int) -> rawptr                  #link_name "realloc" ---;
+	unix_getenv  :: proc(^u8) -> ^u8                                        #link_name "getenv"  ---;
+
+	unix_exit    :: proc(status: int)                                       #link_name "exit"    ---;
 }
 
 foreign dl {
-	unix_dlopen  :: proc(filename: ^u8, flags: int) -> rawptr                         #link_name "dlopen"  ---;
-	unix_dlsym   :: proc(handle: rawptr, symbol: ^u8) ->  (proc() #cc_c)              #link_name "dlsym"   ---;
-	unix_dlclose :: proc(handle: rawptr) -> int                                       #link_name "dlclose" ---;
-	unix_dlerror :: proc() -> ^u8                                                     #link_name "dlerror" ---;
+	unix_dlopen  :: proc(filename: ^u8, flags: int) -> rawptr               #link_name "dlopen"  ---;
+	unix_dlsym   :: proc(handle: rawptr, symbol: ^u8) ->  (proc() #cc_c)    #link_name "dlsym"   ---;
+	unix_dlclose :: proc(handle: rawptr) -> int                             #link_name "dlclose" ---;
+	unix_dlerror :: proc() -> ^u8                                           #link_name "dlerror" ---;
 }
 
 // TODO(zangent): Change this to just `open` when Bill fixes overloading.
@@ -187,10 +187,10 @@ read :: proc(fd: Handle, data: []u8) -> (int, Errno) {
 	return bytes_read, 0;
 }
 
-seek :: proc(fd: Handle, offset: int, whence: int) -> (int, Errno) {
+seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
 	assert(fd != -1);
 
-	final_offset := unix_lseek(fd, offset, whence);
+	final_offset := i64(unix_lseek(fd, offset, whence));
 	if(final_offset == -1) {
 		return 0, 1;
 	}
@@ -201,7 +201,7 @@ file_size :: proc(fd: Handle) -> (i64, Errno) {
 	prev, _   := seek(fd, 0, SEEK_CUR);
 	size, err := seek(fd, 0, SEEK_END);
 	seek(fd, prev, SEEK_SET);
-	return size, err;
+	return i64(size), err;
 }
 
 

+ 2 - 2
src/build_settings.cpp

@@ -57,7 +57,7 @@ String odin_root_dir(void) {
 
 	len = 0;
 	for (;;) {
-		len = GetModuleFileNameW(nullptr, &path_buf[0], path_buf.count);
+		len = GetModuleFileNameW(nullptr, &path_buf[0], cast(int)path_buf.count);
 		if (len == 0) {
 			return make_string(nullptr, 0);
 		}
@@ -73,7 +73,7 @@ String odin_root_dir(void) {
 
 	text = gb_alloc_array(string_buffer_allocator, wchar_t, len+1);
 
-	GetModuleFileNameW(nullptr, text, len);
+	GetModuleFileNameW(nullptr, text, cast(int)len);
 	path = string16_to_string(heap_allocator(), make_string16(text, len));
 
 	for (i = path.len-1; i >= 0; i--) {

+ 15 - 15
src/check_expr.cpp

@@ -494,7 +494,7 @@ i64 check_distance_between_types(Checker *c, Operand *operand, Type *type) {
 		Type *bfv = base_type(operand->type);
 		i32 bits = bfv->BitFieldValue.bits;
 		i32 size = next_pow2((bits+7)/8);
-		i32 dst_size = type_size_of(c->allocator, type);
+		i32 dst_size = cast(i32)type_size_of(c->allocator, type);
 		i32 diff = gb_abs(dst_size - size);
 		// TODO(bill): figure out a decent rule here
 		return 1;
@@ -1279,7 +1279,7 @@ void check_struct_type(Checker *c, Type *struct_type, AstNode *node, Array<Opera
 			gb_sort_array(reordered_fields.data, fields.count, cmp_reorder_struct_fields);
 
 			for_array(i, fields) {
-				reordered_fields[i]->Variable.field_index = i;
+				reordered_fields[i]->Variable.field_index = cast(i32)i;
 			}
 
 			struct_type->Struct.fields = reordered_fields;
@@ -1564,7 +1564,7 @@ void check_enum_type(Checker *c, Type *enum_type, Type *named_type, AstNode *nod
 
 
 	enum_type->Enum.fields      = fields.data;
-	enum_type->Enum.field_count = fields.count;
+	enum_type->Enum.field_count = cast(i32)fields.count;
 
 	enum_type->Enum.count = make_entity_constant(c->allocator, c->context.scope,
 		make_token_ident(str_lit("count")), t_int, exact_value_i64(fields.count));
@@ -1622,7 +1622,7 @@ void check_bit_field_type(Checker *c, Type *bit_field_type, Type *named_type, As
 			continue;
 		}
 
-		Type *value_type = make_type_bit_field_value(c->allocator, bits);
+		Type *value_type = make_type_bit_field_value(c->allocator, cast(i32)bits);
 		Entity *e = make_entity_variable(c->allocator, bit_field_type->BitField.scope, ident->Ident.token, value_type, false);
 		e->identifier = ident;
 		e->flags |= EntityFlag_BitFieldValue;
@@ -1638,16 +1638,16 @@ void check_bit_field_type(Checker *c, Type *bit_field_type, Type *named_type, As
 
 			fields [field_count] = e;
 			offsets[field_count] = curr_offset;
-			sizes  [field_count] = bits;
+			sizes  [field_count] = cast(i32)bits;
 			field_count++;
 
-			curr_offset += bits;
+			curr_offset += cast(i32)bits;
 		}
 	}
 	GB_ASSERT(field_count <= bft->fields.count);
 
 	bit_field_type->BitField.fields      = fields;
-	bit_field_type->BitField.field_count = field_count;
+	bit_field_type->BitField.field_count = cast(i32)field_count;
 	bit_field_type->BitField.sizes       = sizes;
 	bit_field_type->BitField.offsets     = offsets;
 
@@ -2180,7 +2180,7 @@ Type *check_get_params(Checker *c, Scope *scope, AstNode *_params, bool *is_vari
 	if (scope != nullptr) {
 		for_array(i, scope->elements.entries) {
 			Entity *e = scope->elements.entries[i].value;
-			if (e->kind == Type_Named) {
+			if (e->kind == Entity_TypeName) {
 				Type *t = e->type;
 				if (t->kind == Type_Generic &&
 				    t->Generic.specialized != nullptr) {
@@ -2523,9 +2523,9 @@ bool check_procedure_type(Checker *c, Type *type, AstNode *proc_type_node, Array
 	type->Proc.node                 = proc_type_node;
 	type->Proc.scope                = c->context.scope;
 	type->Proc.params               = params;
-	type->Proc.param_count          = param_count;
+	type->Proc.param_count          = cast(i32)param_count;
 	type->Proc.results              = results;
-	type->Proc.result_count         = result_count;
+	type->Proc.result_count         = cast(i32)result_count;
 	type->Proc.variadic             = variadic;
 	type->Proc.calling_convention   = pt->calling_convention;
 	type->Proc.is_polymorphic       = pt->generic;
@@ -3341,12 +3341,12 @@ bool check_representable_as_constant(Checker *c, ExactValue in_value, Type *type
 		i64 s = 8*type_size_of(c->allocator, type);
 		u128 umax = U128_NEG_ONE;
 		if (s < 128) {
-			umax = u128_sub(u128_shl(U128_ONE, s), U128_ONE);
+			umax = u128_sub(u128_shl(U128_ONE, cast(u32)s), U128_ONE);
 		} else {
 			// IMPORTANT TODO(bill): I NEED A PROPER BIG NUMBER LIBRARY THAT CAN SUPPORT 128 bit floats
 			s = 128;
 		}
-		i128 imax = i128_shl(I128_ONE, s-1ll);
+		i128 imax = i128_shl(I128_ONE, cast(u32)s-1);
 
 		switch (type->Basic.kind) {
 		case Basic_rune:
@@ -4399,8 +4399,8 @@ void convert_to_typed(Checker *c, Operand *operand, Type *target_type, i32 level
 			defer (gb_temp_arena_memory_end(tmp));
 			isize count = t->Union.variants.count;
 			ValidIndexAndScore *valids = gb_alloc_array(c->tmp_allocator, ValidIndexAndScore, count);
-			i32 valid_count = 0;
-			i32 first_success_index = -1;
+			isize valid_count = 0;
+			isize first_success_index = -1;
 			for_array(i, t->Union.variants) {
 				Type *vt = t->Union.variants[i];
 				i64 score = 0;
@@ -5693,7 +5693,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
 		gbAllocator a = c->allocator;
 
 		Type *tuple = make_type_tuple(a);
-		i32 variable_count = type->Struct.fields.count;
+		isize variable_count = type->Struct.fields.count;
 		array_init_count(&tuple->Tuple.variables, a, variable_count);
 		// TODO(bill): Should I copy each of the entities or is this good enough?
 		gb_memcopy_array(tuple->Tuple.variables.data, type->Struct.fields_in_src_order.data, variable_count);

+ 3 - 3
src/check_stmt.cpp

@@ -4,7 +4,7 @@ void check_stmt_list(Checker *c, Array<AstNode *> stmts, u32 flags) {
 	}
 
 	if (flags&Stmt_CheckScopeDecls) {
-		check_scope_decls(c, stmts, 1.2*stmts.count);
+		check_scope_decls(c, stmts, cast(isize)(1.2*stmts.count));
 	}
 
 	bool ft_ok = (flags & Stmt_FallthroughAllowed) != 0;
@@ -265,9 +265,9 @@ Type *check_assignment_variable(Checker *c, Operand *rhs, AstNode *lhs_node) {
 					u128 u = *cast(u128 *)&i;
 					u128 umax = U128_NEG_ONE;
 					if (lhs_bits < 128) {
-						umax = u128_sub(u128_shl(U128_ONE, lhs_bits), U128_ONE);
+						umax = u128_sub(u128_shl(U128_ONE, cast(u32)lhs_bits), U128_ONE);
 					}
-					i128 imax = i128_shl(I128_ONE, lhs_bits-1ll);
+					i128 imax = i128_shl(I128_ONE, cast(u32)lhs_bits-1);
 
 					bool ok = false;
 					ok = !(u128_lt(u, U128_ZERO) || u128_gt(u, umax));

+ 1 - 1
src/checker.cpp

@@ -267,7 +267,7 @@ struct DelayedDecl {
 };
 
 struct CheckerFileNode {
-	i32        id;
+	isize      id;
 	Array<i32> wheres;
 	Array<i32> whats;
 	i32        score; // Higher the score, the better

+ 25 - 2
src/common.cpp

@@ -199,7 +199,19 @@ gbAllocator pool_allocator(Pool *pool) {
 
 
 
-
+i32 next_pow2(i32 n) {
+	if (n <= 0) {
+		return 0;
+	}
+	n--;
+	n |= n >> 1;
+	n |= n >> 2;
+	n |= n >> 4;
+	n |= n >> 8;
+	n |= n >> 16;
+	n++;
+	return n;
+}
 i64 next_pow2(i64 n) {
 	if (n <= 0) {
 		return 0;
@@ -215,6 +227,17 @@ i64 next_pow2(i64 n) {
 	return n;
 }
 
+i32 prev_pow2(i32 n) {
+	if (n <= 0) {
+		return 0;
+	}
+	n |= n >> 1;
+	n |= n >> 2;
+	n |= n >> 4;
+	n |= n >> 8;
+	n |= n >> 16;
+	return n - (n >> 1);
+}
 i64 prev_pow2(i64 n) {
 	if (n <= 0) {
 		return 0;
@@ -310,7 +333,7 @@ f64 gb_sqrt(f64 x) {
 wchar_t **command_line_to_wargv(wchar_t *cmd_line, int *_argc) {
 	u32 i, j;
 
-	u32 len = string16_len(cmd_line);
+	u32 len = cast(u32)string16_len(cmd_line);
 	i = ((len+2)/2)*gb_size_of(void *) + gb_size_of(void *);
 
 	wchar_t **argv = cast(wchar_t **)GlobalAlloc(GMEM_FIXED, i + (len+2)*gb_size_of(wchar_t));

+ 12 - 12
src/exact_value.cpp

@@ -504,19 +504,19 @@ ExactValue exact_binary_operator_value(TokenKind op, ExactValue x, ExactValue y)
 		i128 b = y.value_integer;
 		i128 c = I128_ZERO;
 		switch (op) {
-		case Token_Add:    c = a + b;               break;
-		case Token_Sub:    c = a - b;               break;
-		case Token_Mul:    c = a * b;               break;
+		case Token_Add:    c = a + b;                        break;
+		case Token_Sub:    c = a - b;                        break;
+		case Token_Mul:    c = a * b;                        break;
 		case Token_Quo:    return exact_value_float(fmod(i128_to_f64(a), i128_to_f64(b)));
-		case Token_QuoEq:  c = a / b;               break; // NOTE(bill): Integer division
-		case Token_Mod:    c = a % b;               break;
-		case Token_ModMod: c = ((a % b) + b) % b;   break;
-		case Token_And:    c = a & b;               break;
-		case Token_Or:     c = a | b;               break;
-		case Token_Xor:    c = a ^ b;               break;
-		case Token_AndNot: c = i128_and_not(a, b);  break;
-		case Token_Shl:    c = a << i128_to_u64(b); break;
-		case Token_Shr:    c = a >> i128_to_u64(b); break;
+		case Token_QuoEq:  c = a / b;                        break; // NOTE(bill): Integer division
+		case Token_Mod:    c = a % b;                        break;
+		case Token_ModMod: c = ((a % b) + b) % b;            break;
+		case Token_And:    c = a & b;                        break;
+		case Token_Or:     c = a | b;                        break;
+		case Token_Xor:    c = a ^ b;                        break;
+		case Token_AndNot: c = i128_and_not(a, b);           break;
+		case Token_Shl:    c = a << cast(u32)i128_to_u64(b); break;
+		case Token_Shr:    c = a >> cast(u32)i128_to_u64(b); break;
 		default: goto error;
 		}
 

+ 7 - 7
src/gb/gb.h

@@ -985,7 +985,7 @@ typedef struct gbThread {
 } gbThread;
 
 GB_DEF void gb_thread_init            (gbThread *t);
-GB_DEF void gb_thread_destory         (gbThread *t);
+GB_DEF void gb_thread_destroy         (gbThread *t);
 GB_DEF void gb_thread_start           (gbThread *t, gbThreadProc *proc, void *data);
 GB_DEF void gb_thread_start_with_stack(gbThread *t, gbThreadProc *proc, void *data, isize stack_size);
 GB_DEF void gb_thread_join            (gbThread *t);
@@ -4698,7 +4698,7 @@ void gb_thread_init(gbThread *t) {
 	gb_semaphore_init(&t->semaphore);
 }
 
-void gb_thread_destory(gbThread *t) {
+void gb_thread_destroy(gbThread *t) {
 	if (t->is_running) gb_thread_join(t);
 	gb_semaphore_destroy(&t->semaphore);
 }
@@ -7472,13 +7472,13 @@ u64 gb_murmur64_seed(void const *data_, isize len, u64 seed) {
 			if (w_len_) *w_len_ = w_len;
 			return NULL;
 		}
-		w_len = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, text, len, NULL, 0);
+		w_len = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, text, cast(int)len, NULL, 0);
 		if (w_len == 0) {
 			if (w_len_) *w_len_ = w_len;
 			return NULL;
 		}
 		w_text = gb_alloc_array(a, wchar_t, w_len+1);
-		w_len1 = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, text, len, w_text, w_len);
+		w_len1 = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, text, cast(int)len, w_text, cast(int)w_len);
 		if (w_len1 == 0) {
 			gb_free(a, w_text);
 			if (w_len_) *w_len_ = 0;
@@ -8126,17 +8126,17 @@ char *gb_path_get_full_name(gbAllocator a, char const *path) {
 		return NULL;
 	}
 	w_fullpath = gb_alloc_array(gb_heap_allocator(), wchar_t, w_len+1);
-	GetFullPathNameW(w_path, w_len, w_fullpath, NULL);
+	GetFullPathNameW(w_path, cast(int)w_len, w_fullpath, NULL);
 	w_fullpath[w_len] = 0;
 	gb_free(gb_heap_allocator(), w_path);
 
-	new_len = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, w_fullpath, w_len, NULL, 0, NULL, NULL);
+	new_len = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, w_fullpath, cast(int)w_len, NULL, 0, NULL, NULL);
 	if (new_len == 0) {
 		gb_free(gb_heap_allocator(), w_fullpath);
 		return NULL;
 	}
 	new_path = gb_alloc_array(a, char, new_len+1);
-	new_len1 = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, w_fullpath, w_len, new_path, new_len, NULL, NULL);
+	new_len1 = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, w_fullpath, cast(int)w_len, new_path, cast(int)new_len, NULL, NULL);
 	if (new_len1 == 0) {
 		gb_free(gb_heap_allocator(), w_fullpath);
 		gb_free(a, new_path);

+ 37 - 37
src/ir.cpp

@@ -13,7 +13,7 @@ struct irModule {
 	gbAllocator   tmp_allocator;
 	// bool generate_debug_info;
 
-	u32 stmt_state_flags;
+	u64 stmt_state_flags;
 
 	// String source_filename;
 	String layout;
@@ -442,7 +442,7 @@ irAddr ir_addr_map(irValue *addr, irValue *map_key, Type *map_type, Type *map_re
 	return v;
 }
 
-irAddr ir_addr_bit_field(irValue *addr, isize bit_field_value_index) {
+irAddr ir_addr_bit_field(irValue *addr, i32 bit_field_value_index) {
 	irAddr v = {irAddr_BitField, addr};
 	v.bit_field_value_index = bit_field_value_index;
 	return v;
@@ -3435,7 +3435,7 @@ irValue *ir_type_info(irProcedure *proc, Type *type) {
 
 	type = default_type(type);
 
-	i32 entry_index = type_info_index(info, type);
+	i32 entry_index = cast(i32)type_info_index(info, type);
 
 	// gb_printf_err("%d %s\n", entry_index, type_to_string(type));
 
@@ -4454,7 +4454,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
 			Entity *field = t->Struct.fields_in_src_order[src_index];
 			i32 field_index = field->Variable.field_index;
 			irValue *f = ir_emit_struct_ev(proc, s, field_index);
-			irValue *ep = ir_emit_struct_ep(proc, tuple, src_index);
+			irValue *ep = ir_emit_struct_ep(proc, tuple, cast(i32)src_index);
 			ir_emit_store(proc, ep, f);
 		}
 		return ir_emit_load(proc, tuple);
@@ -4901,7 +4901,7 @@ irValue *ir_build_expr(irProcedure *proc, AstNode *expr) {
 				if (at->kind == Type_Tuple) {
 					for_array(i, at->Tuple.variables) {
 						Entity *e = at->Tuple.variables[i];
-						irValue *v = ir_emit_struct_ev(proc, a, i);
+						irValue *v = ir_emit_struct_ev(proc, a, cast(i32)i);
 						args[arg_index++] = v;
 					}
 				} else {
@@ -5001,7 +5001,7 @@ irValue *ir_build_expr(irProcedure *proc, AstNode *expr) {
 				irValue *base_array = ir_add_local_generated(proc, make_type_array(allocator, elem_type, slice_len));
 
 				for (isize i = type->param_count-1, j = 0; i < arg_count; i++, j++) {
-					irValue *addr = ir_emit_array_epi(proc, base_array, j);
+					irValue *addr = ir_emit_array_epi(proc, base_array, cast(i32)j);
 					ir_emit_store(proc, addr, args[i]);
 				}
 
@@ -5497,7 +5497,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
 				isize index_count = bt->Vector.count;
 				irValue *elem_val = ir_build_expr(proc, cl->elems[0]);
 				for (isize i = 0; i < index_count; i++) {
-					ir_emit_store(proc, ir_emit_array_epi(proc, v, i), elem_val);
+					ir_emit_store(proc, ir_emit_array_epi(proc, v, cast(i32)i), elem_val);
 				}
 			} else if (cl->elems.count > 0) {
 				ir_emit_store(proc, v, ir_add_module_constant(proc->module, type, exact_value_compound(expr)));
@@ -5510,7 +5510,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
 					Type *t = ir_type(field_expr);
 					GB_ASSERT(t->kind != Type_Tuple);
 					irValue *ev = ir_emit_conv(proc, field_expr, et);
-					irValue *gep = ir_emit_array_epi(proc, v, i);
+					irValue *gep = ir_emit_array_epi(proc, v, cast(i32)i);
 					ir_emit_store(proc, gep, ev);
 				}
 			}
@@ -5556,7 +5556,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
 					GB_ASSERT(ir_type(field_expr)->kind != Type_Tuple);
 
 					irValue *fv = ir_emit_conv(proc, field_expr, ft);
-					irValue *gep = ir_emit_struct_ep(proc, v, index);
+					irValue *gep = ir_emit_struct_ep(proc, v, cast(i32)index);
 					ir_emit_store(proc, gep, fv);
 				}
 			}
@@ -5585,7 +5585,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
 			for_array(field_index, cl->elems) {
 				AstNode *f = cl->elems[field_index];
 				irValue *value = ir_emit_conv(proc, ir_build_expr(proc, f), elem);
-				irValue *ep = ir_emit_array_epi(proc, items, field_index);
+				irValue *ep = ir_emit_array_epi(proc, items, cast(i32)field_index);
 				ir_emit_store(proc, ep, value);
 			}
 
@@ -5633,7 +5633,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
 					Type *t = ir_type(field_expr);
 					GB_ASSERT(t->kind != Type_Tuple);
 					irValue *ev = ir_emit_conv(proc, field_expr, et);
-					irValue *gep = ir_emit_array_epi(proc, v, i);
+					irValue *gep = ir_emit_array_epi(proc, v, cast(i32)i);
 					ir_emit_store(proc, gep, ev);
 				}
 			}
@@ -5703,7 +5703,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
 
 					Type *ft = field_types[index];
 					irValue *fv = ir_emit_conv(proc, field_expr, ft);
-					irValue *gep = ir_emit_struct_ep(proc, v, index);
+					irValue *gep = ir_emit_struct_ep(proc, v, cast(i32)index);
 					ir_emit_store(proc, gep, fv);
 				}
 			}
@@ -5936,11 +5936,11 @@ void ir_build_stmt_list(irProcedure *proc, Array<AstNode *> stmts) {
 
 void ir_build_stmt_internal(irProcedure *proc, AstNode *node);
 void ir_build_stmt(irProcedure *proc, AstNode *node) {
-	u32 prev_stmt_state_flags = proc->module->stmt_state_flags;
+	u64 prev_stmt_state_flags = proc->module->stmt_state_flags;
 
 	if (node->stmt_state_flags != 0) {
-		u32 in = node->stmt_state_flags;
-		u32 out = proc->module->stmt_state_flags;
+		u64 in = node->stmt_state_flags;
+		u64 out = proc->module->stmt_state_flags;
 
 		if (in & StmtStateFlag_bounds_check) {
 			out |= StmtStateFlag_bounds_check;
@@ -6285,7 +6285,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
 					if (t->kind == Type_Tuple) {
 						for_array(i, t->Tuple.variables) {
 							Entity *e = t->Tuple.variables[i];
-							irValue *v = ir_emit_struct_ev(proc, init, i);
+							irValue *v = ir_emit_struct_ev(proc, init, cast(i32)i);
 							array_add(&inits, v);
 						}
 					} else {
@@ -6350,7 +6350,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
 					if (t->kind == Type_Tuple) {
 						for_array(i, t->Tuple.variables) {
 							Entity *e = t->Tuple.variables[i];
-							irValue *v = ir_emit_struct_ev(proc, init, i);
+							irValue *v = ir_emit_struct_ev(proc, init, cast(i32)i);
 							array_add(&inits, v);
 						}
 					} else {
@@ -6445,7 +6445,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
 				Type *ret_type = proc->type->Proc.results;
 				v = ir_add_local_generated(proc, ret_type);
 				for_array(i, results) {
-					irValue *field = ir_emit_struct_ep(proc, v, i);
+					irValue *field = ir_emit_struct_ep(proc, v, cast(i32)i);
 					irValue *res = results[i];
 					ir_emit_store(proc, field, res);
 				}
@@ -6481,7 +6481,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
 				if (t->kind == Type_Tuple) {
 					for_array(i, t->Tuple.variables) {
 						Entity *e = t->Tuple.variables[i];
-						irValue *v = ir_emit_struct_ev(proc, res, i);
+						irValue *v = ir_emit_struct_ev(proc, res, cast(i32)i);
 						array_add(&results, v);
 						total_index++;
 					}
@@ -6509,7 +6509,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
 			for_array(i, results) {
 				Entity *e = tuple->variables[i];
 				irValue *res = ir_emit_conv(proc, results[i], e->type);
-				irValue *field = ir_emit_struct_ep(proc, v, i);
+				irValue *field = ir_emit_struct_ep(proc, v, cast(i32)i);
 				ir_emit_store(proc, field, res);
 			}
 
@@ -7111,7 +7111,7 @@ void ir_number_proc_registers(irProcedure *proc) {
 	i32 reg_index = 0;
 	for_array(i, proc->blocks) {
 		irBlock *b = proc->blocks[i];
-		b->index = i;
+		b->index = cast(i32)i;
 		for_array(j, b->instrs) {
 			irValue *value = b->instrs[j];
 			GB_ASSERT_MSG(value->kind == irValue_Instr, "%.*s", LIT(proc->name));
@@ -7255,11 +7255,11 @@ void ir_build_proc(irValue *value, irProcedure *parent) {
 	}
 
 	if (proc->body != nullptr) {
-		u32 prev_stmt_state_flags = proc->module->stmt_state_flags;
+		u64 prev_stmt_state_flags = proc->module->stmt_state_flags;
 
 		if (proc->tags != 0) {
-			u32 in = proc->tags;
-			u32 out = proc->module->stmt_state_flags;
+			u64 in = proc->tags;
+			u64 out = proc->module->stmt_state_flags;
 			if (in & ProcTag_bounds_check) {
 				out |= StmtStateFlag_bounds_check;
 				out &= ~StmtStateFlag_no_bounds_check;
@@ -7483,22 +7483,22 @@ irValue *ir_get_type_info_ptr(irProcedure *proc, Type *type) {
 
 irValue *ir_type_info_member_types_offset(irProcedure *proc, isize count) {
 	irValue *offset = ir_emit_array_epi(proc, ir_global_type_info_member_types, ir_global_type_info_member_types_index);
-	ir_global_type_info_member_types_index += count;
+	ir_global_type_info_member_types_index += cast(i32)count;
 	return offset;
 }
 irValue *ir_type_info_member_names_offset(irProcedure *proc, isize count) {
 	irValue *offset = ir_emit_array_epi(proc, ir_global_type_info_member_names, ir_global_type_info_member_names_index);
-	ir_global_type_info_member_names_index += count;
+	ir_global_type_info_member_names_index += cast(i32)count;
 	return offset;
 }
 irValue *ir_type_info_member_offsets_offset(irProcedure *proc, isize count) {
 	irValue *offset = ir_emit_array_epi(proc, ir_global_type_info_member_offsets, ir_global_type_info_member_offsets_index);
-	ir_global_type_info_member_offsets_index += count;
+	ir_global_type_info_member_offsets_index += cast(i32)count;
 	return offset;
 }
 irValue *ir_type_info_member_usings_offset(irProcedure *proc, isize count) {
 	irValue *offset = ir_emit_array_epi(proc, ir_global_type_info_member_usings, ir_global_type_info_member_usings_index);
-	ir_global_type_info_member_usings_index += count;
+	ir_global_type_info_member_usings_index += cast(i32)count;
 	return offset;
 }
 
@@ -7706,7 +7706,7 @@ void ir_gen_tree(irGen *s) {
 	for_array(i, m->debug_info.entries) {
 		auto *entry = &m->debug_info.entries[i];
 		irDebugInfo *di = entry->value;
-		di->id = i;
+		di->id = cast(i32)i;
 		if (di->kind == irDebugInfo_Proc) {
 			all_proc_max_count++;
 		}
@@ -7942,7 +7942,7 @@ void ir_gen_tree(irGen *s) {
 				isize entry_index = type_info_index(info, t);
 
 				irValue *tag = nullptr;
-				irValue *ti_ptr = ir_emit_array_epi(proc, ir_global_type_info_data, entry_index);
+				irValue *ti_ptr = ir_emit_array_epi(proc, ir_global_type_info_data, cast(i32)entry_index);
 				irValue *variant_ptr = ir_emit_struct_ep(proc, ti_ptr, 2);
 
 				ir_emit_store(proc, ir_emit_struct_ep(proc, ti_ptr, 0), ir_const_int(a, type_size_of(a, t)));
@@ -8134,8 +8134,8 @@ void ir_gen_tree(irGen *s) {
 							}
 
 							for (isize i = 0; i < count; i++) {
-								irValue *name_ep  = ir_emit_array_epi(proc, name_array, i);
-								irValue *value_ep = ir_emit_array_epi(proc, value_array, i);
+								irValue *name_ep  = ir_emit_array_epi(proc, name_array, cast(i32)i);
+								irValue *value_ep = ir_emit_array_epi(proc, value_array, cast(i32)i);
 
 								ExactValue value = fields[i]->Constant.value;
 								irValue *v = ir_value_constant(a, t->Enum.base_type, value);
@@ -8202,7 +8202,7 @@ void ir_gen_tree(irGen *s) {
 						ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 7), is_custom_align);
 					}
 
-					i32 count = t->Struct.fields.count;
+					isize count = t->Struct.fields.count;
 
 					irValue *memory_types   = ir_type_info_member_types_offset  (proc, count);
 					irValue *memory_names   = ir_type_info_member_names_offset  (proc, count);
@@ -8271,9 +8271,9 @@ void ir_gen_tree(irGen *s) {
 							Entity *f = fields[i];
 							GB_ASSERT(f->type != nullptr);
 							GB_ASSERT(f->type->kind == Type_BitFieldValue);
-							irValue *name_ep   = ir_emit_array_epi(proc, name_array,   i);
-							irValue *bit_ep    = ir_emit_array_epi(proc, bit_array,    i);
-							irValue *offset_ep = ir_emit_array_epi(proc, offset_array, i);
+							irValue *name_ep   = ir_emit_array_epi(proc, name_array,   cast(i32)i);
+							irValue *bit_ep    = ir_emit_array_epi(proc, bit_array,    cast(i32)i);
+							irValue *offset_ep = ir_emit_array_epi(proc, offset_array, cast(i32)i);
 
 							ir_emit_store(proc, name_ep, ir_const_string(a, f->token.string));
 							ir_emit_store(proc, bit_ep, ir_const_u32(a, f->type->BitFieldValue.bits));
@@ -8336,7 +8336,7 @@ void ir_gen_tree(irGen *s) {
 	for_array(i, m->debug_info.entries) {
 		auto *entry = &m->debug_info.entries[i];
 		irDebugInfo *di = entry->value;
-		di->id = i;
+		di->id = cast(i32)i;
 	}
 
 

+ 2 - 2
src/ir_opt.cpp

@@ -172,7 +172,7 @@ void ir_remove_dead_blocks(irProcedure *proc) {
 			continue;
 		}
 		// NOTE(bill): Swap order
-		b->index = j;
+		b->index = cast(i32)j;
 		proc->blocks[j++] = b;
 	}
 	proc->blocks.count = j;
@@ -373,7 +373,7 @@ void ir_opt_build_dom_tree(irProcedure *proc) {
 
 	gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&proc->module->tmp_arena);
 
-	isize n = proc->blocks.count;
+	i32 n = cast(i32)proc->blocks.count;
 	irBlock **buf = gb_alloc_array(proc->module->tmp_allocator, irBlock *, 5*n);
 
 	irLTState lt = {0};

+ 1 - 1
src/ir_print.cpp

@@ -686,7 +686,7 @@ void ir_print_exact_value(irFileBuffer *f, irModule *m, ExactValue value, Type *
 			ir_write_string(f, "zeroinitializer");
 		} else {
 			if (is_type_struct(type)) {
-				i32 value_count = type->Struct.fields.count;
+				i32 value_count = cast(i32)type->Struct.fields.count;
 				if (type->Struct.is_packed) ir_write_byte(f, '<');
 				ir_write_byte(f, '{');
 				if (type->Struct.custom_align > 0) {

+ 1 - 1
src/main.cpp

@@ -542,7 +542,7 @@ int main(int arg_count, char **arg_ptr) {
 
 	String output_name = ir_gen.output_name;
 	String output_base = ir_gen.output_base;
-	int base_name_len = output_base.len;
+	int base_name_len = cast(int)output_base.len;
 
 	build_context.optimization_level = gb_clamp(build_context.optimization_level, 0, 3);
 

+ 6 - 7
src/parser.cpp

@@ -36,7 +36,7 @@ struct ImportedFile {
 
 
 struct AstFile {
-	i32            id;
+	isize          id;
 	gbArena        arena;
 	Tokenizer      tokenizer;
 	Array<Token>   tokens;
@@ -1574,7 +1574,7 @@ AstNode *ast_foreign_library_spec(AstFile *f, Token filepath, Token library_name
 
 
 bool next_token0(AstFile *f) {
-	Token prev = f->curr_token;
+	// Token prev = f->curr_token;
 	if (f->curr_token_index+1 < f->tokens.count) {
 		f->curr_token = f->tokens[++f->curr_token_index];
 		return true;
@@ -1675,10 +1675,9 @@ TokenKind look_ahead_token_kind(AstFile *f, isize amount) {
 Token expect_token(AstFile *f, TokenKind kind) {
 	Token prev = f->curr_token;
 	if (prev.kind != kind) {
+		String c = token_strings[kind];
 		String p = token_strings[prev.kind];
-		syntax_error(f->curr_token, "Expected `%.*s`, got `%.*s`",
-		             LIT(token_strings[kind]),
-		             LIT(token_strings[prev.kind]));
+		syntax_error(f->curr_token, "Expected `%.*s`, got `%.*s`", LIT(c), LIT(p));
 		if (prev.kind == Token_EOF) {
 			gb_exit(1);
 		}
@@ -5122,7 +5121,7 @@ ParseFileError parse_files(Parser *p, String init_filename) {
 				} else if (p->curr_import_index < p->imports.count) {
 					if (t->return_value != 0) {
 						for_array(i, worker_threads) {
-							gb_thread_destory(&worker_threads[i]);
+							gb_thread_destroy(&worker_threads[i]);
 						}
 						return cast(ParseFileError)t->return_value;
 					}
@@ -5137,7 +5136,7 @@ ParseFileError parse_files(Parser *p, String init_filename) {
 		}
 
 		for_array(i, worker_threads) {
-			gb_thread_destory(&worker_threads[i]);
+			gb_thread_destroy(&worker_threads[i]);
 		}
 	} else {
 		for_array(i, p->imports) {

+ 6 - 6
src/ssa.cpp

@@ -1640,18 +1640,18 @@ ssaValue *ssa_build_expr(ssaProc *p, AstNode *expr) {
 
 			i64 s = 8*type_size_of(p->allocator, t);
 			switch (s) {
-			case 8:  return ssa_const_i8 (p, tv.type, i128_to_i64(tv.value.value_integer));
-			case 16: return ssa_const_i16(p, tv.type, i128_to_i64(tv.value.value_integer));
-			case 32: return ssa_const_i32(p, tv.type, i128_to_i64(tv.value.value_integer));
-			case 64: return ssa_const_i64(p, tv.type, i128_to_i64(tv.value.value_integer));
+			case 8:  return ssa_const_i8 (p, tv.type, cast (i8)i128_to_i64(tv.value.value_integer));
+			case 16: return ssa_const_i16(p, tv.type, cast(i16)i128_to_i64(tv.value.value_integer));
+			case 32: return ssa_const_i32(p, tv.type, cast(i32)i128_to_i64(tv.value.value_integer));
+			case 64: return ssa_const_i64(p, tv.type, cast(i64)i128_to_i64(tv.value.value_integer));
 			default: GB_PANIC("Unknown integer size");
 			}
 		} else if (is_type_float(t)) {
 			GB_ASSERT(tv.value.kind == ExactValue_Float);
 			i64 s = 8*type_size_of(p->allocator, t);
 			switch (s) {
-			case 32: return ssa_const_f32(p, tv.type, tv.value.value_float);
-			case 64: return ssa_const_f64(p, tv.type, tv.value.value_float);
+			case 32: return ssa_const_f32(p, tv.type, cast(f32)tv.value.value_float);
+			case 64: return ssa_const_f64(p, tv.type, cast(f64)tv.value.value_float);
 			default: GB_PANIC("Unknown float size");
 			}
 		}

+ 4 - 5
src/string.cpp

@@ -196,7 +196,6 @@ gb_inline bool str_has_prefix(String s, String prefix) {
 gb_inline isize string_extension_position(String str) {
 	isize dot_pos = -1;
 	isize i = str.len;
-	bool seen_dot = false;
 	while (i --> 0) {
 		if (str[i] == GB_PATH_SEPARATOR)
 			break;
@@ -317,14 +316,14 @@ String16 string_to_string16(gbAllocator a, String s) {
 		return make_string16(nullptr, 0);
 	}
 
-	len = convert_multibyte_to_widechar(cast(char *)s.text, s.len, nullptr, 0);
+	len = convert_multibyte_to_widechar(cast(char *)s.text, cast(int)s.len, nullptr, 0);
 	if (len == 0) {
 		return make_string16(nullptr, 0);
 	}
 
 	text = gb_alloc_array(a, wchar_t, len+1);
 
-	len1 = convert_multibyte_to_widechar(cast(char *)s.text, s.len, text, len);
+	len1 = convert_multibyte_to_widechar(cast(char *)s.text, cast(int)s.len, text, cast(int)len);
 	if (len1 == 0) {
 		gb_free(a, text);
 		return make_string16(nullptr, 0);
@@ -343,7 +342,7 @@ String string16_to_string(gbAllocator a, String16 s) {
 		return make_string(nullptr, 0);
 	}
 
-	len = convert_widechar_to_multibyte(s.text, s.len, nullptr, 0);
+	len = convert_widechar_to_multibyte(s.text, cast(int)s.len, nullptr, 0);
 	if (len == 0) {
 		return make_string(nullptr, 0);
 	}
@@ -351,7 +350,7 @@ String string16_to_string(gbAllocator a, String16 s) {
 
 	text = gb_alloc_array(a, u8, len+1);
 
-	len1 = convert_widechar_to_multibyte(s.text, s.len, cast(char *)text, len);
+	len1 = convert_widechar_to_multibyte(s.text, cast(int)s.len, cast(char *)text, cast(int)len);
 	if (len1 == 0) {
 		gb_free(a, text);
 		return make_string(nullptr, 0);

+ 6 - 6
src/types.cpp

@@ -551,9 +551,9 @@ Type *make_type_proc(gbAllocator a, Scope *scope, Type *params, isize param_coun
 
 	t->Proc.scope        = scope;
 	t->Proc.params       = params;
-	t->Proc.param_count  = param_count;
+	t->Proc.param_count  = cast(i32)param_count;
 	t->Proc.results      = results;
-	t->Proc.result_count = result_count;
+	t->Proc.result_count = cast(i32)result_count;
 	t->Proc.variadic     = variadic;
 	t->Proc.calling_convention = calling_convention;
 	return t;
@@ -1400,7 +1400,7 @@ Selection lookup_field_from_index(gbAllocator a, Type *type, i64 index) {
 	GB_ASSERT(is_type_struct(type) || is_type_union(type) || is_type_tuple(type));
 	type = base_type(type);
 
-	i64 max_count = 0;
+	isize max_count = 0;
 	switch (type->kind) {
 	case Type_Struct:   max_count = type->Struct.fields.count;   break;
 	case Type_Tuple:    max_count = type->Tuple.variables.count; break;
@@ -1419,7 +1419,7 @@ Selection lookup_field_from_index(gbAllocator a, Type *type, i64 index) {
 				if (f->Variable.field_src_index == index) {
 					Array<i32> sel_array = {0};
 					array_init_count(&sel_array, a, 1);
-					sel_array[0] = i;
+					sel_array[0] = cast(i32)i;
 					return make_selection(f, sel_array, false);
 				}
 			}
@@ -1431,7 +1431,7 @@ Selection lookup_field_from_index(gbAllocator a, Type *type, i64 index) {
 			if (i == index) {
 				Array<i32> sel_array = {0};
 				array_init_count(&sel_array, a, 1);
-				sel_array[0] = i;
+				sel_array[0] = cast(i32)i;
 				return make_selection(f, sel_array, false);
 			}
 		}
@@ -2192,7 +2192,7 @@ i64 type_offset_of_from_selection(gbAllocator allocator, Type *type, Selection s
 	Type *t = type;
 	i64 offset = 0;
 	for_array(i, sel.index) {
-		isize index = sel.index[i];
+		i32 index = sel.index[i];
 		t = base_type(t);
 		offset += type_offset_of(allocator, t, index);
 		if (t->kind == Type_Struct && !t->Struct.is_raw_union) {