docs(specs): add Index Operator design; CURRENT_TASK: plan for Phase‑20.31 small-scope bring‑up
This commit is contained in:
@ -136,6 +136,29 @@ Plan — Next(一本化の続きと段階導入)
|
|||||||
- 型注釈の最小拡張(観測ベースで1〜2件)。
|
- 型注釈の最小拡張(観測ベースで1〜2件)。
|
||||||
- phase‑15.7/README と Quick Reference に「内部正規化(obj.m→Class.m)」の注記を追記(ユーザー向け説明を簡潔に)。
|
- phase‑15.7/README と Quick Reference に「内部正規化(obj.m→Class.m)」の注記を追記(ユーザー向け説明を簡潔に)。
|
||||||
|
|
||||||
|
Index Operator Bring‑up(Phase‑20.31 内の小粒対応)
|
||||||
|
|
||||||
|
目的
|
||||||
|
- `expr[index]` の最小サポート(Array/Map の読み書き)。実行は NyRT dotted extern に正規化(get/set)。
|
||||||
|
|
||||||
|
仕様(Phase‑1)
|
||||||
|
- 読み取り: `arr[i]`, `map[k]`
|
||||||
|
- 書き込み: `arr[i] = v`, `map[k] = v`
|
||||||
|
- 文字列 index/range は後続(Phase‑2)
|
||||||
|
- 未対応型は Fail‑Fast: "index operator is only supported for Array/Map"
|
||||||
|
|
||||||
|
実装計画
|
||||||
|
1) AST: IndexExpr と Assign(IndexExpr, …)(Rust パーサー)
|
||||||
|
2) MIR Lowering: Array/Map の get/set に正規化
|
||||||
|
3) スモーク(quick): arr_read / arr_write / map_rw / negative_string
|
||||||
|
4) ドキュメント: docs/specs/language/index-operator.md
|
||||||
|
|
||||||
|
ロールアウト
|
||||||
|
- 必要なら dev フラグ(HAKO_INDEX_OPERATOR_DEV=1)で段階導入(dev=ON, prod=OFF)。
|
||||||
|
|
||||||
|
受け入れ基準
|
||||||
|
- 上記スモークが PASS。未対応型は安定診断で Fail。
|
||||||
|
|
||||||
Docs — Added
|
Docs — Added
|
||||||
- Unified method resolution design note: docs/development/builder/unified-method-resolution.md
|
- Unified method resolution design note: docs/development/builder/unified-method-resolution.md
|
||||||
- Pipeline, invariants, flags, rollout plan(P4 observe → dev opt‑in → consider default)を整理。
|
- Pipeline, invariants, flags, rollout plan(P4 observe → dev opt‑in → consider default)を整理。
|
||||||
|
|||||||
41
docs/specs/language/index-operator.md
Normal file
41
docs/specs/language/index-operator.md
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
Index Operator — Design (Phase‑20.31 scoped)
|
||||||
|
|
||||||
|
Scope (Phase‑1)
|
||||||
|
- Support bracket indexing for Array/Map:
|
||||||
|
- Read: expr[index]
|
||||||
|
- Write: expr[index] = value
|
||||||
|
- Semantics (lowering):
|
||||||
|
- Array
|
||||||
|
- Read → nyash.array.get_h(handle, idx)
|
||||||
|
- Write → nyash.array.set_h(handle, idx, val)
|
||||||
|
- Map
|
||||||
|
- Read → nyash.map.get_hh(handle, key_any)
|
||||||
|
- Write → nyash.map.set_hh(handle, key_any, val_any)
|
||||||
|
- Out of scope in Phase‑1: String indexing/ranges.
|
||||||
|
|
||||||
|
Parser/AST
|
||||||
|
- Add IndexExpr(target, index)
|
||||||
|
- Permit Assign(IndexExpr, value) on the LHS.
|
||||||
|
|
||||||
|
MIR Lowering (Fail‑Fast contract)
|
||||||
|
- If receiver is neither Array nor Map → error: "index operator is only supported for Array/Map".
|
||||||
|
- For Map keys/values:
|
||||||
|
- If arguments are SSA values (handles), pass as is; otherwise wrap primitive i64 as IntegerBox via available builder utilities.
|
||||||
|
|
||||||
|
Error Policy
|
||||||
|
- Fail‑Fast, no silent fallback.
|
||||||
|
- Stable diagnostics for unsupported types and malformed LHS.
|
||||||
|
|
||||||
|
Rollout / Flags
|
||||||
|
- Implement in Rust parser first; Ny parser later.
|
||||||
|
- If needed, guard with a dev flag for initial rollout (HAKO_INDEX_OPERATOR_DEV=1), default ON in dev profile, OFF in prod profiles.
|
||||||
|
|
||||||
|
Tests (canaries)
|
||||||
|
- arr_read: [1,2][0] == 1 → true
|
||||||
|
- arr_write: arr[1]=3; arr[1]==3 → true
|
||||||
|
- map_rw: m[10]=7; m[10]==7 → true
|
||||||
|
- negative: "hello"[0] (Phase‑1) → error
|
||||||
|
|
||||||
|
Notes
|
||||||
|
- This leverages existing NyRT dotted externs already implemented for Array/Map, minimizing surface area and risk.
|
||||||
|
|
||||||
Reference in New Issue
Block a user