Skip to content

feat: breakpoint(), array highlighting, interpreter improvements - #4

Merged
zojize merged 7 commits into
mainfrom
refactor/simplify-codebase
Apr 11, 2026
Merged

zojize merged 7 commits into
mainfrom
refactor/simplify-codebase

Conversation

@zojize

@zojize zojize commented Apr 11, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add breakpoint() interpreter builtin that pauses play mode while acting as a normal step when stepping manually. All templates call breakpoint() before return 0;.
  • Fix array subscript highlighting in memory map and DS view (pass statement address props to DSValue, add highlight classes on array leaf elements)
  • Inline struct arrays (contiguous allocation with structFieldOffset)
  • Pointer arithmetic support (ptr+int, ptr-int, ptr-ptr, comparison, ++/--)
  • B-tree and bubble sort templates
  • Variable-index array highlighting (arr[j] where j is a runtime variable)
  • Shared format helpers extracted, components simplified

Test plan

  • bun run typecheck passes
  • bun run lint passes
  • bun run knip passes
  • bun run test -- run — 138 tests pass
  • bun run build succeeds
  • Array subscript highlighting verified via Playwright
  • CI e2e tests

🤖 Generated with Claude Code

zojize and others added 6 commits April 11, 2026 13:00
- bubble-sort.cpp: in-place bubble sort on int[6] array, demonstrates
  array visualization with element swapping
- btree.cpp: manually constructed order-3 B-tree with root [10,20],
  three leaf nodes, arrays for keys and children pointers

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Move duplicate formatAddr/formatType/formatValue/isPointerValue to
composables/interpreter/helpers.ts. Simplify DataStructureView
(compute subCellAddresses as computed, O(1) addressToKey via Map),
DanglingEdge as type alias, and minor cleanups across components.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ghting

- Fix allocStruct to allocate array elements for struct array fields
  (previously only created a placeholder with base=0, crashing on access)
- Flatten array fields in DSValue and FieldTable: show keys[0], keys[1]
  instead of a single "keys" entry for struct array fields
- Optimize DS view expression highlighting to target specific fields:
  field_expression (node->data) highlights only the data field row,
  subscript_expression (arr[i], root->keys[0]) highlights the element
- Remove struct base from resolveFieldAddress output (field access now
  highlights only the specific field, not the whole item)
- Add resolveSubscriptAddress for array element highlighting
- Add B-tree unit test for struct array field allocation

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
**Pointer graph**: Handle arrays of pointers to structs in edge building.
For fields like \`BTreeNode *children[4]\`, iterate array elements and
create edges for each non-null pointer. Fixes arrows not rendering for
btree-style structs.

**Pointer arithmetic**: Support ptr+int, int+ptr, ptr-int, ptr-ptr,
pointer comparison (<, >, <=, >=), ptr++/ptr--, and ptr+=n/ptr-=n.
Memory model is naturally compatible (arrays are contiguous cells).

**N-d array rendering**: DSValue and FieldTable recursively flatten
nested array fields with subscript prefixes (e.g. \`p[0][1]\`).

**Tests**: 6 pointer arithmetic program tests (offset, subtract,
difference, comparison, increment, iterator loop). Moved 3 scope
cleanup tests from evaluate.test.ts to programs.test.ts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
**Inline arrays**: Struct array fields are now allocated contiguously
within the struct's memory block instead of as separate heap
allocations. BTreeNode layout: [header][numKeys][keys_hdr][k0][k1][k2]
[children_hdr][c0][c1][c2][c3] — all 11 cells contiguous. This
eliminates dangling array allocations after struct deletion.

Refactored field addressing from `base + 1 + fieldIndex` to
`base + 1 + structFieldOffset(name, defs)` across all consumers
(usePointerGraph, DataStructureView, DSValue, FieldTable, MemoryMap,
useStatementAddresses, declarations).

**Variable-index highlighting**: `resolveSubscriptAddress` now resolves
variable indices (e.g. `arr[j]`) by looking up the variable's current
value in the env stack. Also handles simple binary expressions like
`j + 1`. Fixes bubble sort array element highlighting.

**Tests**: Updated btree test to verify contiguous inline memory layout
with exact cell offsets.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add `breakpoint()` as an interpreter builtin that pauses play mode via
a context flag while still acting as a normal step when stepping manually.
All templates now call `breakpoint()` before `return 0` so users can
inspect the final state.

Fix array element highlighting in both memory map and DS view by passing
statement address props through to DSValue and adding conditional
highlight classes on array leaf elements.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@netlify

netlify Bot commented Apr 11, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for viz-list ready!

Name Link
🔨 Latest commit b8a8732
🔍 Latest deploy log https://app.netlify.com/projects/viz-list/deploys/69da8d9aeec1870008ee74dd
😎 Deploy Preview https://deploy-preview-4--viz-list.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@zojize
zojize merged commit 9357b84 into main Apr 11, 2026
6 checks passed
@zojize
zojize deleted the refactor/simplify-codebase branch April 11, 2026 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant