Skip to content

Commit

Permalink
Update to latest master of Zig
Browse files Browse the repository at this point in the history
  • Loading branch information
Luukdegram committed May 24, 2021
1 parent f8fa0ed commit 2edb962
Show file tree
Hide file tree
Showing 8 changed files with 220 additions and 222 deletions.
6 changes: 3 additions & 3 deletions src/Lexer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,8 @@ test "All supported tokens" {
for (tests) |unit| {
const current_token = lexer.next();

testing.expectEqual(unit.start, current_token.start);
testing.expectEqual(unit.end, current_token.end);
testing.expectEqual(unit.token_type, current_token.token_type);
try testing.expectEqual(unit.start, current_token.start);
try testing.expectEqual(unit.end, current_token.end);
try testing.expectEqual(unit.token_type, current_token.token_type);
}
}
4 changes: 2 additions & 2 deletions src/Token.zig
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ test "Keywords" {
};

for (keywords) |keyword| {
testing.expect(findType(keyword) != .identifier);
try testing.expect(findType(keyword) != .identifier);
}
}

Expand All @@ -239,6 +239,6 @@ test "Identifiers" {
"random",
};
for (identifiers) |identifier| {
testing.expect(findType(identifier) == .identifier);
try testing.expect(findType(identifier) == .identifier);
}
}
28 changes: 13 additions & 15 deletions src/bytecode.zig
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,7 @@ pub const Instruction = union(Type) {
entry: u32,
},

const Type = enum {
op, ptr, integer, string, function
};
const Type = enum { op, ptr, integer, string, function };

/// Returns the Opcode of the Instruction
pub fn getOp(self: Instruction) Opcode {
Expand Down Expand Up @@ -872,26 +870,26 @@ test "Encoding and decoding of instructions" {
const load_int = "\x00\x05\x00\x00\x00\x00\x00\x00\x00";
const load_ptr = "\x0F\x05\x00\x00\x00";
const load_fn = "\x02\x03add\x02\x00\x00\x00\x02\x01\x00\x00\x00";
testing.expectEqualSlices(u8, load_false ++ load_string ++ load_int ++ load_ptr ++ load_fn, code);
testing.expectEqualSlices(u8, load_false ++ load_string ++ load_int ++ load_ptr ++ load_fn, stream.getWritten());
try testing.expectEqualSlices(u8, load_false ++ load_string ++ load_int ++ load_ptr ++ load_fn, code);
try testing.expectEqualSlices(u8, load_false ++ load_string ++ load_int ++ load_ptr ++ load_fn, stream.getWritten());

stream.reset();
const decoded = try Decoder.decode(stream.reader(), allocator);
defer allocator.free(decoded);

testing.expectEqual(instructions.len, decoded.len);
try testing.expectEqual(instructions.len, decoded.len);

for (instructions) |inst, i| {
switch (inst) {
.op => testing.expectEqual(inst.op, decoded[i].op),
.ptr => testing.expectEqual(inst.ptr.pos, decoded[i].ptr.pos),
.string => testing.expectEqualStrings(inst.string, decoded[i].string),
.integer => testing.expectEqual(inst.integer, decoded[i].integer),
.op => try testing.expectEqual(inst.op, decoded[i].op),
.ptr => try testing.expectEqual(inst.ptr.pos, decoded[i].ptr.pos),
.string => try testing.expectEqualStrings(inst.string, decoded[i].string),
.integer => try testing.expectEqual(inst.integer, decoded[i].integer),
.function => |func| {
testing.expectEqualStrings(func.name, decoded[i].function.name);
testing.expectEqual(func.locals, decoded[i].function.locals);
testing.expectEqual(func.arg_len, decoded[i].function.arg_len);
testing.expectEqual(func.entry, decoded[i].function.entry);
try testing.expectEqualStrings(func.name, decoded[i].function.name);
try testing.expectEqual(func.locals, decoded[i].function.locals);
try testing.expectEqual(func.arg_len, decoded[i].function.arg_len);
try testing.expectEqual(func.entry, decoded[i].function.entry);
},
}
}
Expand All @@ -915,7 +913,7 @@ fn testInput(input: []const u8, expected: []const Opcode) !void {
defer result.deinit();

for (expected) |exp, i| {
testing.expectEqual(exp, result.instructions[i].getOp());
try testing.expectEqual(exp, result.instructions[i].getOp());
}
}

Expand Down
20 changes: 10 additions & 10 deletions src/compiler.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1218,9 +1218,9 @@ fn testInput(input: []const u8, expected: []const lir.Inst.Tag) !void {
};
defer result.deinit();

testing.expectEqual(expected.len, result.instructions.len);
try testing.expectEqual(expected.len, result.instructions.len);
for (result.instructions) |inst, i| {
testing.expectEqual(expected[i], inst.tag);
try testing.expectEqual(expected[i], inst.tag);
}
}

Expand Down Expand Up @@ -1310,12 +1310,12 @@ test "Declaration" {

var inst = result.instructions[0];

testing.expectEqual(lir.Inst.Tag.decl, inst.tag);
try testing.expectEqual(lir.Inst.Tag.decl, inst.tag);

const decl = inst.as(lir.Inst.Decl);
testing.expectEqualStrings("x", decl.name);
testing.expectEqual(lir.Inst.Tag.string, decl.value.tag);
testing.expectEqualStrings("foo", decl.value.as(lir.Inst.String).value);
try testing.expectEqualStrings("x", decl.name);
try testing.expectEqual(lir.Inst.Tag.string, decl.value.tag);
try testing.expectEqualStrings("foo", decl.value.as(lir.Inst.String).value);
}

test "Lists" {
Expand Down Expand Up @@ -1376,12 +1376,12 @@ test "Loop" {

var inst = result.instructions[0];

testing.expectEqual(lir.Inst.Tag.@"while", inst.tag);
try testing.expectEqual(lir.Inst.Tag.@"while", inst.tag);

const loop = inst.as(lir.Inst.Double);
testing.expectEqual(lir.Inst.Tag.primitive, loop.lhs.tag);
testing.expectEqual(lir.Inst.Primitive.PrimType.@"true", loop.lhs.as(lir.Inst.Primitive).prim_type);
testing.expectEqual(
try testing.expectEqual(lir.Inst.Tag.primitive, loop.lhs.tag);
try testing.expectEqual(lir.Inst.Primitive.PrimType.@"true", loop.lhs.as(lir.Inst.Primitive).prim_type);
try testing.expectEqual(
@as(u64, 10),
loop.rhs.as(lir.Inst.Block).instructions[0].as(lir.Inst.Single).rhs.as(lir.Inst.Int).value,
);
Expand Down
Loading

0 comments on commit 2edb962

Please sign in to comment.