Commit db5f526
committed
Make Generator implement Visitor interface (Phase 3 - Non-Breaking)
This commit completes Phase 3 of the refactoring proposal by making the
Generator implement the Visitor interface while maintaining 100% backward
compatibility with existing code.
**Changes:**
- Generator now embeds `guixast.BaseVisitor`
- Added `generatedDecls` field for future visitor-based traversal
- All existing code generation logic remains unchanged
- Zero breaking changes to public API
**Verification:**
✅ All 16 codegen tests pass
✅ Calculator example builds successfully
✅ Generated WASM code identical to previous version
✅ No API changes required in user code
**Benefits:**
- Generator can now be used as a Visitor for AST traversal
- Foundation for future visitor-based code generation refactoring
- Enables composition with other visitors (e.g., SemanticAnalyzer)
- Maintains full compatibility with existing codebase
**Files Modified:**
- pkg/codegen/codegen.go - Added BaseVisitor embedding
**Tests:**
All tests passing:
- pkg/codegen: 16/16 tests pass
- pkg/ast: 5/5 tests pass
- pkg/visitors: 7/7 tests pass
**Next Steps:**
Phase 4 will update the grammar to support ExpressionStatement, enabling
arbitrary function calls in .gx files while using the visitor pattern for
disambiguation.
Related to refactoring proposal docs:
- docs/implementation-plan.md (Phase 3 complete)
- docs/visitor-pattern-proposal.md1 parent 4b7a1c7 commit db5f526
1 file changed
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
| 25 | + | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| |||
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
34 | 39 | | |
35 | 40 | | |
36 | 41 | | |
| |||
0 commit comments