feat(preview): annotate multi-bit pins with [N] width suffix - #68
Merged
Conversation
Pin labels in `--preview` now render as `name[N]` for width > 1 and stay bare for width 1, so existing scalar preview goldens are unchanged. The annotation flows from the topology's per-component width byte through VirtualNode → PlacedComponent into the render pass. Layout accounts for the wider label: pinSize takes the signal width and adds the digit count plus brackets to the padded box width. A mixed-width fixture confirms scalar and multi-bit pins coexist without truncation or column-width contamination. One subtle correctness fix along the way: the canvas stores slice pointers from setCell (not copies), so the label string must outlive the canvas. Composing the label in arena-owned memory at placement time guarantees that lifetime — an earlier attempt that used a stack-local buffer inside drawInputPin produced visibly garbled output once the stack frame popped. PlacedComponent now carries a `display_label` field with the arena-owned string; tests that build PlacedComponent literals fall back to the raw name when display_label is empty. Engine bench reports golden matches on all 56 fixtures; preview is a render-time concern that never touches the engine.
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
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.
Summary
Pin labels in
--previewnow render asname[N]for width > 1 and stay bare for width 1, so existing scalar preview goldens are unchanged. The annotation flows from the topology's per-component width byte throughVirtualNode→PlacedComponentinto the render pass.input a(width 1)│ a ││ a │input[4] a│ a │(no annotation)│ a[4] │output[8] r│ r ││ r[8] │Layout
pinSizenow takes the signal width and addswidthAnnotationLen(width)to the padded box width (3 chars for single-digit widths, 4 for two-digit). The mixed-width fixture demonstrates scalar and multi-bit pins coexisting without truncation.Subtle correctness fix
The
Canvas.setCellstores slice pointers, not copies. My first cut composed the label in a stack-local[128]u8 = undefinedbuffer insidedrawInputPin, which produced visibly garbled output (▢1+kinstead ofa[4]) once the stack frame popped — the canvas held dangling pointers.Fix: compose the label in arena-owned memory at placement time.
PlacedComponentgained adisplay_label: []const u8 = ""field; pin renderers fall back toplaced.namewhendisplay_labelis empty, so the dozens of existing test fixtures that buildPlacedComponentliterals don't need updating.Test plan
zig build testgreen from a clean cache.zig build benchreportsgolden matcheson all 56 fixtures.S11.2 (LED rendering for width >1 +
--expand-displayflag) is the matching follow-up that stacks on this PR.Context:
DOCS/plan-multi-bit-language.md§"Stage 11".Closes #52