@@ -105,7 +105,7 @@ fn void Generator.emitStmt(Generator* gen, Stmt* s, u32 indent, bool newline) {
105105 if (!out.endsWith('\n')) out.add1(';');
106106 }
107107 }
108- out.newline();
108+ if (!out.endsWith('\n')) out.newline();
109109 if (is_decl) {
110110 indent--;
111111 out.indent(indent);
@@ -237,22 +237,24 @@ fn void Generator.emitStmt(Generator* gen, Stmt* s, u32 indent, bool newline) {
237237 gen.emitAsmStmt(cast<AsmStmt*>(s), indent);
238238 break;
239239 case Assert:
240- if (!gen.enable_asserts) break;
241-
240+ if (!gen.enable_asserts) out.print(";//assert");
242241 AssertStmt* a = cast<AssertStmt*>(s);
243- source_mgr.Location loc = gen.sm.locate(s.getLoc());
244- const char* funcname = gen.cur_function.asDecl().getFullName();
245-
246242 out.add1('(');
247243 Expr* inner = a.getInner();
248244 gen.emitExpr(out, inner);
249- out.print(") || c2_assert(\"%s\", %d, \"%s\", \"", loc.filename, loc.line, funcname);
250- // encode expression as a string
251- string_buffer.Buf* str = string_buffer.create(128, false, 0);
252- inner.printLiteral(str);
253- out.encodeBytes(str.data(), str.size(), '"');
254- str.free();
255- out.add("\");\n");
245+ out.add1(')');
246+ if (gen.enable_asserts) {
247+ source_mgr.Location loc = gen.sm.locate(s.getLoc());
248+ const char* funcname = gen.cur_function.asDecl().getFullName();
249+ out.print(" || c2_assert(\"%s\", %d, \"%s\", \"", loc.filename, loc.line, funcname);
250+ // encode expression as a string
251+ string_buffer.Buf* str = string_buffer.create(128, false, 0);
252+ inner.printLiteral(str);
253+ out.encodeBytes(str.data(), str.size(), '"');
254+ str.free();
255+ out.add("\")");
256+ }
257+ out.add(";\n");
256258 break;
257259 }
258260}
0 commit comments