4.3 KiB
Session Handoff: WiseCode Visual C IDE — Session 9
Date: June 23, 2026
Summary
Refactored code generation to eliminate duplicated logic, added loop support via goto labels, fixed C code quality issues, and added compilation tests.
Changes
Shared codegen module (codegen/index.js — new)
Pure C code generation with zero DOM dependencies. Exports as window.CodeGen (browser) and module.exports (Node.js):
branchDescendants(roots, isDecision)— discovers reachable blocks, excluding decisionsemitBranch(roots, stop, visited, isDecision)— emits C code for a branch viagenerateCode, withgotoon back-edgesgenerateCallWithError(ifHeader, errTargets, okTargets, isDecision)— shared visited set across all branches to prevent duplicate labelsgenerateCFile(entryBlock, includes, declarations)— assembles complete C file
Browser blocks adapted
blocks-proc.js:_branchDescendantsand_emitBranchare now 3-line adapters passingb instanceof WCDecisiontoCodeGen._generateCallWithErrordelegates toCodeGen.generateCallWithError.blocks-algo.js:WCDecision._emitBranchdelegates togenerateCode(notgenerateOwnCode), usesvisitedin-place._emitBranchskips roots already visited by prior roots.index.html:codegen/index.jsloaded beforeblocks-proc.js.
Loop support
Every block in #draw-area emits a C label (block_id:) before its code. generateNextCode emits goto label; when a target is already visited (back-edge). _emitBranch emits goto label; when encountering a visited block.
Files changed: wcblock.js, blocks-algo.js, blocks-proc.js, codegen/index.js
C code quality fixes
- Double
return 0:wcprogram.jsnow checks if the body already contains a return/exit before appending the hardcodedreturn 0;\n. - Variable labels:
WCBlock.generateCodechecks_isFlowBlock(set from#draw-areapresence). Variable blocks in#variable-areaskip label/goto logic. - Default array removed: Unconditional
verticesarray creation inapp.js:main()removed. Templates should create their own variables.
Compilation tests (tests/compile/)
- Makefile: Uses
pkg-config, compiles with-Wall -Wextra -fsyntax-only - run.js: Uses shared
CodeGenmodule — no duplicatedbranchDescendants/emitBranch/generateCodelogic - 5 test cases (console, error-simple, error-merge, error-sequential, error-value) all pass
WCEnd modal bugfix
- Colour:
dataset.exitErrorinstead oftagName === "WC-END"— success ENDs default to blue - Value:
setAttribute("value", ...)alongsideinput.value = ...—cloneNode(true)preserves formatted display - 4 regression tests added
Warning icon overlap
padding-right added to .proccall-header and .end-header when warnings active, preventing ::after text from colliding with the .block-warn icon.
Template spacing
Block gap increased from 16px to 40px. Error WCEnd blocks added to console and SDL3 templates with error-hook connections.
Commit log
e879e21 fix: variable blocks no longer emit labels; remove default array variable
7451def fix: double return 0 in generated C output
439cc6e feat: loop support via goto labels on each block
f1eed2d refactor: extract pure codegen into shared module, remove duplication
9dd79c2 chore: remove stale test-compile.js
8522ece test: C compilation tests for generated template code
3657a22 fix: WCEnd editor modal pre-loads correct colour and errno value
68da559 refactor: unwrap nested if-else in error-path code generation
5caa306 fix: prevent deletion of library procedures
File inventory (key files)
| File | Lines | Notes |
|---|---|---|
codegen/index.js |
~150 | Pure codegen module, shared browser+Node |
blocks-proc.js |
~600 | ProcCall with codegen delegation |
blocks-algo.js |
~560 | Decision/End blocks with label support |
wcblock.js |
~330 | Base class with _isFlowBlock, label/goto |
wcprogram.js |
~300 | Double-return guard |
tests/compile/run.js |
~230 | Compilation tests using CodeGen module |
tests/compile/Makefile |
~40 | pkg-config based build |
tests/app/test-runner.js |
~845 | Browser tests |
shell.nix |
~56 | Added gcc, mesa |
style.css |
~1340 | Warning icon padding fix |