Browse Source

Fix fmt printing `uintptr` type

gingerBill 7 years ago
parent
commit
6bc5584add
9 changed files with 77 additions and 73 deletions
  1. 4 3
      core/_preload.odin
  2. 12 11
      core/bits.odin
  3. 19 15
      core/fmt.odin
  4. 3 2
      core/math.odin
  5. 3 3
      core/mem.odin
  6. 26 25
      core/opengl.odin
  7. 1 1
      core/sys/wgl.odin
  8. 3 7
      core/thread.odin
  9. 6 6
      src/ir.cpp

+ 4 - 3
core/_preload.odin

@@ -38,6 +38,7 @@ Type_Info_Enum_Value :: union {
 	rune,
 	i8, i16, i32, i64, i128, int,
 	u8, u16, u32, u64, u128, uint,
+	uintptr,
 	f32, f64,
 };
 
@@ -687,13 +688,13 @@ __string_decode_rune :: inline proc "contextless" (s: string) -> (rune, int) {
 	return utf8.decode_rune(s);
 }
 
-__bounds_check_error_loc :: proc "contextless" (using loc := #caller_location, index, count: int) {
+__bounds_check_error_loc :: inline proc "contextless" (using loc := #caller_location, index, count: int) {
 	__bounds_check_error(file_path, int(line), int(column), index, count);
 }
-__slice_expr_error_loc :: proc "contextless" (using loc := #caller_location, low, high, max: int) {
+__slice_expr_error_loc :: inline proc "contextless" (using loc := #caller_location, low, high, max: int) {
 	__slice_expr_error(file_path, int(line), int(column), low, high, max);
 }
-__substring_expr_error_loc :: proc "contextless" (using loc := #caller_location, low, high: int) {
+__substring_expr_error_loc :: inline proc "contextless" (using loc := #caller_location, low, high: int) {
 	__substring_expr_error(file_path, int(line), int(column), low, high);
 }
 

+ 12 - 11
core/bits.odin

@@ -4,23 +4,24 @@ U32_MIN  ::  u32(0);
 U64_MIN  ::  u64(0);
 U128_MIN :: u128(0);
 
-I8_MIN   ::   i8(-0x80);
-I16_MIN  ::  i16(-0x8000);
-I32_MIN  ::  i32(-0x8000_0000);
-I64_MIN  ::  i64(-0x8000_0000_0000_0000);
-I128_MIN :: i128(-0x8000_0000_0000_0000_0000_0000_0000_0000);
-
 U8_MAX   ::   ~u8(0);
 U16_MAX  ::  ~u16(0);
 U32_MAX  ::  ~u32(0);
 U64_MAX  ::  ~u64(0);
 U128_MAX :: ~u128(0);
 
-I8_MAX   ::   i8(0x7f);
-I16_MAX  ::  i16(0x7fff);
-I32_MAX  ::  i32(0x7fff_ffff);
-I64_MAX  ::  i64(0x7fff_ffff_ffff_ffff);
-I128_MAX :: i128(0x7fff_ffff_ffff_ffff_ffff_ffff_ffff_ffff);
+I8_MIN   ::   i8(  ~u8(0) >> 1);
+I16_MIN  ::  i16( ~u16(0) >> 1);
+I32_MIN  ::  i32( ~u32(0) >> 1);
+I64_MIN  ::  i64( ~u64(0) >> 1);
+I128_MIN :: i128(~u128(0) >> 1);
+
+I8_MAX   ::   -I8_MIN - 1;
+I16_MAX  ::  -I16_MIN - 1;
+I32_MAX  ::  -I32_MIN - 1;
+I64_MAX  ::  -I64_MIN - 1;
+I128_MAX :: -I128_MIN - 1;
+
 
 count_ones :: proc(i:   u8) ->   u8 { foreign __llvm_core @(link_name="llvm.ctpop.i8")   __llvm_ctpop :: proc(u8)   ->   u8 ---; return __llvm_ctpop(i); }
 count_ones :: proc(i:   i8) ->   i8 { foreign __llvm_core @(link_name="llvm.ctpop.i8")   __llvm_ctpop :: proc(i8)   ->   i8 ---; return __llvm_ctpop(i); }

+ 19 - 15
core/fmt.odin

@@ -184,8 +184,9 @@ write_type :: proc(buf: ^String_Buffer, ti: ^Type_Info) {
 		write_string(buf, info.name);
 	case Type_Info_Integer:
 		switch {
-		case ti == type_info_of(int):  write_string(buf, "int");
-		case ti == type_info_of(uint): write_string(buf, "uint");
+		case ti == type_info_of(int):     write_string(buf, "int");
+		case ti == type_info_of(uint):    write_string(buf, "uint");
+		case ti == type_info_of(uintptr): write_string(buf, "uintptr");
 		case:
 			if info.signed do write_byte(buf, 'i');
 			else           do write_byte(buf, 'u');
@@ -674,19 +675,20 @@ enum_value_to_string :: proc(v: any) -> (string, bool) {
 
 		a := any{v.data, type_info_base(e.base)};
 		switch v in a {
-		case rune: return get_str(v, e);
-		case i8:   return get_str(v, e);
-		case i16:  return get_str(v, e);
-		case i32:  return get_str(v, e);
-		case i64:  return get_str(v, e);
-		case i128: return get_str(v, e);
-		case int:  return get_str(v, e);
-		case u8:   return get_str(v, e);
-		case u16:  return get_str(v, e);
-		case u32:  return get_str(v, e);
-		case u64:  return get_str(v, e);
-		case u128: return get_str(v, e);
-		case uint: return get_str(v, e);
+		case rune:    return get_str(v, e);
+		case i8:      return get_str(v, e);
+		case i16:     return get_str(v, e);
+		case i32:     return get_str(v, e);
+		case i64:     return get_str(v, e);
+		case i128:    return get_str(v, e);
+		case int:     return get_str(v, e);
+		case u8:      return get_str(v, e);
+		case u16:     return get_str(v, e);
+		case u32:     return get_str(v, e);
+		case u64:     return get_str(v, e);
+		case u128:    return get_str(v, e);
+		case uint:    return get_str(v, e);
+		case uintptr: return get_str(v, e);
 
 		case f32:  return get_str(v, e);
 		case f64:  return get_str(v, e);
@@ -1017,6 +1019,8 @@ fmt_arg :: proc(fi: ^Fmt_Info, arg: any, verb: rune) {
 	case i64:     fmt_int(fi, u128(a), true,  64, verb);
 	case i128:    fmt_int(fi, u128(a), true, 128, verb);
 
+	case uintptr: fmt_int(fi, u128(a), false, 8*size_of(uintptr), verb);
+
 	case uint:    fmt_int(fi, u128(a), false, 8*size_of(uint), verb);
 	case u8:      fmt_int(fi, u128(a), false, 8, verb);
 	case u16:     fmt_int(fi, u128(a), false, 16, verb);

+ 3 - 2
core/math.odin

@@ -27,6 +27,7 @@ Mat4 :: [4][4]f32;
 
 Complex :: complex64;
 
+@(default_calling_convention="c")
 foreign __llvm_core {
 	@(link_name="llvm.sqrt.f32")
 	sqrt :: proc(x: f32) -> f32 ---;
@@ -54,8 +55,8 @@ foreign __llvm_core {
 	fmuladd :: proc(a, b, c: f64) -> f64 ---;
 }
 
-tan    :: proc(θ: f32) -> f32 do return sin(θ)/cos(θ);
-tan    :: proc(θ: f64) -> f64 do return sin(θ)/cos(θ);
+tan :: proc "c" (θ: f32) -> f32 do return sin(θ)/cos(θ);
+tan :: proc "c" (θ: f64) -> f64 do return sin(θ)/cos(θ);
 
 lerp   :: proc(a, b: $T, t: $E) -> (x: T) do return a*(1-t) + b*t;
 

+ 3 - 3
core/mem.odin

@@ -1,9 +1,9 @@
 import "core:raw.odin"
 
 foreign __llvm_core {
-	@(link_name = "llvm.bswap.i16") swap :: proc(b: u16) -> u16  ---;
-	@(link_name = "llvm.bswap.i32") swap :: proc(b: u32) -> u32  ---;
-	@(link_name = "llvm.bswap.i64") swap :: proc(b: u64) -> u64  ---;
+	@(link_name = "llvm.bswap.i16") swap :: proc(b: u16) -> u16 ---;
+	@(link_name = "llvm.bswap.i32") swap :: proc(b: u32) -> u32 ---;
+	@(link_name = "llvm.bswap.i64") swap :: proc(b: u64) -> u64 ---;
 }
 
 set :: proc "contextless" (data: rawptr, value: i32, len: int) -> rawptr {

+ 26 - 25
core/opengl.odin

@@ -10,32 +10,33 @@ export "core:opengl_constants.odin"
 
 _ := compile_assert(ODIN_OS != "osx");
 
+@(default_calling_convention="c", link_prefix="gl")
 foreign lib {
-	@(link_name="glClear")          Clear          :: proc(mask: u32) ---;
-	@(link_name="glClearColor")     ClearColor     :: proc(r, g, b, a: f32) ---;
-	@(link_name="glBegin")          Begin          :: proc(mode: i32) ---;
-	@(link_name="glEnd")            End            :: proc() ---;
-	@(link_name="glFinish")         Finish         :: proc() ---;
-	@(link_name="glBlendFunc")      BlendFunc      :: proc(sfactor, dfactor: i32) ---;
-	@(link_name="glEnable")         Enable         :: proc(cap: i32) ---;
-	@(link_name="glDisable")        Disable        :: proc(cap: i32) ---;
-	@(link_name="glGenTextures")    GenTextures    :: proc(count: i32, result: ^u32) ---;
-	@(link_name="glDeleteTextures") DeleteTextures :: proc(count: i32, result: ^u32) ---;
-	@(link_name="glTexParameteri")  TexParameteri  :: proc(target, pname, param: i32) ---;
-	@(link_name="glTexParameterf")  TexParameterf  :: proc(target: i32, pname: i32, param: f32) ---;
-	@(link_name="glBindTexture")    BindTexture    :: proc(target: i32, texture: u32) ---;
-	@(link_name="glLoadIdentity")   LoadIdentity   :: proc() ---;
-	@(link_name="glViewport")       Viewport       :: proc(x, y, width, height: i32) ---;
-	@(link_name="glOrtho")          Ortho          :: proc(left, right, bottom, top, near, far: f64) ---;
-	@(link_name="glColor3f")        Color3f        :: proc(r, g, b: f32) ---;
-	@(link_name="glVertex3f")       Vertex3f       :: proc(x, y, z: f32) ---;
-	@(link_name="glGetError")       GetError       :: proc() -> i32 ---;
-	@(link_name="glGetString")      GetString      :: proc(name: i32) -> ^u8 ---;
-	@(link_name="glGetIntegerv")    GetIntegerv    :: proc(name: i32, v: ^i32) ---;
-	@(link_name="glTexCoord2f")     TexCoord2f     :: proc(x, y: f32) ---;
-	@(link_name="glTexImage2D")     TexImage2D     :: proc(target, level, internal_format,
-	                                                       width, height, border,
-	                                                       format, type_: i32, pixels: rawptr) ---;
+	Clear          :: proc(mask: u32) ---;
+	ClearColor     :: proc(r, g, b, a: f32) ---;
+	Begin          :: proc(mode: i32) ---;
+	End            :: proc() ---;
+	Finish         :: proc() ---;
+	BlendFunc      :: proc(sfactor, dfactor: i32) ---;
+	Enable         :: proc(cap: i32) ---;
+	Disable        :: proc(cap: i32) ---;
+	GenTextures    :: proc(count: i32, result: ^u32) ---;
+	DeleteTextures :: proc(count: i32, result: ^u32) ---;
+	TexParameteri  :: proc(target, pname, param: i32) ---;
+	TexParameterf  :: proc(target: i32, pname: i32, param: f32) ---;
+	BindTexture    :: proc(target: i32, texture: u32) ---;
+	LoadIdentity   :: proc() ---;
+	Viewport       :: proc(x, y, width, height: i32) ---;
+	Ortho          :: proc(left, right, bottom, top, near, far: f64) ---;
+	Color3f        :: proc(r, g, b: f32) ---;
+	Vertex3f       :: proc(x, y, z: f32) ---;
+	GetError       :: proc() -> i32 ---;
+	GetString      :: proc(name: i32) -> ^u8 ---;
+	GetIntegerv    :: proc(name: i32, v: ^i32) ---;
+	TexCoord2f     :: proc(x, y: f32) ---;
+	TexImage2D     :: proc(target, level, internal_format: i32,
+	                       width, height, border: i32,
+	                       format, type_: i32, pixels: rawptr) ---;
 }
 
 

+ 1 - 1
core/sys/wgl.odin

@@ -1,7 +1,7 @@
 when ODIN_OS == "windows" {
 	foreign import "system:opengl32.lib"
+	using import "core:sys/windows.odin"
 }
-using import "core:sys/windows.odin"
 
 
 CONTEXT_MAJOR_VERSION_ARB             :: 0x2091;

+ 3 - 7
core/thread.odin

@@ -25,11 +25,7 @@ Thread :: struct {
 create :: proc(procedure: Thread_Proc) -> ^Thread {
 	win32_thread_id: u32;
 
-	__windows_thread_entry_proc :: proc "c" (data: rawptr) -> i32 {
-		if data	== nil do return 0;
-
-		t := cast(^Thread)data;
-
+	__windows_thread_entry_proc :: proc "c" (t: ^Thread) -> i32 {
 		c := context;
 		if t.use_init_context {
 			c = t.init_context;
@@ -40,11 +36,11 @@ create :: proc(procedure: Thread_Proc) -> ^Thread {
 			exit = t.procedure(t);
 		}
 
-		return cast(i32)exit;
+		return i32(exit);
 	}
 
 
-	win32_thread_proc := cast(rawptr)__windows_thread_entry_proc;
+	win32_thread_proc := rawptr(__windows_thread_entry_proc);
 	thread := new(Thread);
 
 	win32_thread := win32.create_thread(nil, 0, win32_thread_proc, thread, win32.CREATE_SUSPENDED, &win32_thread_id);

+ 6 - 6
src/ir.cpp

@@ -376,12 +376,12 @@ enum irParamPasskind {
 };
 
 struct irValueParam {
-	irParamPasskind kind;
-	irProcedure *   parent;
-	Entity *        entity;
-	Type *          type;
-	Type *          original_type;
-	Array<irValue *>    referrers;
+	irParamPasskind  kind;
+	irProcedure *    parent;
+	Entity *         entity;
+	Type *           type;
+	Type *           original_type;
+	Array<irValue *> referrers;
 };
 
 struct irValue {