Repository navigation
plawk: array-element lines from one structural .stache template (template PR 4) - #4350
Merged
s243a merged 1 commit intoOct 5, 2026
Conversation
…late PR 4) The plawk .stache pilot -- the first pattern_stache consumer on this line (PLAN_TEMPLATE_REFACTOR decision 5). templates/assoc_elem.ll.stache has three structural cases replacing 20 format/2 strings in plawk_native_codegen.pl: - elem_print(T, Key, Kind): the i64 / f64 / str element printers (the runtime names are uniform, @wam_assoc_<Kind>_print, so the kind is a value); - elem_write(Res, T, Key, V, Fn, i64) and its f64 twin: every increment, add-assign and set (11 inc, 2 f64 add, 4 set) and the mixed-route writer; only the LLVM type word differs per encoding. Prolog keeps every decision -- the kind, the SSA names, the op -> runtime function map (plawk_assoc_write_fn/3; the runtime spells i64 add `inc`). plawk_stache.pl renders a ground term to one IR line: templates cached per process, surrounding newlines stripped and exactly one line required, and a load-time preflight that renders every case against its expected line. Verified: ir_corpus dump + diff over all 2573 corpus programs (400 declines): 0 changed. The corpus exercises every case (~950 lines). tests/test_plawk_stache.pl (5). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QrQistdoYMNpVtecwims6g
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.
Template PR 4 of
docs/design/PLAN_TEMPLATE_REFACTOR.md(§2.3-A; decision 5: plawk is the firstpattern_stacheconsumer on this line). It applies the owner's point directly: many literal cases that share a shape collapse into one structural case.What
examples/plawk/codegen/llvm/templates/assoc_elem.ll.stachereplaces 20format/2strings inplawk_native_codegen.plwith 3 structural cases:elem_printserves the i64, f64 and str printers. The runtime names are uniform, so the kind is a value, not a case.elem_write, one case per encoding, serves every element write:Only the LLVM type word differs between the two encodings. The plan's sketch had four cases; set joined the write family.
Prolog keeps every decision: the kind, the SSA names, and the op → runtime-function map (
plawk_assoc_write_fn/3; the runtime spells i64 addinc). The template only spells the line.A new encoding would need zero new cases for print and one for write.
examples/plawk/codegen/llvm/plawk_stache.plprovidesplawk_render_stache(+Name, +Op, -Line):Verification
ir_corpus.pl dump+diffover all 2573 corpus programs (400 declines), feature line vs this branch: 0 changed. The corpus exercises every case, about 950 rendered lines:tests/test_plawk_stache.pl(5). It covers the preflight, one print case for all kinds, the write cases, and the error cases (non-ground and unmatched ops).Next
🤖 Generated with Claude Code
https://claude.ai/code/session_01QrQistdoYMNpVtecwims6g