diff --git a/lib/lua/runtime.sx b/lib/lua/runtime.sx index b3b95eaa..99371195 100644 --- a/lib/lua/runtime.sx +++ b/lib/lua/runtime.sx @@ -1493,3 +1493,27 @@ (if (>= i (len args)) (list) (cons (nth args i) (lua-varargs-tail args (+ i 1)))))) + +;; preload standard libs in package.loaded +(dict-set! __package-loaded "string" string) +(dict-set! __package-loaded "math" math) +(dict-set! __package-loaded "table" table) +(dict-set! __package-loaded "io" io) +(dict-set! __package-loaded "os" os) +(dict-set! __package-loaded "coroutine" coroutine) +(dict-set! __package-loaded "package" package) +(dict-set! __package-loaded "_G" _G) + +(define arg {}) + +;; preload debug stub +(define debug {}) +(dict-set! debug "traceback" (fn (&rest args) (if (> (len args) 0) (first args) ""))) +(dict-set! debug "getinfo" (fn (&rest args) {})) +(dict-set! debug "sethook" (fn (&rest args) nil)) +(dict-set! debug "gethook" (fn () nil)) +(dict-set! debug "getlocal" (fn (&rest args) nil)) +(dict-set! debug "setlocal" (fn (&rest args) nil)) +(dict-set! debug "getupvalue" (fn (&rest args) nil)) +(dict-set! debug "setupvalue" (fn (&rest args) nil)) +(dict-set! __package-loaded "debug" debug) diff --git a/lib/lua/scoreboard.json b/lib/lua/scoreboard.json index 41028753..29dc0907 100644 --- a/lib/lua/scoreboard.json +++ b/lib/lua/scoreboard.json @@ -11,20 +11,12 @@ "top_failure_modes": [ [ "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - 5 - ], - [ - "parse error", - 3 + 8 ], [ "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio", 2 ], - [ - "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: module 'string' not found\\\\", - 1 - ], [ "timeout", 1 @@ -33,16 +25,20 @@ "undefined symbol: collectgarbage\\", 1 ], + [ + "parse error", + 1 + ], [ "undefined symbol: setfenv\\", 1 ], [ - "undefined symbol: T\\", + "arith type error", 1 ], [ - "undefined symbol: arg\\", + "undefined symbol: T\\", 1 ] ], @@ -62,20 +58,20 @@ { "name": "attrib.lua", "status": "fail", - "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: module 'string' not found\\\\", - "ms": 5744 + "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", + "ms": 5747 }, { "name": "big.lua", "status": "timeout", "reason": "per-test timeout", - "ms": 8004 + "ms": 8007 }, { "name": "calls.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 4612 + "ms": 4595 }, { "name": "checktable.lua", @@ -87,7 +83,7 @@ "name": "closure.lua", "status": "fail", "reason": "undefined symbol: collectgarbage\\", - "ms": 6160 + "ms": 6175 }, { "name": "code.lua", @@ -99,7 +95,7 @@ "name": "constructs.lua", "status": "fail", "reason": "parse error", - "ms": 2720 + "ms": 2589 }, { "name": "db.lua", @@ -111,13 +107,13 @@ "name": "errors.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 3172 + "ms": 2997 }, { "name": "events.lua", "status": "fail", "reason": "undefined symbol: setfenv\\", - "ms": 6976 + "ms": 6803 }, { "name": "files.lua", @@ -134,14 +130,14 @@ { "name": "literals.lua", "status": "fail", - "reason": "parse error", - "ms": 1786 + "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", + "ms": 1783 }, { "name": "locals.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 1707 + "ms": 1623 }, { "name": "main.lua", @@ -152,44 +148,44 @@ { "name": "math.lua", "status": "fail", - "reason": "parse error", - "ms": 2475 + "reason": "arith type error", + "ms": 3864 }, { "name": "nextvar.lua", "status": "fail", "reason": "undefined symbol: T\\", - "ms": 6743 + "ms": 6725 }, { "name": "pm.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 5928 + "ms": 5622 }, { "name": "sort.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio", - "ms": 1169 + "ms": 1158 }, { "name": "strings.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 3872 + "ms": 3811 }, { "name": "vararg.lua", "status": "fail", - "reason": "undefined symbol: arg\\", - "ms": 2140 + "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", + "ms": 2111 }, { "name": "verybig.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio", - "ms": 553 + "ms": 563 } ] } \ No newline at end of file diff --git a/lib/lua/scoreboard.md b/lib/lua/scoreboard.md index 9c23636f..c4e3a9c9 100644 --- a/lib/lua/scoreboard.md +++ b/lib/lua/scoreboard.md @@ -5,15 +5,14 @@ fail=15 timeout=1 skip=8 total=24 ## Top failure modes -- **5x** other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ -- **3x** parse error +- **8x** 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 'string' not found\\ - **1x** timeout - **1x** undefined symbol: collectgarbage\ +- **1x** parse error - **1x** undefined symbol: setfenv\ +- **1x** arith type error - **1x** undefined symbol: T\ -- **1x** undefined symbol: arg\ ## Per-test results @@ -21,25 +20,25 @@ fail=15 timeout=1 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 'string' not found\\ | 5744 | -| big.lua | timeout | per-test timeout | 8004 | -| calls.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4612 | +| attrib.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 5747 | +| big.lua | timeout | per-test timeout | 8007 | +| calls.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4595 | | checktable.lua | skip | internal debug helpers | 0 | -| closure.lua | fail | undefined symbol: collectgarbage\ | 6160 | +| closure.lua | fail | undefined symbol: collectgarbage\ | 6175 | | code.lua | skip | bytecode inspection via debug library | 0 | -| constructs.lua | fail | parse error | 2720 | +| constructs.lua | fail | parse error | 2589 | | db.lua | skip | debug library | 0 | -| errors.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3172 | -| events.lua | fail | undefined symbol: setfenv\ | 6976 | +| errors.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 2997 | +| events.lua | fail | undefined symbol: setfenv\ | 6803 | | files.lua | skip | io library | 0 | | gc.lua | skip | collectgarbage / finalisers | 0 | -| literals.lua | fail | parse error | 1786 | -| locals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 1707 | +| literals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 1783 | +| locals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 1623 | | main.lua | skip | standalone interpreter driver | 0 | -| math.lua | fail | parse error | 2475 | -| nextvar.lua | fail | undefined symbol: T\ | 6743 | -| pm.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 5928 | -| sort.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 1169 | -| strings.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3872 | -| vararg.lua | fail | undefined symbol: arg\ | 2140 | -| verybig.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 553 | +| math.lua | fail | arith type error | 3864 | +| nextvar.lua | fail | undefined symbol: T\ | 6725 | +| pm.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 5622 | +| sort.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 1158 | +| strings.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3811 | +| vararg.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 2111 | +| verybig.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 563 | diff --git a/lib/lua/tokenizer.sx b/lib/lua/tokenizer.sx index 6a09788d..a31dff38 100644 --- a/lib/lua/tokenizer.sx +++ b/lib/lua/tokenizer.sx @@ -224,11 +224,7 @@ (begin (read-decimal-digits!) (when - (and - (< pos src-len) - (= (cur) ".") - (< (+ pos 1) src-len) - (lua-digit? (lua-peek 1))) + (and (< pos src-len) (= (cur) ".")) (begin (advance! 1) (read-decimal-digits!))) (read-exp-part!) (parse-number (slice src start pos))))))) diff --git a/plans/lua-on-sx.md b/plans/lua-on-sx.md index 5778cd39..142551bb 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-24: lua: scoreboard iteration — trailing-dot number literals (`5.`), preload stdlibs in `package.loaded` (`string`/`math`/`table`/`io`/`os`/`coroutine`/`package`/`_G`), `arg` stub, `debug` module stub. Assertion-failure count 4→**8**, parse errors 3→**1**, call-non-fn stable, module-not-found gone. - 2026-04-24: lua: scoreboard iteration — **vararg `...` transpile**. Parser already emitted `(lua-vararg)`; transpile now: (a) binds `__varargs` in function body when `is-vararg`, (b) emits `__varargs` for `...` uses; `lua-varargs`/`lua-spread-last-multi` runtime helpers spread multi in last call-arg and last table-pos positions. Eliminated all 6× "transpile: unsupported" failures; top-5 now all real asserts. 353 unit tests. - 2026-04-24: lua: scoreboard iteration — added `rawget`/`rawset`/`rawequal`/`rawlen`, `loadstring`/`load`, `select`, `assert`, `_G`, `_VERSION`. Failure mix now 6×vararg-transpile / 4×real-assertion / 3×parse / 2×call-non-fn / 1×timeout (was 14 parse + 1 print undef at baseline); tests now reach deep into real assertions. Still 0/16 runnable — next targets: vararg transpile, goto, loadstring-compile depth. 347 unit tests. - 2026-04-24: lua: `require`/`package` via preload-only (no filesystem search). `package.loaded` caching, nil-returning modules cache as `true`, unknown modules error. 347 tests.