feat(parser): Phase 285A1.4 & A1.5 - Weak field sugar + Parser hang fix
A1.4: Add sugar syntax `public weak parent` ≡ `public { weak parent }`
A1.5: Fix parser hang on unsupported `param: Type` syntax
Key changes:
- A1.4: Extend visibility parser to handle weak modifier (fields.rs)
- A1.5: Shared helper `parse_param_name_list()` with progress-zero detection
- A1.5: Fix 6 vulnerable parameter parsing loops (methods, constructors, functions)
- Tests: Sugar syntax (OK/NG), parser hang (timeout-based)
- Docs: lifecycle.md, EBNF.md, phase-285a1-boxification.md
Additional changes:
- weak() builtin implementation (handlers/weak.rs)
- Leak tracking improvements (leak_tracker.rs)
- Documentation updates (lifecycle, types, memory-finalization, etc.)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -4,13 +4,15 @@ Status: Stable (Stage‑3 surface for `local`), default strong references.
|
||||
|
||||
This document defines the variable model used by Hakorune/Nyash and clarifies how locals interact with blocks, memory, and references across VMs (Rust VM, Hakorune VM, LLVM harness).
|
||||
|
||||
For the lifecycle/finalization SSOT, see: `docs/reference/language/lifecycle.md`.
|
||||
|
||||
## Local Variables
|
||||
|
||||
- Syntax: `local name = expr`
|
||||
- Scope: Block‑scoped. The variable is visible from its declaration to the end of the lexical block.
|
||||
- Redeclaration: Writing `local name = ...` inside a nested block creates a new shadowing binding. Writing `name = ...` without `local` updates the nearest existing binding in an enclosing scope.
|
||||
- Mutability: Locals are mutable unless future keywords specify otherwise (e.g., `const`).
|
||||
- Lifetime: The variable binding is dropped at block end; any referenced objects live as long as at least one strong reference exists elsewhere.
|
||||
- Lifetime: The variable binding is dropped at block end (`}`); object lifetime/finalization is defined separately in `docs/reference/language/lifecycle.md`.
|
||||
|
||||
Notes:
|
||||
- Stage‑3 gate: Parsing `local` requires Stage‑3 to be enabled (`NYASH_PARSER_STAGE3=1` or equivalent runner profile).
|
||||
@ -27,8 +29,8 @@ This matches intuitive block‑scoped semantics (Lua‑like), and differs from P
|
||||
|
||||
## Reference Semantics (Strong/Weak)
|
||||
|
||||
- Default: Locals hold strong references to boxes/collections. Implementation uses reference counting (strong = ownership) with internal synchronization.
|
||||
- Weak references: Use `WeakBox` to hold a non‑owning (weak) reference. Weak refs do not keep the object alive; they can be upgraded to strong at use sites. Intended for back‑pointers and cache‑like links to avoid cycles.
|
||||
- Default: Locals hold strong references to boxes/collections.
|
||||
- Weak references: Use `weak(x)` (and fields that store `WeakRef`) to hold a non‑owning reference. Weak refs do not keep the object alive; they can be upgraded at use sites (see SSOT: `docs/reference/language/lifecycle.md`).
|
||||
- Typical guidance:
|
||||
- Locals and return values: strong references.
|
||||
- Object fields that create cycles (child→parent): weak references.
|
||||
|
||||
Reference in New Issue
Block a user