docs: session handoff document for session 9
This commit is contained in:
@@ -0,0 +1,80 @@
|
|||||||
|
# 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 decisions
|
||||||
|
- `emitBranch(roots, stop, visited, isDecision)` — emits C code for a branch via `generateCode`, with `goto` on back-edges
|
||||||
|
- `generateCallWithError(ifHeader, errTargets, okTargets, isDecision)` — shared visited set across all branches to prevent duplicate labels
|
||||||
|
- `generateCFile(entryBlock, includes, declarations)` — assembles complete C file
|
||||||
|
|
||||||
|
### Browser blocks adapted
|
||||||
|
- **`blocks-proc.js`**: `_branchDescendants` and `_emitBranch` are now 3-line adapters passing `b instanceof WCDecision` to `CodeGen`. `_generateCallWithError` delegates to `CodeGen.generateCallWithError`.
|
||||||
|
- **`blocks-algo.js`**: `WCDecision._emitBranch` delegates to `generateCode` (not `generateOwnCode`), uses `visited` in-place. `_emitBranch` skips roots already visited by prior roots.
|
||||||
|
- **`index.html`**: `codegen/index.js` loaded before `blocks-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.js` now checks if the body already contains a return/exit before appending the hardcoded `return 0;\n`.
|
||||||
|
- **Variable labels**: `WCBlock.generateCode` checks `_isFlowBlock` (set from `#draw-area` presence). Variable blocks in `#variable-area` skip label/goto logic.
|
||||||
|
- **Default array removed**: Unconditional `vertices` array creation in `app.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 `CodeGen` module — no duplicated `branchDescendants`/`emitBranch`/`generateCode` logic
|
||||||
|
- 5 test cases (console, error-simple, error-merge, error-sequential, error-value) all pass
|
||||||
|
|
||||||
|
### WCEnd modal bugfix
|
||||||
|
- Colour: `dataset.exitError` instead of `tagName === "WC-END"` — success ENDs default to blue
|
||||||
|
- Value: `setAttribute("value", ...)` alongside `input.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 |
|
||||||
Reference in New Issue
Block a user