authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2021-02-06 13:10:30+01:00
committergravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2021-03-22 19:56:38+01:00
log4b854b75d2d0add085ac202c611bbe10fa79b51c
tree01a192666ff8fde99b9d74b22f21755187886bba
parent803f9e5dd02afc36014c292f3ebcf7ea5cd065ee
signature Commit is signed but in an unrecognized format.

Fix getNot and add test cases


2 files changed, 37 insertions(+), 2 deletions(-)

src/codegen/wasm.zig+2-2
......@@ -207,8 +207,8 @@ pub const Context = struct {
207207 .add => self.genAdd(inst.castTag(.add).?),
208208 .alloc => self.genAlloc(inst.castTag(.alloc).?),
209209 .arg => self.genArg(inst.castTag(.arg).?),
210 .breakpoint => self.genBreakpoint(inst.castTag(.breakpoint).?),
211210 .block => self.genBlock(inst.castTag(.block).?),
211 .breakpoint => self.genBreakpoint(inst.castTag(.breakpoint).?),
212212 .br => self.genBr(inst.castTag(.br).?),
213213 .call => self.genCall(inst.castTag(.call).?),
214214 .cmp_eq => self.genCmp(inst.castTag(.cmp_eq).?, .eq),
......@@ -546,7 +546,7 @@ pub const Context = struct {
546546 try writer.writeByte(wasm.opcode(.i32_const));
547547 try leb.writeILEB128(writer, @as(i32, 0));
548548
549 try self.code.append(wasm.opcode(.i32_ne));
549 try writer.writeByte(wasm.opcode(.i32_eq));
550550
551551 return WValue{ .code_offset = offset };
552552 }
test/stage2/wasm.zig+35
......@@ -175,6 +175,41 @@ pub fn addCases(ctx: *TestContext) !void {
175175 \\ return i;
176176 \\}
177177 , "31\n");
178
179 case.addCompareOutput(
180 \\export fn _start() void {
181 \\ assert(foo(true) != @as(i32, 30));
182 \\}
183 \\
184 \\fn assert(ok: bool) void {
185 \\ if (!ok) unreachable;
186 \\}
187 \\
188 \\fn foo(ok: bool) i32 {
189 \\ const x = if(ok) @as(i32, 20) else @as(i32, 10);
190 \\ return x;
191 \\}
192 , "");
193
194 case.addCompareOutput(
195 \\export fn _start() void {
196 \\ assert(foo(false) == @as(i32, 20));
197 \\ assert(foo(true) == @as(i32, 30));
198 \\}
199 \\
200 \\fn assert(ok: bool) void {
201 \\ if (!ok) unreachable;
202 \\}
203 \\
204 \\fn foo(ok: bool) i32 {
205 \\ const val: i32 = blk: {
206 \\ var x: i32 = 1;
207 \\ if (!ok) break :blk x + @as(i32, 9);
208 \\ break :blk x + @as(i32, 19);
209 \\ };
210 \\ return val + 10;
211 \\}
212 , "");
178213 }
179214
180215 {