Skip to content

feat: sourceで使えるクラスとスコープ付き参照を追加 - #120

Draft
milkeclair wants to merge 27 commits into
mainfrom
feat/class-runtime
Draft

milkeclair wants to merge 27 commits into
mainfrom
feat/class-runtime

Conversation

@milkeclair

@milkeclair milkeclair commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

変更内容

Refs #90。通常のsourceで平坦なクラス定義を読み込みます。draw/drewとfn/fn.doneが境界です。属性にはdefault=が必須で、空文字列も初期値にできます。定義の開始を拒否した場合は対応するdrewまで読み飛ばして1を返し、外側の定義を維持します。

各メソッドに実体IDを持つreadonlyローカル変数selfを用意します。$self.incrementで同じ実体のメソッドを呼び出し、$self.count.getと$self.count.setで保存済みの属性へアクセスします。getterとsetterは実体IDと属性名で値を特定するため、利用者のlocal countから独立します。成功したsetterはその場で値を更新し、メソッドがあとで非0終了してもその値を保持します。

不正な数値式と奇数個の連想配列引数は元の値を保って失敗します。参照を変換する代入先は生成前に拒否します。メソッド実行に通常のZshのerrexit規則を適用し、定義時のDEBUGトラップとオプションも復元します。

fixtureを対応ディレクトリへまとめ、テストは実装に対応するファイルに配置しました。内部関数のコメントには使用例と結果を記載しています。LSの認識と診断は、このブランチをbaseとする#121に含めています。

内部では、メソッドの登録と定義スコープの判定を共通化しています。メソッドを実行する経路では実行中の実体を管理し、型付き属性を操作する経路では宣言の復元・取得/更新・保存を扱います。

検証

  • Zsh 5.9で全1,581件成功。クラス・補完の関連120件も実行しました。
  • 実体のcountが10の状態で、呼出元がlocal count=3を持ったままcounter.add count=3を実行しました。呼出元は3、実体とREPLYは13です。入れ子呼出し、別実体から戻った後のself、型付き属性、失敗時の元の値も検証しました。
  • 親ブランチのLS全673件成功。書式、lint、ビルド、型検査を含みます。

@milkeclair
milkeclair added this pull request to stack #122 November 15, 2026 22:18
@milkeclair
milkeclair force-pushed the feat/class-runtime branch 4 times, most recently from cde6a2c to 8a13bdc Compare November 16, 2026 11:42
Collect unquoted method blocks through the DEBUG trap and keep instance state behind immutable scoped handles. Share dispatcher programs and preserve typed attribute values, return status and existing traps. Refs #90.
Missing associative lookups can retain unset parameter nodes even when visible element counts are zero. Explicitly remove each deleted active-state entry and rebuild empty instance tables after the last deletion so repeated object graphs reuse bounded storage.
Reuse existing predicates and collection APIs, separate generated-command responsibilities, and directly test each runtime function at its namespace path. Keep isolated source, attribute and reference scenarios for whole-shell contracts.
Use the reserved z_cls_ prefix for both local runtime variables and persistent state. Release the unused double-underscore prefix for ordinary identifiers, and cover caller-local shadowing and attributes with the former prefix. Expand declarations and command groups, initialize bindings at use, and separate test phases without changing class dispatch or typed snapshots.
Separate call validation, saved-scalar access, restored execution, native accessors and instance release. Keep restoration and canonical snapshots in one owning scope, with no fallback status protocol or shared API changes. Cover every extracted function directly and retain source, reentry, typed-value and readonly-reference scenarios.
Keep the eight source DSL entrypoints public and mark twenty internal leaf names private using the existing completion convention. Update generated dispatch and DEBUG callbacks, reuse signed-integer and type-flag predicates, and retain native operations where normalization would alter literal values or parameter shape. Verify the real shell completion cache and caller-visible behavior.
Follow main after implicit value conversion and z.return removal. Update obsolete fixtures and docs, remove old getter-loop isolation, and retain scalar/array and owning-scope accessor contracts with focused regressions.
Follow the updated repository policy for README and function comments while preserving parser markers and executable code. State assumptions and concrete outcomes in public DSL examples, including a labelled PID-dependent reference example.
Match existing function comments for operations without a reply value. Only change the REPLY description; retain runtime behavior, examples and all other documentation markers.
Use direct scoped expectations and dedicated null/array matchers instead of custom observation hashes. Capture status and reply in ordinary locals when both are required. Normalize fixture comments, reject unknown fixture cases, and keep production behavior and original scenarios intact.
@milkeclair
milkeclair removed this pull request from stack #122 November 17, 2026 08:47
@milkeclair
milkeclair added this pull request to stack #166 November 17, 2026 08:47
@milkeclair
milkeclair removed this pull request from stack #166 November 17, 2026 08:48
@milkeclair
milkeclair added this pull request to stack #167 November 17, 2026 08:49
Replace case-based scenario scripts and their custom failure function with standard z.t cases. Keep state and reference checks in their local scopes, and assert isolated option and DEBUG results in the parent test. Preserve all 29 integration cases and retain a small fixture for actual child-shell initialization.
The child inherited z_mode=test and printed its own zero-test summary in normal output mode, adding a line to the observed result. Clear that mode before loading z so the fixture initializes a regular child shell. Reproduced the CI failure without compact output and verified both output modes.
Use the existing execution function scope for method locals, return and arguments. Remove test wrappers that do not isolate a readonly binding, shadowed local or shell option. Extend the existing execution test to cover local isolation and positional arguments.
Spell out all five option cases instead of generating it declarations at runtime. Indent class bodies and retain the missing-end fixture as incomplete input. Use the existing z string-prefix predicate in the counter method.
An EXIT trap runs in its caller environment. Keep the method body scope so its trap sees the method arguments instead of the dispatcher's caller arguments. Extend the existing execution case to assert the trap argument alongside method locals, return value and status.
Use the shell-word and line split APIs added on main when saving the DEBUG trap. Keep the splitter results in a local REPLY so the caller result is preserved, and extend the capture test with array, whitespace and empty-element values. Keep the execution and snapshot hot paths unchanged.

This branch has not been deployed

No deployments
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