瀏覽代碼

Merge branch 'odin-lang:master' into raylib5

Michael 1 年之前
父節點
當前提交
3de15987bd

+ 2 - 4
core/runtime/default_allocators_nil.odin

@@ -35,7 +35,7 @@ nil_allocator :: proc() -> Allocator {
 when ODIN_OS == .Freestanding {
 when ODIN_OS == .Freestanding {
 	default_allocator_proc :: nil_allocator_proc
 	default_allocator_proc :: nil_allocator_proc
 	default_allocator :: nil_allocator
 	default_allocator :: nil_allocator
-} 
+}
 
 
 
 
 
 
@@ -78,9 +78,7 @@ panic_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
 
 
 panic_allocator :: proc() -> Allocator {
 panic_allocator :: proc() -> Allocator {
 	return Allocator{
 	return Allocator{
-		procedure = nil_allocator_proc,
+		procedure = panic_allocator_proc,
 		data = nil,
 		data = nil,
 	}
 	}
 }
 }
-
-

+ 34 - 0
core/slice/slice.odin

@@ -512,6 +512,40 @@ min_max :: proc(s: $S/[]$T) -> (min, max: T, ok: bool) where intrinsics.type_is_
 	return
 	return
 }
 }
 
 
+// Find the index of the (first) minimum element in a slice.
+@(require_results)
+min_index :: proc(s: $S/[]$T) -> (min_index: int, ok: bool) where intrinsics.type_is_ordered(T) #optional_ok {
+	if len(s) == 0 {
+		return -1, false
+	}
+	min_index = 0
+	min_value := s[0]
+	for v, i in s[1:] {
+		if v < min_value {
+			min_value = v
+			min_index = i+1
+		}
+	}
+	return min_index, true
+}
+
+// Find the index of the (first) maximum element in a slice.
+@(require_results)
+max_index :: proc(s: $S/[]$T) -> (max_index: int, ok: bool) where intrinsics.type_is_ordered(T) #optional_ok {
+	if len(s) == 0 {
+		return -1, false
+	}
+	max_index = 0
+	max_value := s[0]
+	for v, i in s[1:] {
+		if v > max_value {
+			max_value = v
+			max_index = i+1
+		}
+	}
+	return max_index, true
+}
+
 @(require_results)
 @(require_results)
 any_of :: proc(s: $S/[]$T, value: T) -> bool where intrinsics.type_is_comparable(T) {
 any_of :: proc(s: $S/[]$T, value: T) -> bool where intrinsics.type_is_comparable(T) {
 	for v in s {
 	for v in s {

+ 9 - 9
src/llvm_backend.cpp

@@ -21,8 +21,8 @@
 #include "llvm_backend_stmt.cpp"
 #include "llvm_backend_stmt.cpp"
 #include "llvm_backend_proc.cpp"
 #include "llvm_backend_proc.cpp"
 
 
-char *get_default_microarchitecture() {
-	char * default_march = "generic";
+String get_default_microarchitecture() {
+	String default_march = str_lit("generic");
 	if (build_context.metrics.arch == TargetArch_amd64) {
 	if (build_context.metrics.arch == TargetArch_amd64) {
 		// NOTE(bill): x86-64-v2 is more than enough for everyone
 		// NOTE(bill): x86-64-v2 is more than enough for everyone
 		//
 		//
@@ -32,9 +32,9 @@ char *get_default_microarchitecture() {
 		// x86-64-v4: AVX512F, AVX512BW, AVX512CD, AVX512DQ, AVX512VL
 		// x86-64-v4: AVX512F, AVX512BW, AVX512CD, AVX512DQ, AVX512VL
 		if (ODIN_LLVM_MINIMUM_VERSION_12) {
 		if (ODIN_LLVM_MINIMUM_VERSION_12) {
 			if (build_context.metrics.os == TargetOs_freestanding) {
 			if (build_context.metrics.os == TargetOs_freestanding) {
-				default_march = "x86-64";
+				default_march = str_lit("x86-64");
 			} else {
 			} else {
-				default_march = "x86-64-v2";
+				default_march = str_lit("x86-64-v2");
 			}
 			}
 		}
 		}
 	}
 	}
@@ -2509,16 +2509,16 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
 		code_mode = LLVMCodeModelKernel;
 		code_mode = LLVMCodeModelKernel;
 	}
 	}
 
 
-	char const *host_cpu_name = LLVMGetHostCPUName();
-	char const *llvm_cpu = get_default_microarchitecture();
+	String      host_cpu_name = copy_string(permanent_allocator(), make_string_c(LLVMGetHostCPUName()));
+	String      llvm_cpu      = get_default_microarchitecture();
 	char const *llvm_features = "";
 	char const *llvm_features = "";
 	if (build_context.microarch.len != 0) {
 	if (build_context.microarch.len != 0) {
 		if (build_context.microarch == "native") {
 		if (build_context.microarch == "native") {
 			llvm_cpu = host_cpu_name;
 			llvm_cpu = host_cpu_name;
 		} else {
 		} else {
-			llvm_cpu = alloc_cstring(permanent_allocator(), build_context.microarch);
+			llvm_cpu = copy_string(permanent_allocator(), build_context.microarch);
 		}
 		}
-		if (gb_strcmp(llvm_cpu, host_cpu_name) == 0) {
+		if (llvm_cpu == host_cpu_name) {
 			llvm_features = LLVMGetHostCPUFeatures();
 			llvm_features = LLVMGetHostCPUFeatures();
 		}
 		}
 	}
 	}
@@ -2578,7 +2578,7 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
 
 
 	for (auto const &entry : gen->modules) {
 	for (auto const &entry : gen->modules) {
 		LLVMTargetMachineRef target_machine = LLVMCreateTargetMachine(
 		LLVMTargetMachineRef target_machine = LLVMCreateTargetMachine(
-			target, target_triple, llvm_cpu,
+			target, target_triple, (const char *)llvm_cpu.text,
 			llvm_features,
 			llvm_features,
 			code_gen_level,
 			code_gen_level,
 			reloc_mode,
 			reloc_mode,

+ 2 - 2
src/main.cpp

@@ -2544,6 +2544,7 @@ int main(int arg_count, char const **arg_ptr) {
 		}
 		}
 	}
 	}
 
 
+	String default_march = get_default_microarchitecture();
 	if (print_microarch_list) {
 	if (print_microarch_list) {
 		if (build_context.microarch != "?") {
 		if (build_context.microarch != "?") {
 			gb_printf("Unknown microarchitecture '%.*s'.\n", LIT(build_context.microarch));
 			gb_printf("Unknown microarchitecture '%.*s'.\n", LIT(build_context.microarch));
@@ -2554,8 +2555,6 @@ int main(int arg_count, char const **arg_ptr) {
 		String march_list  = target_microarch_list[build_context.metrics.arch];
 		String march_list  = target_microarch_list[build_context.metrics.arch];
 		String_Iterator it = {march_list, 0};
 		String_Iterator it = {march_list, 0};
 
 
-		String default_march = make_string_c(get_default_microarchitecture());
-
 		for (;;) {
 		for (;;) {
 			String str = string_split_iterator(&it, ',');
 			String str = string_split_iterator(&it, ',');
 			if (str == "") break;
 			if (str == "") break;
@@ -2574,6 +2573,7 @@ int main(int arg_count, char const **arg_ptr) {
 	}
 	}
 
 
 	if (build_context.show_debug_messages) {
 	if (build_context.show_debug_messages) {
+		debugf("Selected microarch: %.*s\n", LIT(default_march));
 		for_array(i, build_context.build_paths) {
 		for_array(i, build_context.build_paths) {
 			String build_path = path_to_string(heap_allocator(), build_context.build_paths[i]);
 			String build_path = path_to_string(heap_allocator(), build_context.build_paths[i]);
 			debugf("build_paths[%ld]: %.*s\n", i, LIT(build_path));
 			debugf("build_paths[%ld]: %.*s\n", i, LIT(build_path));

+ 8 - 8
vendor/sdl2/sdl_pixels.odin

@@ -163,21 +163,21 @@ PixelFormatEnum :: enum u32 {
 	ABGR32 = ABGR8888 when ODIN_ENDIAN == .Big else RGBA8888,
 	ABGR32 = ABGR8888 when ODIN_ENDIAN == .Big else RGBA8888,
 
 
 	YV12 =      /**< Planar mode: Y + V + U  (3 planes) */
 	YV12 =      /**< Planar mode: Y + V + U  (3 planes) */
-		'Y'<<24 | 'V'<<16 | '1'<<8 | '2'<<0,
+		'Y'<<0 | 'V'<<8 | '1'<<16 | '2'<<24,
 	IYUV =      /**< Planar mode: Y + U + V  (3 planes) */
 	IYUV =      /**< Planar mode: Y + U + V  (3 planes) */
-		'I'<<24 | 'Y'<<16 | 'U'<<8 | 'V'<<0,
+		'I'<<0 | 'Y'<<8 | 'U'<<16 | 'V'<<24,
 	YUY2 =      /**< Packed mode: Y0+U0+Y1+V0 (1 plane) */
 	YUY2 =      /**< Packed mode: Y0+U0+Y1+V0 (1 plane) */
-		'Y'<<24 | 'U'<<16 | 'Y'<<8 | '2'<<0,
+		'Y'<<0 | 'U'<<8 | 'Y'<<16 | '2'<<24,
 	UYVY =      /**< Packed mode: U0+Y0+V0+Y1 (1 plane) */
 	UYVY =      /**< Packed mode: U0+Y0+V0+Y1 (1 plane) */
-		'U'<<24 | 'Y'<<16 | 'V'<<8 | 'Y'<<0,
+		'U'<<0 | 'Y'<<8 | 'V'<<16 | 'Y'<<24,
 	YVYU =      /**< Packed mode: Y0+V0+Y1+U0 (1 plane) */
 	YVYU =      /**< Packed mode: Y0+V0+Y1+U0 (1 plane) */
-		'Y'<<24 | 'V'<<16 | 'Y'<<8 | 'U'<<0,
+		'Y'<<0 | 'V'<<8 | 'Y'<<16 | 'U'<<24,
 	NV12 =      /**< Planar mode: Y + U/V interleaved  (2 planes) */
 	NV12 =      /**< Planar mode: Y + U/V interleaved  (2 planes) */
-		'N'<<24 | 'V'<<16 | '1'<<8 | '2'<<0,
+		'N'<<0 | 'V'<<8 | '1'<<16 | '2'<<24,
 	NV21 =      /**< Planar mode: Y + V/U interleaved  (2 planes) */
 	NV21 =      /**< Planar mode: Y + V/U interleaved  (2 planes) */
-		'N'<<24 | 'V'<<16 | '2'<<8 | '1'<<0,
+		'N'<<0 | 'V'<<8 | '2'<<16 | '1'<<24,
 	EXTERNAL_OES =      /**< Android video texture format */
 	EXTERNAL_OES =      /**< Android video texture format */
-		'O'<<24 | 'E'<<16 | 'S'<<8 | ' '<<0,
+		'O'<<0 | 'E'<<8 | 'S'<<16 | ' '<<24,
 }
 }
 
 
 
 

+ 3 - 2
vendor/x11/xlib/xlib_procs.odin

@@ -224,7 +224,7 @@ foreign xlib {
 	XGetWindowAttributes :: proc(
 	XGetWindowAttributes :: proc(
 		display: ^Display,
 		display: ^Display,
 		window:  Window,
 		window:  Window,
-		attr:    XWindowAttributes,
+		attr:    ^XWindowAttributes,
 		) ---
 		) ---
 	XGetGeometry :: proc(
 	XGetGeometry :: proc(
 		display:   ^Display,
 		display:   ^Display,
@@ -251,6 +251,7 @@ foreign xlib {
 		display: ^Display,
 		display: ^Display,
 		window:  Window,
 		window:  Window,
 		root:    ^Window,
 		root:    ^Window,
+		child:   ^Window,
 		root_x:  ^i32,
 		root_x:  ^i32,
 		root_y:  ^i32,
 		root_y:  ^i32,
 		x:       ^i32,
 		x:       ^i32,
@@ -394,7 +395,7 @@ foreign xlib {
 	XCreateColormap :: proc(
 	XCreateColormap :: proc(
 		display:  ^Display,
 		display:  ^Display,
 		window:   Window,
 		window:   Window,
-		visual:   Visual,
+		visual:   ^Visual,
 		alloc:    ColormapAlloc,
 		alloc:    ColormapAlloc,
 		) -> Colormap ---
 		) -> Colormap ---
 	XCopyColormapAndFree :: proc(
 	XCopyColormapAndFree :: proc(