fix: double return 0 in generated C output

- wcprogram.js.generateCode now checks if the body already contains
  a return or exit statement before appending the hardcoded return 0;
  This eliminates the duplicate return 0 from the END block.
This commit is contained in:
2026-06-23 01:19:53 +02:00
parent 439cc6e7ba
commit 7451defb60
+3 -1
View File
@@ -237,6 +237,8 @@ class WCProgram extends HTMLElement {
.filter(Boolean).map(s => s + "\n").join("")
: "";
const hasReturnOrExit =
body.includes("\n return ") || body.includes("\n exit(");
const raw =
"// --- WiseCode\u00ae ---\n" +
(includes ? includes + "\n\n" : "") +
@@ -244,7 +246,7 @@ class WCProgram extends HTMLElement {
(typeDefs ? typeDefs + "\n\n" : "") +
(unitDefs ? unitDefs + "\n\n" : "") +
stringStruct + dataSection + body +
"return 0;\n" +
(hasReturnOrExit ? "" : "return 0;\n") +
"}\n// --- END ---";
outputEl.textContent = raw;
if (typeof hljs !== "undefined") hljs.highlightElement(outputEl);