Compare commits
	
		
			No commits in common. "074a62807b41983325bcd507e4b77b2763906117" and "af1976b69cb73758afcdc1df15f2572d5c8cbf5b" have entirely different histories.
		
	
	
		
			074a62807b
			...
			af1976b69c
		
	
		
@ -6,4 +6,3 @@ steps:
 | 
			
		||||
  image: euantorano/zig:0.9.1
 | 
			
		||||
  commands:
 | 
			
		||||
  - zig build test
 | 
			
		||||
  - ./zig-cache/o/b57ef32c79a05339fbe4a8eb648ff6df/test main.zig
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										31
									
								
								src/io.zig
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								src/io.zig
									
									
									
									
									
								
							@ -10,7 +10,7 @@ pub const Writer = struct {
 | 
			
		||||
    writeContext: fn (*anyopaque, []const u8) usize,
 | 
			
		||||
 | 
			
		||||
    ///
 | 
			
		||||
    /// Radices supported by [writeInt].
 | 
			
		||||
    ///
 | 
			
		||||
    ///
 | 
			
		||||
    pub const Radix = enum {
 | 
			
		||||
        binary,
 | 
			
		||||
@ -79,8 +79,8 @@ pub const Writer = struct {
 | 
			
		||||
        const Int = @TypeOf(value);
 | 
			
		||||
        const type_info = @typeInfo(Int);
 | 
			
		||||
 | 
			
		||||
        switch (type_info) {
 | 
			
		||||
            .Int => {
 | 
			
		||||
        if (type_info != .Int) @compileError("value must be of type int");
 | 
			
		||||
 | 
			
		||||
        if (value == 0) return writer.writeByte('0');
 | 
			
		||||
 | 
			
		||||
        // TODO: Unhardcode this as it will break with large ints.
 | 
			
		||||
@ -107,17 +107,11 @@ pub const Writer = struct {
 | 
			
		||||
            std.mem.swap(u8, &buffer[i], &buffer[buffer_count - i - 1]);
 | 
			
		||||
 | 
			
		||||
        return (writer.write(buffer[0 .. buffer_count]) == buffer_count);
 | 
			
		||||
            },
 | 
			
		||||
 | 
			
		||||
            // Cast comptime int into known-size integer and try again.
 | 
			
		||||
            .ComptimeInt => return writer.
 | 
			
		||||
                writeInt(radix, @intCast(std.math.IntFittingRange(value, value), value)),
 | 
			
		||||
 | 
			
		||||
            else => @compileError("value must be of type int"),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
var null_context = @as(usize, 0);
 | 
			
		||||
 | 
			
		||||
///
 | 
			
		||||
/// Writer that silently throws consumed data away and never fails.
 | 
			
		||||
///
 | 
			
		||||
@ -125,10 +119,13 @@ pub const Writer = struct {
 | 
			
		||||
/// sent somewhere for whatever reason.
 | 
			
		||||
///
 | 
			
		||||
pub const null_writer = Writer{
 | 
			
		||||
    .context = undefined,
 | 
			
		||||
    .context = (&null_context),
 | 
			
		||||
 | 
			
		||||
    .operation = struct {
 | 
			
		||||
        fn write(context: *anyopaque, buffer: []const u8) usize {
 | 
			
		||||
            // Validate context canary value.
 | 
			
		||||
            std.debug.assert(@ptrCast(*usize, @alignCast(@alignOf(usize), context)).* == 0);
 | 
			
		||||
 | 
			
		||||
    .writeContext = struct {
 | 
			
		||||
        fn write(_: *anyopaque, buffer: []const u8) usize {
 | 
			
		||||
            return buffer.len;
 | 
			
		||||
        }
 | 
			
		||||
    }.write,
 | 
			
		||||
@ -140,9 +137,9 @@ test {
 | 
			
		||||
    {
 | 
			
		||||
        const sequence = "foo";
 | 
			
		||||
 | 
			
		||||
        try testing.expectEqual(null_writer.write(sequence), sequence.len);
 | 
			
		||||
        testing.expectEqual(null_writer.write(sequence), sequence.len);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    try testing.expect(null_writer.writeByte(0));
 | 
			
		||||
    try testing.expect(null_writer.writeInt(.decimal, 420));
 | 
			
		||||
    testing.expect(null_writer.writeByte(0));
 | 
			
		||||
    testing.expect(null_writer.writeInt(.decimal, 420));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -15,10 +15,7 @@ pub fn main() anyerror!void {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
test {
 | 
			
		||||
    _ = io;
 | 
			
		||||
    _ = stack;
 | 
			
		||||
    _ = std;
 | 
			
		||||
    _ = sys;
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn run(event_loop: *sys.EventLoop, graphics: *sys.GraphicsContext) anyerror!void {
 | 
			
		||||
 | 
			
		||||
@ -91,7 +91,7 @@ pub const FixedPushError = error {
 | 
			
		||||
    Overflow,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
test {
 | 
			
		||||
test "fixed stack" {
 | 
			
		||||
    const testing = std.testing;
 | 
			
		||||
    var buffer = std.mem.zeroes([4]u8);
 | 
			
		||||
    var stack = Fixed(u8){.buffer = &buffer};
 | 
			
		||||
 | 
			
		||||
@ -377,11 +377,11 @@ pub const FileAccess = opaque {
 | 
			
		||||
    ///
 | 
			
		||||
    pub fn size(file_access: *FileAccess, event_loop: *EventLoop) FileError!usize {
 | 
			
		||||
        // Save cursor to return to it later.
 | 
			
		||||
        const origin_cursor = try event_loop.queryFile(file_access);
 | 
			
		||||
        const origin_cursor = try event_loop.tellFile(file_access);
 | 
			
		||||
 | 
			
		||||
        try event_loop.seekFile(file_access, .tail, 0);
 | 
			
		||||
 | 
			
		||||
        const ending_cursor = try event_loop.queryFile(file_access);
 | 
			
		||||
        const ending_cursor = try event_loop.tellFile(file_access);
 | 
			
		||||
 | 
			
		||||
        // Return to original cursor.
 | 
			
		||||
        try event_loop.seekFile(file_access, .head, origin_cursor);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user