Browse Source

Fix fmt.odin printing enums

Ginger Bill 8 years ago
parent
commit
eec709c545
2 changed files with 13 additions and 7 deletions
  1. 1 0
      build.bat
  2. 12 7
      core/fmt.odin

+ 1 - 0
build.bat

@@ -45,6 +45,7 @@ del *.ilk > NUL 2> NUL
 cl %compiler_settings% "src\main.c" ^
 cl %compiler_settings% "src\main.c" ^
 	/link %linker_settings% -OUT:%exe_name% ^
 	/link %linker_settings% -OUT:%exe_name% ^
 	&& odin run code/demo.odin
 	&& odin run code/demo.odin
+	rem && odin run code/Jaze/src/main.odin
 	rem && odin build_dll code/example.odin ^
 	rem && odin build_dll code/example.odin ^
 	rem odin run code/demo.odin
 	rem odin run code/demo.odin
 
 

+ 12 - 7
core/fmt.odin

@@ -268,7 +268,12 @@ buffer_write_type :: proc(buf: ^Buffer, ti: ^Type_Info) {
 		buffer_write_string(buf, "enum ");
 		buffer_write_string(buf, "enum ");
 		buffer_write_type(buf, info.base);
 		buffer_write_type(buf, info.base);
 		buffer_write_string(buf, " {");
 		buffer_write_string(buf, " {");
-
+		for name, i in info.names {
+			if i > 0 {
+				buffer_write_string(buf, ", ");
+			}
+			buffer_write_string(buf, name);
+		}
 		buffer_write_string(buf, "}");
 		buffer_write_string(buf, "}");
 	}
 	}
 }
 }
@@ -708,13 +713,13 @@ fmt_enum :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
 			case u32:  i = cast(i64)v;
 			case u32:  i = cast(i64)v;
 			case u64:  i = cast(i64)v;
 			case u64:  i = cast(i64)v;
 			case uint: i = cast(i64)v;
 			case uint: i = cast(i64)v;
-			case f32:  f = cast(f64)v;
-			case f64:  f = cast(f64)v;
+			case f32:  f = cast(f64)v; i = transmute(i64)f;
+			case f64:  f = cast(f64)v; i = transmute(i64)f;
 			}
 			}
 
 
 			if types.is_string(e.base) {
 			if types.is_string(e.base) {
-				for it, idx in e.values {
-					if it.i == i {
+				for val, idx in e.values {
+					if val.i == i {
 						buffer_write_string(fi.buf, e.names[idx]);
 						buffer_write_string(fi.buf, e.names[idx]);
 						ok = true;
 						ok = true;
 						break;
 						break;
@@ -724,8 +729,8 @@ fmt_enum :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
 				buffer_write_string(fi.buf, "");
 				buffer_write_string(fi.buf, "");
 				ok = true;
 				ok = true;
 			} else {
 			} else {
-				for it, idx in e.values {
-					if it.f == f {
+				for val, idx in e.values {
+					if val.i == i {
 						buffer_write_string(fi.buf, e.names[idx]);
 						buffer_write_string(fi.buf, e.names[idx]);
 						ok = true;
 						ok = true;
 						break;
 						break;