diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-09-23 02:00:23 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-09-23 02:00:23 -0400 |
| commit | 46eb77dbb200756b96bfae4c5166397fefba66d0 (patch) | |
| tree | 618f0117563dfabbe0e4253f6fa817e526b5a64c /std/io.zig | |
| parent | 4b902b44a244e29106637f9777aa71b1cd4c22d2 (diff) | |
| download | zig-46eb77dbb200756b96bfae4c5166397fefba66d0.tar.gz zig-46eb77dbb200756b96bfae4c5166397fefba66d0.zip | |
stack trace is able to figure out compilation unit
each address is contained within
also fix a bug having to do with codegen for enum value
initialization expressions
Diffstat (limited to 'std/io.zig')
| -rw-r--r-- | std/io.zig | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/std/io.zig b/std/io.zig index 9c30233cb4..938368c585 100644 --- a/std/io.zig +++ b/std/io.zig @@ -10,6 +10,7 @@ const endian = @import("endian.zig"); const debug = @import("debug.zig"); const assert = debug.assert; const os = @import("os.zig"); +const mem = @import("mem.zig"); pub const stdin_fileno = 0; pub const stdout_fileno = 1; @@ -261,34 +262,28 @@ pub struct InStream { return result[0]; } - pub inline fn readIntLe(is: &InStream, inline T: type) -> %T { + pub fn readIntLe(is: &InStream, inline T: type) -> %T { is.readInt(false, T) } - pub inline fn readIntBe(is: &InStream, inline T: type) -> %T { + pub fn readIntBe(is: &InStream, inline T: type) -> %T { is.readInt(true, T) } - pub inline fn readInt(is: &InStream, is_be: bool, inline T: type) -> %T { + pub fn readInt(is: &InStream, is_be: bool, inline T: type) -> %T { var result: T = undefined; const result_slice = ([]u8)((&result)[0...1]); %return is.readNoEof(result_slice); return endian.swapIf(!is_be, T, result); } - pub inline fn readVarInt(is: &InStream, is_be: bool, inline T: type, size: usize) -> %T { - var result: T = zeroes; - const result_slice = ([]u8)((&result)[0...1]); - const padding = @sizeOf(T) - size; - {var i: usize = 0; while (i < size; i += 1) { - const index = if (is_be == @compileVar("is_big_endian")) { - padding + i - } else { - result_slice.len - i - 1 - padding - }; - result_slice[index] = %return is.readByte(); - }} - return result; + pub fn readVarInt(is: &InStream, is_be: bool, inline T: type, size: usize) -> %T { + assert(size <= @sizeOf(T)); + assert(size <= 8); + var input_buf: [8]u8 = undefined; + const input_slice = input_buf[0...size]; + %return is.readNoEof(input_slice); + return mem.sliceAsInt(input_slice, is_be, T); } pub fn seekForward(is: &InStream, amount: usize) -> %void { |
