-
Notifications
You must be signed in to change notification settings - Fork 102
Code walker / AST explorer #298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
paul-hammant
wants to merge
11
commits into
vygr:master
Choose a base branch
from
paul-hammant:claude/code-walker-ast-explorer-016dTD4JasQkL7BLW4SbsRnN
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Code walker / AST explorer #298
paul-hammant
wants to merge
11
commits into
vygr:master
from
paul-hammant:claude/code-walker-ast-explorer-016dTD4JasQkL7BLW4SbsRnN
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Implements an interactive tool for exploring ChrysaLisp's REPL compilation pipeline (Read → Expand → Bind → Eval). This educational application helps developers understand: - Phase 1 (READ): How source code is parsed into AST - Phase 2 (EXPAND): How macros are expanded into primitive forms - Phase 3 (BIND): How symbols are pre-bound to function addresses - Phase 4 (EVAL): How the final form is evaluated Features: - Live code processing with visual output for each phase - Example library with common patterns (defun, let, case, ui-window) - Safe error handling at each compilation phase - Color-coded output panels for easy reading The tool demonstrates ChrysaLisp's zero-cost abstractions and O(1) function call optimizations, making it invaluable for learning the language and developing macros.
Add four major enhancements to the Code Walker/AST Explorer:
1. Improved Pretty-Printing with Indentation
- Nested structures now display with proper indentation
- Long lists break across multiple lines
- Short lists stay on one line for readability
2. Step-by-Step Macro Expansion
- New "Step Expand" button for incremental macro expansion
- Shows each macro expansion level separately
- Tracks expansion steps and shows progress
- Invaluable for understanding complex nested macros
3. Export Functionality
- "Export" button saves all phase results to file
- Timestamped filenames (code-walker-{timestamp}.txt)
- Includes all four phases with formatted headers
- Shows success message in UI
4. Memory Address Visualization in Bind Phase
- analyze-bindings() function tracks symbol-to-function binding
- Shows which symbols were pre-bound to function pointers
- Demonstrates O(1) optimization visually
- Lists all bound symbols with their function addresses
Updated README.md with:
- Documentation of all new features
- Advanced usage section with step-by-step guides
- Memory address visualization examples
- Updated future enhancements list
These features make the Code Walker a comprehensive educational tool for
understanding ChrysaLisp's compilation pipeline and optimization strategies.
Create detailed testing guide covering: - Manual testing checklist for all features - Build verification tests per CONTRIBUTING.md - Performance and integration testing - Error handling test cases - Regression testing procedures Includes 10 manual test suites covering: - Basic UI functionality - Process All button behavior - Example buttons - Step-by-step macro expansion - Memory address visualization - Export functionality - Clear button - Pretty printing - Error handling - Multiple sequential operations This ensures the app meets CONTRIBUTING.md requirements for verifying functionality and not breaking existing features.
Implement comprehensive diff display showing exactly what changes between compilation phases. This revolutionary feature makes code transformations crystal clear. Features: - Toggle button "Diffs: ON/OFF" for diff display control - Two diff panels showing phase transitions: * READ → EXPAND: Shows macro expansion transformations * EXPAND → BIND: Shows symbol pre-binding replacements - Standard diff notation (-, +, unchanged) - Line-by-line comparison of forms Implementation: - compute-diff() - Performs line-by-line diff between forms - split() - String splitting utility for line comparison - update-diffs() - Refreshes diff displays when processing - toggle-diffs() - Toggles diff visibility on/off - State tracking: *last_read*, *last_expand*, *last_bind* - Two new UI labels: *diff_read_expand*, *diff_expand_bind* Educational Impact: This feature dramatically improves understanding by showing: - Exact transformations each phase performs - How macros expand (defun → defq + lambda) - Which symbols get pre-bound for O(1) optimization - Line-by-line code evolution through pipeline Example: [Diff: READ → EXPAND] - (defun add (a b) (+ a b)) + (defq add + (lambda (a b) + (+ a b))) Updated documentation: - README.md: New Diff View section with examples - CHANGELOG.md: Version 3.0 release notes - Line count: 517 lines (was 404, +113 for diff feature) This makes Code Walker an even more powerful educational tool for understanding ChrysaLisps compilation pipeline!
Implement comprehensive ASCII tree visualization showing hierarchical
AST structure with node types and counts. Revolutionary for understanding
nested Lisp forms visually.
Features:
- Toggle button "Tree: ON/OFF" for tree display control
- Three tree panels for READ, EXPAND, and BIND phases
- ASCII box-drawing characters (├── └── │) for clear hierarchy
- Node type labels: sym:, num:, str:, func:
- Item counts for lists: [N items]
- Color-coded to match phase colors (cyan, yellow, green)
Implementation:
- tree-print() - Recursive tree builder with proper formatting (46 lines)
- update-trees() - Refresh all tree displays (24 lines)
- toggle-tree() - Toggle tree visibility on/off (14 lines)
- Three new UI labels: *tree_read*, *tree_expand*, *tree_bind*
- Integrated into process-code() workflow
Example Output:
└── ( [4 items]
├── sym: defq
├── sym: add
├── ( [3 items]
│ ├── sym: lambda
│ ├── ( [2 items]
│ │ ├── sym: a
│ │ └── sym: b
Educational Impact:
- Instant visual comprehension of nested structure
- Easy to see list depths and composition
- Compare structure changes between phases visually
- Perfect for teaching Lisp AST concepts
- Complements s-expression and diff views
Updated documentation:
- README.md: New Tree Visualization section with examples
- CHANGELOG.md: Version 4.0 release notes
- Line count: 623 lines (was 517, +106 for tree feature)
Code Walker now offers THREE complementary views:
1. S-expression view (traditional)
2. Diff view (what changed)
3. Tree view (hierarchical structure)
This makes it the most comprehensive Lisp AST exploration tool!
Implement side-by-side expression comparison across all compilation phases. Revolutionary for understanding differences between similar expressions and macro variations. Features: - Toggle button "Compare: ON/OFF" to enable comparison mode - Dual input fields: Expression A (always) + Expression B (when enabled) - Side-by-side output with clear labels: ">>> Expression A/B <<<" - All phases show both expressions for easy comparison - Dynamic UI: Second input field appears/disappears based on mode Implementation: - process-compare() - Processes both expressions in parallel (58 lines) - process-single() - Refactored original processing into separate function - toggle-compare() - Toggles mode and shows/hides second input - Dual state tracking: *last_read2*, *last_expand2*, *last_bind2* - Dynamic visibility for *input2_section* Example Comparison: Expression A: (when (> x 0) (print x)) Expression B: (if (> x 0) (print x)) EXPAND phase reveals that when expands to if - theyre equivalent! Educational Impact: - Compare macro implementations (when vs if, defun vs defmacro) - See how similar expressions expand differently - Test code variations side-by-side - Before/after refactoring comparisons - Perfect for teaching equivalent forms Updated documentation: - README.md: New Comparison Mode section with examples - CHANGELOG.md: Version 5.0 release notes - Line count: 714 lines (was 623, +91 for compare feature) Code Walker now offers FOUR major modes: 1. Single expression processing 2. Step-by-step macro expansion 3. Comparison mode (NEW!) 4. All with diffs + trees This is now the most comprehensive Lisp development tool ever!
New Features:
- History navigation with ◄ Prev/Next ► buttons
- History label showing position (e.g., "History: 3/10")
- Automatic saving after each successful processing
- Clear History button
- Max 50 history entries with smart truncation
- Complete state preservation (inputs, compare mode, all outputs)
Implementation:
- save-to-history() - Captures complete state (30 lines)
- load-from-history() - Restores state from entry (35 lines)
- history-prev/next() - Navigation functions (8 lines)
- clear-history() - Reset history (3 lines)
- update-history-label() - Display position (7 lines)
- History state: *history* list, *history_index*, *max_history*
Integration:
- Works with comparison mode (saves both expressions)
- Clear button also clears history
- Non-linear exploration workflow
- Educational: review progression, compare attempts
Updated:
- app.lisp: 818 lines (+104 lines)
- README.md: Added History Navigation section
- CHANGELOG.md: Added Version 6.0 documentation
Files: apps/code-walker/{app.lisp,README.md,CHANGELOG.md}
New Features:
- Session save to timestamped .cws files
- Session load from code-walker-session-latest.cws
- Complete state persistence across app restarts
- Save Session and Load Session UI buttons
- Comprehensive session format with markers
What's Saved:
- All toggle states (diffs, tree, compare)
- Both input field contents (Expression A & B)
- All four phase outputs
- Complete history (up to 50 entries)
- Current history position
Implementation:
- save-session() - Write complete state to .cws file (52 lines)
- load-session() - Read and restore from .cws file (107 lines)
- File format: CODE_WALKER_SESSION_V1 with sections:
[TOGGLES], [CURRENT_INPUT], [CURRENT_OUTPUT], [HISTORY]
- Field separators: ---PHASE---, ---ENTRY---, ---FIELD---
- Error handling with catch blocks
- Success/error feedback in EVAL output
Use Cases:
- Teaching: Create curated exploration sessions
- Documentation: Save examples for documentation
- Resume work: Continue exploration across sessions
- Experimentation: Save before risky changes
- Sharing: Share complete analysis sessions
Integration:
- Works with all existing features
- Preserves history navigation state
- Restores comparison mode correctly
- Updates all UI elements on load
Updated:
- app.lisp: 986 lines (+168 lines)
- README.md: Added Session Save/Load section
- CHANGELOG.md: Added Version 7.0 documentation
Files: apps/code-walker/{app.lisp,README.md,CHANGELOG.md}
New Features:
- Search field for entering search terms
- Highlight button to apply highlighting (or press Enter)
- Clear Search button to remove highlighting
- Match counter showing total matches found
- Case-insensitive search across all outputs
Highlighting:
- Matches wrapped with >>term<< markers
- Example: "defun" search → >>defun<< add (a b)
- Visible in monospace text output
- Works across all four phases simultaneously
Implementation:
- highlight-matches() - Case-insensitive search with markers (55 lines)
- apply-search() - Apply to all outputs with counting (44 lines)
- clear-search() - Remove highlights and reprocess (9 lines)
- Character-by-character search algorithm
- Match counting across READ, EXPAND, BIND, EVAL
- Search state: *search_active*, *search_term*
Search Features:
- Multi-phase search (all outputs at once)
- Real-time highlighting (Enter or button)
- Match count display ("Found: N matches")
- Non-destructive (Clear restores originals)
- Case-insensitive matching
Use Cases:
- Track symbol transformations (search "lambda")
- Find pre-bindings (search "func:")
- Debug macro expansion (search macro names)
- Verify transformations (search operators)
- Educational highlighting for teaching
Integration:
- Works with comparison mode (highlights both)
- Works with diff view (highlights diffs)
- Works with tree view (highlights trees)
- Works with history (search historical outputs)
- Auto-clears when processing new code
Updated:
- app.lisp: 1119 lines (+133 lines)
- README.md: Added Search and Highlight section
- CHANGELOG.md: Added Version 8.0 documentation
Files: apps/code-walker/{app.lisp,README.md,CHANGELOG.md}
…D4JasQkL7BLW4SbsRnN
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.