| author | |
| committer | |
| log | a2ac06dcd506fd5e119e4eb8e1de201fefa05bbc |
| tree | 65fdd42a0a6f19b729dd44d2ed95abd4a6905f06 |
| parent | 37d167f6e0e26e8dc57950cb0fa1bfa630036521 |
4 files changed, 16 insertions(+), 22 deletions(-)
std/debug.zig+1-1| ... | @@ -10,7 +10,7 @@ pub fn printStackTrace() { | ... | @@ -10,7 +10,7 @@ pub fn printStackTrace() { |
| 10 | while (true) { | 10 | while (true) { |
| 11 | const fp = maybe_fp ?? break; | 11 | const fp = maybe_fp ?? break; |
| 12 | const return_address = *(&const usize)(usize(fp) + @sizeOf(usize)); | 12 | const return_address = *(&const usize)(usize(fp) + @sizeOf(usize)); |
| 13 | %%io.stderr.print_u64(return_address); | 13 | %%io.stderr.printInt(usize, return_address); |
| 14 | %%io.stderr.printf("\n"); | 14 | %%io.stderr.printf("\n"); |
| 15 | maybe_fp = *(&const ?&const u8)(fp); | 15 | maybe_fp = *(&const ?&const u8)(fp); |
| 16 | } | 16 | } |
std/io.zig+9-15| ... | @@ -94,23 +94,13 @@ pub struct OutStream { | ... | @@ -94,23 +94,13 @@ pub struct OutStream { |
| 94 | return byte_count; | 94 | return byte_count; |
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | pub fn print_u64(os: &OutStream, x: u64) -> %usize { | 97 | pub fn printInt(os: &OutStream, inline T: type, x: T) -> %usize { |
| 98 | // TODO replace max_u64_base10_digits with math.log10(math.pow(2, @sizeOf(T))) | ||
| 98 | if (os.index + max_u64_base10_digits >= os.buffer.len) { | 99 | if (os.index + max_u64_base10_digits >= os.buffer.len) { |
| 99 | %return os.flush(); | 100 | %return os.flush(); |
| 100 | } | 101 | } |
| 101 | const amt_printed = bufPrintUnsigned(u64, os.buffer[os.index...], x); | 102 | const amt_printed = bufPrintInt(T, os.buffer[os.index...], x); |
| 102 | os.index += amt_printed; | 103 | os.index += amt_printed; |
| 103 | |||
| 104 | return amt_printed; | ||
| 105 | } | ||
| 106 | |||
| 107 | pub fn print_i64(os: &OutStream, x: i64) -> %usize { | ||
| 108 | if (os.index + max_u64_base10_digits >= os.buffer.len) { | ||
| 109 | %return os.flush(); | ||
| 110 | } | ||
| 111 | const amt_printed = bufPrintSigned(i64, os.buffer[os.index...], x); | ||
| 112 | os.index += amt_printed; | ||
| 113 | |||
| 114 | return amt_printed; | 104 | return amt_printed; |
| 115 | } | 105 | } |
| 116 | 106 | ||
| ... | @@ -234,7 +224,11 @@ fn charToDigit(c: u8, radix: u8) -> %u8 { | ... | @@ -234,7 +224,11 @@ fn charToDigit(c: u8, radix: u8) -> %u8 { |
| 234 | return if (value >= radix) error.InvalidChar else value; | 224 | return if (value >= radix) error.InvalidChar else value; |
| 235 | } | 225 | } |
| 236 | 226 | ||
| 237 | pub fn bufPrintSigned(inline T: type, out_buf: []u8, x: T) -> usize { | 227 | pub fn bufPrintInt(inline T: type, out_buf: []u8, x: T) -> usize { |
| 228 | if (T.is_signed) bufPrintSigned(T, out_buf, x) else bufPrintUnsigned(T, out_buf, x) | ||
| 229 | } | ||
| 230 | |||
| 231 | fn bufPrintSigned(inline T: type, out_buf: []u8, x: T) -> usize { | ||
| 238 | const uint = @intType(false, T.bit_count); | 232 | const uint = @intType(false, T.bit_count); |
| 239 | if (x < 0) { | 233 | if (x < 0) { |
| 240 | out_buf[0] = '-'; | 234 | out_buf[0] = '-'; |
| ... | @@ -244,7 +238,7 @@ pub fn bufPrintSigned(inline T: type, out_buf: []u8, x: T) -> usize { | ... | @@ -244,7 +238,7 @@ pub fn bufPrintSigned(inline T: type, out_buf: []u8, x: T) -> usize { |
| 244 | } | 238 | } |
| 245 | } | 239 | } |
| 246 | 240 | ||
| 247 | pub fn bufPrintUnsigned(inline T: type, out_buf: []u8, x: T) -> usize { | 241 | fn bufPrintUnsigned(inline T: type, out_buf: []u8, x: T) -> usize { |
| 248 | var buf: [max_u64_base10_digits]u8 = undefined; | 242 | var buf: [max_u64_base10_digits]u8 = undefined; |
| 249 | var a = x; | 243 | var a = x; |
| 250 | var index: usize = buf.len; | 244 | var index: usize = buf.len; |
std/test_runner.zig+2-2| ... | @@ -11,9 +11,9 @@ pub fn runTests() -> %void { | ... | @@ -11,9 +11,9 @@ pub fn runTests() -> %void { |
| 11 | for (zig_test_fn_list) |testFn, i| { | 11 | for (zig_test_fn_list) |testFn, i| { |
| 12 | // TODO: print var args | 12 | // TODO: print var args |
| 13 | %%io.stderr.write("Test "); | 13 | %%io.stderr.write("Test "); |
| 14 | %%io.stderr.print_u64(i + 1); | 14 | %%io.stderr.printInt(@typeOf(i), i + 1); |
| 15 | %%io.stderr.write("/"); | 15 | %%io.stderr.write("/"); |
| 16 | %%io.stderr.print_u64(zig_test_fn_list.len); | 16 | %%io.stderr.printInt(@typeOf(zig_test_fn_list.len), zig_test_fn_list.len); |
| 17 | %%io.stderr.write(" "); | 17 | %%io.stderr.write(" "); |
| 18 | %%io.stderr.write(testFn.name); | 18 | %%io.stderr.write(testFn.name); |
| 19 | %%io.stderr.write("..."); | 19 | %%io.stderr.write("..."); |
test/run_tests.cpp+4-4| ... | @@ -462,20 +462,20 @@ const io = @import("std").io; | ... | @@ -462,20 +462,20 @@ const io = @import("std").io; |
| 462 | pub fn main(args: [][]u8) -> %void { | 462 | pub fn main(args: [][]u8) -> %void { |
| 463 | const array = []u8 {9, 8, 7, 6}; | 463 | const array = []u8 {9, 8, 7, 6}; |
| 464 | for (array) |item| { | 464 | for (array) |item| { |
| 465 | %%io.stdout.print_u64(item); | 465 | %%io.stdout.printInt(@typeOf(item), item); |
| 466 | %%io.stdout.printf("\n"); | 466 | %%io.stdout.printf("\n"); |
| 467 | } | 467 | } |
| 468 | for (array) |item, index| { | 468 | for (array) |item, index| { |
| 469 | %%io.stdout.print_u64(index); | 469 | %%io.stdout.printInt(@typeOf(index), index); |
| 470 | %%io.stdout.printf("\n"); | 470 | %%io.stdout.printf("\n"); |
| 471 | } | 471 | } |
| 472 | const unknown_size: []u8 = array; | 472 | const unknown_size: []u8 = array; |
| 473 | for (unknown_size) |item| { | 473 | for (unknown_size) |item| { |
| 474 | %%io.stdout.print_u64(item); | 474 | %%io.stdout.printInt(@typeOf(item), item); |
| 475 | %%io.stdout.printf("\n"); | 475 | %%io.stdout.printf("\n"); |
| 476 | } | 476 | } |
| 477 | for (unknown_size) |item, index| { | 477 | for (unknown_size) |item, index| { |
| 478 | %%io.stdout.print_u64(index); | 478 | %%io.stdout.printInt(@typeOf(index), index); |
| 479 | %%io.stdout.printf("\n"); | 479 | %%io.stdout.printf("\n"); |
| 480 | } | 480 | } |
| 481 | } | 481 | } |