Phase 12.7: Nyash文法革命とANCP 90%圧縮技法の発見 - 文法改革完了とFunctionBox実装
This commit is contained in:
23
docs/development/current/function_values_and_captures.md
Normal file
23
docs/development/current/function_values_and_captures.md
Normal file
@ -0,0 +1,23 @@
|
||||
# Function Values, Captures, and Events
|
||||
|
||||
Summary of current behavior and guidelines.
|
||||
|
||||
- Function values: created via `function(...) { ... }` produce a `FunctionBox` with
|
||||
captured environment (by-ref for locals via `RefCellBox`, by-value for globals/statics) and optional weak `me`.
|
||||
- Assignment cell reflection: assigning to a variable or field bound to `RefCellBox` updates the inner value instead of replacing the cell.
|
||||
- `this → me`: inside methods, `this` is bound as `me` for field/method access. External code should prefer `me`.
|
||||
- Parent:: syntax: parser groundwork exists for `Parent::method` references; calling from child uses from-call lowering.
|
||||
- `?` (propagate): `expr ?` lowers to `isOk`/`getValue` branching and returns early with the Result on error.
|
||||
- `peek`: tokenized and parsed; desugars to if-else chain in VM.
|
||||
|
||||
Event APIs
|
||||
|
||||
- P2PBox.on/onOnce/off: handlers now accept both `MethodBox` and `FunctionBox`.
|
||||
- `MethodBox` handlers invoke the bound method on receive with arguments `(intent, from)`.
|
||||
- `FunctionBox` handlers execute the function body with params bound from `(intent, from)` (excess args ignored).
|
||||
|
||||
Notes
|
||||
|
||||
- RefCell-backed locals captured by closures will reflect assignments (`x = ...`) in the outer scope.
|
||||
- For plugin-backed boxes, assignment and argument passing uses share semantics to preserve identity.
|
||||
|
||||
Reference in New Issue
Block a user