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:
+3
-1
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user