mirror of
https://github.com/ziglang/zig.git
synced 2025-12-17 03:33:06 +00:00
Fix getNot and add test cases
This commit is contained in:
parent
803f9e5dd0
commit
4b854b75d2
@ -207,8 +207,8 @@ pub const Context = struct {
|
|||||||
.add => self.genAdd(inst.castTag(.add).?),
|
.add => self.genAdd(inst.castTag(.add).?),
|
||||||
.alloc => self.genAlloc(inst.castTag(.alloc).?),
|
.alloc => self.genAlloc(inst.castTag(.alloc).?),
|
||||||
.arg => self.genArg(inst.castTag(.arg).?),
|
.arg => self.genArg(inst.castTag(.arg).?),
|
||||||
.breakpoint => self.genBreakpoint(inst.castTag(.breakpoint).?),
|
|
||||||
.block => self.genBlock(inst.castTag(.block).?),
|
.block => self.genBlock(inst.castTag(.block).?),
|
||||||
|
.breakpoint => self.genBreakpoint(inst.castTag(.breakpoint).?),
|
||||||
.br => self.genBr(inst.castTag(.br).?),
|
.br => self.genBr(inst.castTag(.br).?),
|
||||||
.call => self.genCall(inst.castTag(.call).?),
|
.call => self.genCall(inst.castTag(.call).?),
|
||||||
.cmp_eq => self.genCmp(inst.castTag(.cmp_eq).?, .eq),
|
.cmp_eq => self.genCmp(inst.castTag(.cmp_eq).?, .eq),
|
||||||
@ -546,7 +546,7 @@ pub const Context = struct {
|
|||||||
try writer.writeByte(wasm.opcode(.i32_const));
|
try writer.writeByte(wasm.opcode(.i32_const));
|
||||||
try leb.writeILEB128(writer, @as(i32, 0));
|
try leb.writeILEB128(writer, @as(i32, 0));
|
||||||
|
|
||||||
try self.code.append(wasm.opcode(.i32_ne));
|
try writer.writeByte(wasm.opcode(.i32_eq));
|
||||||
|
|
||||||
return WValue{ .code_offset = offset };
|
return WValue{ .code_offset = offset };
|
||||||
}
|
}
|
||||||
|
|||||||
@ -175,6 +175,41 @@ pub fn addCases(ctx: *TestContext) !void {
|
|||||||
\\ return i;
|
\\ return i;
|
||||||
\\}
|
\\}
|
||||||
, "31\n");
|
, "31\n");
|
||||||
|
|
||||||
|
case.addCompareOutput(
|
||||||
|
\\export fn _start() void {
|
||||||
|
\\ assert(foo(true) != @as(i32, 30));
|
||||||
|
\\}
|
||||||
|
\\
|
||||||
|
\\fn assert(ok: bool) void {
|
||||||
|
\\ if (!ok) unreachable;
|
||||||
|
\\}
|
||||||
|
\\
|
||||||
|
\\fn foo(ok: bool) i32 {
|
||||||
|
\\ const x = if(ok) @as(i32, 20) else @as(i32, 10);
|
||||||
|
\\ return x;
|
||||||
|
\\}
|
||||||
|
, "");
|
||||||
|
|
||||||
|
case.addCompareOutput(
|
||||||
|
\\export fn _start() void {
|
||||||
|
\\ assert(foo(false) == @as(i32, 20));
|
||||||
|
\\ assert(foo(true) == @as(i32, 30));
|
||||||
|
\\}
|
||||||
|
\\
|
||||||
|
\\fn assert(ok: bool) void {
|
||||||
|
\\ if (!ok) unreachable;
|
||||||
|
\\}
|
||||||
|
\\
|
||||||
|
\\fn foo(ok: bool) i32 {
|
||||||
|
\\ const val: i32 = blk: {
|
||||||
|
\\ var x: i32 = 1;
|
||||||
|
\\ if (!ok) break :blk x + @as(i32, 9);
|
||||||
|
\\ break :blk x + @as(i32, 19);
|
||||||
|
\\ };
|
||||||
|
\\ return val + 10;
|
||||||
|
\\}
|
||||||
|
, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user