From dd47fa8a0b0a903f69ac772469b2c17410d7a1fe Mon Sep 17 00:00:00 2001 From: giles Date: Sat, 25 Apr 2026 01:18:59 +0000 Subject: [PATCH] lua: coroutine.running/isyieldable --- lib/lua/runtime.sx | 2 ++ lib/lua/scoreboard.json | 60 +++++++++++++++++++---------------------- lib/lua/scoreboard.md | 39 +++++++++++++-------------- plans/lua-on-sx.md | 1 + 4 files changed, 50 insertions(+), 52 deletions(-) diff --git a/lib/lua/runtime.sx b/lib/lua/runtime.sx index 1880f2ed..b87ce355 100644 --- a/lib/lua/runtime.sx +++ b/lib/lua/runtime.sx @@ -694,6 +694,8 @@ (dict-set! coroutine "yield" lua-coroutine-yield) (dict-set! coroutine "status" lua-coroutine-status) (dict-set! coroutine "wrap" lua-coroutine-wrap) +(dict-set! coroutine "running" (fn () __current-co)) +(dict-set! coroutine "isyieldable" (fn () (not (= __current-co nil)))) ;; ── string library ──────────────────────────────────────────── diff --git a/lib/lua/scoreboard.json b/lib/lua/scoreboard.json index 0c1f859b..c5d68ddb 100644 --- a/lib/lua/scoreboard.json +++ b/lib/lua/scoreboard.json @@ -1,8 +1,8 @@ { "totals": { "pass": 1, - "fail": 12, - "timeout": 3, + "fail": 9, + "timeout": 6, "skip": 8, "total": 24, "runnable": 16, @@ -10,12 +10,12 @@ }, "top_failure_modes": [ [ - "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - 7 + "timeout", + 6 ], [ - "timeout", - 3 + "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", + 5 ], [ "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio", @@ -28,10 +28,6 @@ [ "undefined symbol: fat\\", 1 - ], - [ - "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to compare incompat", - 1 ] ], "results": [ @@ -51,19 +47,19 @@ "name": "attrib.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: module 'C' not found\\\\\\\"\\", - "ms": 6698 + "ms": 6174 }, { "name": "big.lua", "status": "timeout", "reason": "per-test timeout", - "ms": 8002 + "ms": 8007 }, { "name": "calls.lua", "status": "fail", "reason": "undefined symbol: fat\\", - "ms": 5168 + "ms": 5270 }, { "name": "checktable.lua", @@ -75,7 +71,7 @@ "name": "closure.lua", "status": "timeout", "reason": "per-test timeout", - "ms": 8001 + "ms": 8006 }, { "name": "code.lua", @@ -85,9 +81,9 @@ }, { "name": "constructs.lua", - "status": "fail", - "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to compare incompat", - "ms": 7174 + "status": "timeout", + "reason": "per-test timeout", + "ms": 8007 }, { "name": "db.lua", @@ -99,13 +95,13 @@ "name": "errors.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 3446 + "ms": 4731 }, { "name": "events.lua", - "status": "fail", - "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 7749 + "status": "timeout", + "reason": "per-test timeout", + "ms": 8007 }, { "name": "files.lua", @@ -123,13 +119,13 @@ "name": "literals.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 1931 + "ms": 1996 }, { "name": "locals.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio", - "ms": 1767 + "ms": 1785 }, { "name": "main.lua", @@ -141,43 +137,43 @@ "name": "math.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio", - "ms": 4412 + "ms": 4610 }, { "name": "nextvar.lua", - "status": "fail", - "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 7512 + "status": "timeout", + "reason": "per-test timeout", + "ms": 8007 }, { "name": "pm.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 6522 + "ms": 7860 }, { "name": "sort.lua", "status": "timeout", "reason": "per-test timeout", - "ms": 8008 + "ms": 8003 }, { "name": "strings.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 4282 + "ms": 4636 }, { "name": "vararg.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 2373 + "ms": 2770 }, { "name": "verybig.lua", "status": "pass", "reason": "", - "ms": 1080 + "ms": 1319 } ] } \ No newline at end of file diff --git a/lib/lua/scoreboard.md b/lib/lua/scoreboard.md index b2b79717..b16f8400 100644 --- a/lib/lua/scoreboard.md +++ b/lib/lua/scoreboard.md @@ -1,16 +1,15 @@ # Lua-on-SX conformance scoreboard **Pass rate:** 1/16 runnable (6.2%) -fail=12 timeout=3 skip=8 total=24 +fail=9 timeout=6 skip=8 total=24 ## Top failure modes -- **7x** other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ -- **3x** timeout +- **6x** timeout +- **5x** other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ - **2x** other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio - **1x** other: Unhandled exception: \"Unhandled exception: \\\"lua: module 'C' not found\\\"\ - **1x** undefined symbol: fat\ -- **1x** other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to compare incompat ## Per-test results @@ -18,25 +17,25 @@ fail=12 timeout=3 skip=8 total=24 |---|---|---|---:| | all.lua | skip | driver uses dofile to chain other tests | 0 | | api.lua | skip | requires testC (C debug library) | 0 | -| attrib.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: module 'C' not found\\\"\ | 6698 | -| big.lua | timeout | per-test timeout | 8002 | -| calls.lua | fail | undefined symbol: fat\ | 5168 | +| attrib.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: module 'C' not found\\\"\ | 6174 | +| big.lua | timeout | per-test timeout | 8007 | +| calls.lua | fail | undefined symbol: fat\ | 5270 | | checktable.lua | skip | internal debug helpers | 0 | -| closure.lua | timeout | per-test timeout | 8001 | +| closure.lua | timeout | per-test timeout | 8006 | | code.lua | skip | bytecode inspection via debug library | 0 | -| constructs.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to compare incompat | 7174 | +| constructs.lua | timeout | per-test timeout | 8007 | | db.lua | skip | debug library | 0 | -| errors.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3446 | -| events.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 7749 | +| errors.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4731 | +| events.lua | timeout | per-test timeout | 8007 | | files.lua | skip | io library | 0 | | gc.lua | skip | collectgarbage / finalisers | 0 | -| literals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 1931 | -| locals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 1767 | +| literals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 1996 | +| locals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 1785 | | main.lua | skip | standalone interpreter driver | 0 | -| math.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 4412 | -| nextvar.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 7512 | -| pm.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 6522 | -| sort.lua | timeout | per-test timeout | 8008 | -| strings.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4282 | -| vararg.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 2373 | -| verybig.lua | pass | - | 1080 | +| math.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 4610 | +| nextvar.lua | timeout | per-test timeout | 8007 | +| pm.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 7860 | +| sort.lua | timeout | per-test timeout | 8003 | +| strings.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4636 | +| vararg.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 2770 | +| verybig.lua | pass | - | 1319 | diff --git a/plans/lua-on-sx.md b/plans/lua-on-sx.md index 2f397799..c1605c28 100644 --- a/plans/lua-on-sx.md +++ b/plans/lua-on-sx.md @@ -82,6 +82,7 @@ Each item: implement → tests → tick box → update progress log. _Newest first. Agent appends on every commit._ +- 2026-04-25: lua: scoreboard iteration — `coroutine.running()` (returns current `__current-co` or nil) and `coroutine.isyieldable()`. 393/393 green. - 2026-04-25: lua: scoreboard iteration — `string.byte(s, i, j)` now returns multi-values for ranges (was single byte only). 393/393 green; scoreboard unchanged. - 2026-04-25: lua: scoreboard iteration — `math.sinh`/`cosh`/`tanh` (Lua 5.1 hyperbolic). 393/393 green; scoreboard unchanged. - 2026-04-25: lua: scoreboard iteration — tried two-phase eval (extract top-level `function f` decls, evaluate them BEFORE the guard so they leak to top-level env, then run the rest inside guard). Broke method-decl tests because `function a:add(...)` requires `a` to exist, and `a = {...}` was in the deferred phase-2. Reverted. Real fix needs `_G` table or AST-level rewriting of top-level returns into chunk-result mutations. 393/393 green.