selfhost(pyvm): MiniVmPrints – prefer JSON route early-return (ok==1) to avoid fallback loops; keep default behavior unchanged elsewhere
This commit is contained in:
@ -1,10 +1,10 @@
|
||||
# Nyash ABI Minimal Core and Evolution Strategy
|
||||
|
||||
目的
|
||||
- 極小コアのみABI凍結し、将来拡張は交渉+予約+フォールバックで吸収する。
|
||||
- 極小コアのABIを長期安定化(仕様固定)し、将来拡張は交渉+予約+フォールバックで吸収する。
|
||||
- VM/JIT/プラグインを同じ枠組み(TypeBox + vtable + NyrtValue)に統一する。
|
||||
|
||||
最小コア(凍結対象)
|
||||
最小コア(安定化対象)
|
||||
- NyrtValue: 16B固定 `#[repr(C)]`(`tag:u32 | reserved:u32 | payload:u64`)
|
||||
- InstanceHeader: 先頭に `vtbl:*const NyVTable, refcnt:u32, flags:u32`(実体は不透明)
|
||||
- NyMethodFn: `fn(ctx:*mut VmCtx, recv:*mut InstanceHeader, args:*const NyrtValue, argc:u32, out:*mut NyrtValue) -> NyStatus`
|
||||
@ -66,4 +66,3 @@ typedef struct NyVEntry { NyMethodSig sig; NyMethodFn fn_ptr; } NyVEntry;
|
||||
- [ ] `execute_boxcall`: vtable直行→PIC→汎用の三段整備(STRICTガード)。
|
||||
- [ ] TypeRegistry: Array/Map/String の "get/set/len" を登録→vtable優先呼び出し。
|
||||
- [ ] ABIコンプライアンステストと同一実行テストの設計をdocsに反映。
|
||||
|
||||
|
||||
@ -91,4 +91,4 @@ uint64_t nyplug_array_len(NyBox arr);
|
||||
## 注意
|
||||
- 例外/パニックの越境は不可(戻り値/エラーコードで返す)。
|
||||
- C++ 側は必ず `extern "C"`、ELF は `visibility("default")`。
|
||||
- ABI 破壊変更は `*_v1` などの別シンボルで導入(v0は凍結)。
|
||||
- ABI 破壊変更は `*_v1` などの別シンボルで導入(v0は当面固定=長期安定化)。
|
||||
|
||||
55
docs/reference/concurrency/semantics.md
Normal file
55
docs/reference/concurrency/semantics.md
Normal file
@ -0,0 +1,55 @@
|
||||
## Concurrency Semantics (docs-only; to guide MVP)
|
||||
|
||||
Status: reference for userland Phase‑0. No runtime changes during the feature‑pause.
|
||||
|
||||
### Blocking & Non-Blocking
|
||||
- `send(v)` blocks when the buffer is full (capacity reached). Unblocks when a receiver takes an item.
|
||||
- `receive()` blocks when buffer is empty. Unblocks when a sender provides an item.
|
||||
- `try_send(v) -> Bool`: returns immediately; false if full or closed.
|
||||
- `try_receive() -> (Bool, Any?)`: returns immediately; false if empty and not closed.
|
||||
- `receive_timeout(ms) -> (Bool, Any?)`: returns false on timeout.
|
||||
|
||||
Implementation note (Phase‑0): no busy loop. Use cooperative queues; later replaced by OS-efficient wait.
|
||||
|
||||
### Close Semantics
|
||||
- `close()` marks the channel closed. Further `send` is an error.
|
||||
- After close, `receive` continues to drain buffered items; once empty, returns a closed indicator (shape per API, e.g., `(false, End)`).
|
||||
- Double close is an error.
|
||||
|
||||
### Select Semantics
|
||||
- `when(channel, handler)` registers selectable cases.
|
||||
- `await()` examines cases:
|
||||
- If one or more ready: choose one (random/round‑robin) and execute its handler atomically.
|
||||
- If none ready: Phase‑0 may block via a multi-wait helper or return false if non-blocking policy requested.
|
||||
- Fairness: no starvation requirement; Phase‑0 uses simple fairness; Phase‑2 integrates runtime help.
|
||||
|
||||
### Structured Concurrency
|
||||
- `RoutineScopeBox` owns spawned routines.
|
||||
- On `fini()`: cancel pending children, bounded join, and ensure resource release.
|
||||
- Cancellation should unblock channel waits promptly.
|
||||
|
||||
### Types & Safety
|
||||
- Phase‑0: runtime tag checks on `ChannelBox` send/receive are optional; document expected element type.
|
||||
- Future: `TypedChannelBox<T>` with static verification; falls back to runtime tags when needed.
|
||||
|
||||
### Observability
|
||||
- Enable `NYASH_CONC_TRACE=1` to emit JSONL events.
|
||||
- Event schema (recommendation):
|
||||
- Common: `ts` (ms), `op` (string), `rid` (routine id), `cid` (channel id, optional), `ok` (bool), `scope` (scope id, optional)
|
||||
- spawn/start/join/cancel: `{op:"spawn", rid, ts}`, `{op:"join", rid, ok, ts}`
|
||||
- send/recv: `{op:"send", cid, size, cap, ts}`, `{op:"recv", cid, size, cap, ts}`
|
||||
- park/unpark: `{op:"park", rid, reason, ts}`, `{op:"unpark", rid, reason, ts}`
|
||||
- select: `{op:"select", cases:n, chosen:k, ts}`
|
||||
- close: `{op:"close", cid, ts}`
|
||||
- Causality: producers must emit before consumers observe; timestamps monotonic per process.
|
||||
|
||||
### Test Plan (smokes)
|
||||
- ping_pong.nyash: two routines exchange N messages; assert order and count.
|
||||
- bounded_pc.nyash: producer/consumer with capacity=1..N; ensure no busy-wait and correct totals.
|
||||
- select_two.nyash: two channels; verify first-ready choice and distribution.
|
||||
- close_semantics.nyash: send after close -> error; drain -> End; double close -> error.
|
||||
- scope_cancel.nyash: RoutineScopeBox cancels children; parked receivers unblocked.
|
||||
|
||||
### Migration Path
|
||||
- Phase‑0 userland boxes are kept while Phase‑2 runtime grows; API stable.
|
||||
- Replace cooperative wait with WaiterBox (Phase‑1) and runtime park/unpark later.
|
||||
@ -1,6 +1,6 @@
|
||||
# Match Guards — Syntax and Lowering (MVP + Design Notes)
|
||||
|
||||
Status: reference + design additions during freeze (no implementation changes)
|
||||
Status: reference + design additions during feature‑pause (no implementation changes)
|
||||
|
||||
Scope
|
||||
- Guarded branches as a readable form of first-match selection.
|
||||
@ -37,5 +37,4 @@ Observability (design)
|
||||
- `NYASH_FLOW_TRACE=1` may trace how guard chains desugar into if/else.
|
||||
|
||||
Notes
|
||||
- This page describes existing guard semantics and adds range/charclass as documentation-only sugar during freeze.
|
||||
|
||||
- This page describes existing guard semantics and adds range/charclass as documentation-only sugar during the feature‑pause.
|
||||
|
||||
@ -48,7 +48,7 @@ Bytes: handled by `ByteCursorBox`.
|
||||
|
||||
## Proposed Convenience (design only)
|
||||
|
||||
Parsing helpers (sugar; freeze-era design, not implemented):
|
||||
Parsing helpers (sugar; documented during feature‑pause, not implemented):
|
||||
- `toDigitOrNull(base=10) -> i64 | null`
|
||||
- Returns 0..9 when the code point is a decimal digit (or base subset), otherwise `null`.
|
||||
- CP based; delegates to `Utf8CursorBox` to read the leading code point.
|
||||
|
||||
Reference in New Issue
Block a user