lua: math.mod (alias) + math.frexp + math.ldexp
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled

This commit is contained in:
2026-04-25 00:39:46 +00:00
parent 1b34d41b33
commit f620be096b
4 changed files with 78 additions and 43 deletions

View File

@@ -1425,6 +1425,35 @@
(dict-set! math "min" lua-math-min) (dict-set! math "min" lua-math-min)
(dict-set! math "max" lua-math-max) (dict-set! math "max" lua-math-max)
(dict-set! math "fmod" lua-math-fmod) (dict-set! math "fmod" lua-math-fmod)
(dict-set! math "mod" lua-math-fmod)
(define
lua-math-frexp
(fn (x)
(cond
((= x 0) (list (quote lua-multi) 0 0))
(else
(let ((sign (if (< x 0) -1 1)) (ax (abs x)) (e 0))
(begin
(define
fr-up
(fn ()
(when (>= ax 1)
(begin (set! ax (/ ax 2)) (set! e (+ e 1)) (fr-up)))))
(define
fr-dn
(fn ()
(when (< ax 0.5)
(begin (set! ax (* ax 2)) (set! e (- e 1)) (fr-dn)))))
(fr-up)
(fr-dn)
(list (quote lua-multi) (* sign ax) e)))))))
(define
lua-math-ldexp
(fn (m e) (* m (pow 2 e))))
(dict-set! math "frexp" lua-math-frexp)
(dict-set! math "ldexp" lua-math-ldexp)
(dict-set! math "modf" lua-math-modf) (dict-set! math "modf" lua-math-modf)
(dict-set! math "random" lua-math-random) (dict-set! math "random" lua-math-random)
(dict-set! math "randomseed" lua-math-randomseed) (dict-set! math "randomseed" lua-math-randomseed)

View File

@@ -1,8 +1,8 @@
{ {
"totals": { "totals": {
"pass": 1, "pass": 1,
"fail": 9, "fail": 12,
"timeout": 6, "timeout": 3,
"skip": 8, "skip": 8,
"total": 24, "total": 24,
"runnable": 16, "runnable": 16,
@@ -10,12 +10,12 @@
}, },
"top_failure_modes": [ "top_failure_modes": [
[ [
"timeout", "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
6 7
], ],
[ [
"other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "timeout",
5 3
], ],
[ [
"other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio", "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio",
@@ -28,6 +28,10 @@
[ [
"undefined symbol: fat\\", "undefined symbol: fat\\",
1 1
],
[
"other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to compare incompat",
1
] ]
], ],
"results": [ "results": [
@@ -47,7 +51,7 @@
"name": "attrib.lua", "name": "attrib.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: module 'C' not found\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: module 'C' not found\\\\\\\"\\",
"ms": 6985 "ms": 6723
}, },
{ {
"name": "big.lua", "name": "big.lua",
@@ -59,7 +63,7 @@
"name": "calls.lua", "name": "calls.lua",
"status": "fail", "status": "fail",
"reason": "undefined symbol: fat\\", "reason": "undefined symbol: fat\\",
"ms": 5721 "ms": 5181
}, },
{ {
"name": "checktable.lua", "name": "checktable.lua",
@@ -71,7 +75,7 @@
"name": "closure.lua", "name": "closure.lua",
"status": "timeout", "status": "timeout",
"reason": "per-test timeout", "reason": "per-test timeout",
"ms": 8008 "ms": 8004
}, },
{ {
"name": "code.lua", "name": "code.lua",
@@ -81,9 +85,9 @@
}, },
{ {
"name": "constructs.lua", "name": "constructs.lua",
"status": "timeout", "status": "fail",
"reason": "per-test timeout", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to compare incompat",
"ms": 8007 "ms": 7350
}, },
{ {
"name": "db.lua", "name": "db.lua",
@@ -95,13 +99,13 @@
"name": "errors.lua", "name": "errors.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 4667 "ms": 3439
}, },
{ {
"name": "events.lua", "name": "events.lua",
"status": "timeout", "status": "fail",
"reason": "per-test timeout", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 8007 "ms": 7915
}, },
{ {
"name": "files.lua", "name": "files.lua",
@@ -119,13 +123,13 @@
"name": "literals.lua", "name": "literals.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 2950 "ms": 2141
}, },
{ {
"name": "locals.lua", "name": "locals.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio",
"ms": 2366 "ms": 1799
}, },
{ {
"name": "main.lua", "name": "main.lua",
@@ -137,19 +141,19 @@
"name": "math.lua", "name": "math.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio",
"ms": 4991 "ms": 4738
}, },
{ {
"name": "nextvar.lua", "name": "nextvar.lua",
"status": "timeout", "status": "fail",
"reason": "per-test timeout", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 8007 "ms": 7818
}, },
{ {
"name": "pm.lua", "name": "pm.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 6697 "ms": 6478
}, },
{ {
"name": "sort.lua", "name": "sort.lua",
@@ -161,19 +165,19 @@
"name": "strings.lua", "name": "strings.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 4493 "ms": 4339
}, },
{ {
"name": "vararg.lua", "name": "vararg.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 2541 "ms": 2343
}, },
{ {
"name": "verybig.lua", "name": "verybig.lua",
"status": "pass", "status": "pass",
"reason": "", "reason": "",
"ms": 1187 "ms": 1064
} }
] ]
} }

View File

@@ -1,15 +1,16 @@
# Lua-on-SX conformance scoreboard # Lua-on-SX conformance scoreboard
**Pass rate:** 1/16 runnable (6.2%) **Pass rate:** 1/16 runnable (6.2%)
fail=9 timeout=6 skip=8 total=24 fail=12 timeout=3 skip=8 total=24
## Top failure modes ## Top failure modes
- **6x** timeout - **7x** other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\
- **5x** other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ - **3x** timeout
- **2x** other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio - **2x** other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio
- **1x** other: Unhandled exception: \"Unhandled exception: \\\"lua: module 'C' not found\\\"\ - **1x** other: Unhandled exception: \"Unhandled exception: \\\"lua: module 'C' not found\\\"\
- **1x** undefined symbol: fat\ - **1x** undefined symbol: fat\
- **1x** other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to compare incompat
## Per-test results ## Per-test results
@@ -17,25 +18,25 @@ fail=9 timeout=6 skip=8 total=24
|---|---|---|---:| |---|---|---|---:|
| all.lua | skip | driver uses dofile to chain other tests | 0 | | all.lua | skip | driver uses dofile to chain other tests | 0 |
| api.lua | skip | requires testC (C debug library) | 0 | | api.lua | skip | requires testC (C debug library) | 0 |
| attrib.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: module 'C' not found\\\"\ | 6985 | | attrib.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: module 'C' not found\\\"\ | 6723 |
| big.lua | timeout | per-test timeout | 8008 | | big.lua | timeout | per-test timeout | 8008 |
| calls.lua | fail | undefined symbol: fat\ | 5721 | | calls.lua | fail | undefined symbol: fat\ | 5181 |
| checktable.lua | skip | internal debug helpers | 0 | | checktable.lua | skip | internal debug helpers | 0 |
| closure.lua | timeout | per-test timeout | 8008 | | closure.lua | timeout | per-test timeout | 8004 |
| code.lua | skip | bytecode inspection via debug library | 0 | | code.lua | skip | bytecode inspection via debug library | 0 |
| constructs.lua | timeout | per-test timeout | 8007 | | constructs.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to compare incompat | 7350 |
| db.lua | skip | debug library | 0 | | db.lua | skip | debug library | 0 |
| errors.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4667 | | errors.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3439 |
| events.lua | timeout | per-test timeout | 8007 | | events.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 7915 |
| files.lua | skip | io library | 0 | | files.lua | skip | io library | 0 |
| gc.lua | skip | collectgarbage / finalisers | 0 | | gc.lua | skip | collectgarbage / finalisers | 0 |
| literals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 2950 | | literals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 2141 |
| locals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 2366 | | locals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 1799 |
| main.lua | skip | standalone interpreter driver | 0 | | main.lua | skip | standalone interpreter driver | 0 |
| math.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 4991 | | math.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 4738 |
| nextvar.lua | timeout | per-test timeout | 8007 | | nextvar.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 7818 |
| pm.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 6697 | | pm.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 6478 |
| sort.lua | timeout | per-test timeout | 8007 | | sort.lua | timeout | per-test timeout | 8007 |
| strings.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4493 | | strings.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4339 |
| vararg.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 2541 | | vararg.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 2343 |
| verybig.lua | pass | - | 1187 | | verybig.lua | pass | - | 1064 |

View File

@@ -82,6 +82,7 @@ Each item: implement → tests → tick box → update progress log.
_Newest first. Agent appends on every commit._ _Newest first. Agent appends on every commit._
- 2026-04-25: lua: scoreboard iteration — `math.mod` (Lua 5.0 alias for `fmod`), `math.frexp` (mantissa/exponent split), `math.ldexp` (m·2^e). math.lua moves past line-103 `math.mod` call. Timeouts 6→3, asserts 5→7. 393/393 green.
- 2026-04-25: lua: scoreboard iteration — `unpack(t, i, j)` now treats explicit nil for `i` or `j` as missing (defaults to 1 and `#t`). vararg.lua-style `unpack(args, 1, args.n)` works when `args.n` is nil. Asserts 4→5, timeouts 8→6 (more tests reach assertions instead of timing out). 393/393 green. - 2026-04-25: lua: scoreboard iteration — `unpack(t, i, j)` now treats explicit nil for `i` or `j` as missing (defaults to 1 and `#t`). vararg.lua-style `unpack(args, 1, args.n)` works when `args.n` is nil. Asserts 4→5, timeouts 8→6 (more tests reach assertions instead of timing out). 393/393 green.
- 2026-04-25: lua: scoreboard iteration — extended `string.format`. New `%x`/`%X`/`%o` (hex/octal), `%c` (codepoint→char via `lua-char-one`), `%q` (basic quote), width N (`%5d`), zero-pad (`%05d`), left-align (`%-5d`), `%.Ns` precision. Helpers `lua-fmt-pad` and `lua-fmt-int-base`. 393/393 green (+6 format tests). - 2026-04-25: lua: scoreboard iteration — extended `string.format`. New `%x`/`%X`/`%o` (hex/octal), `%c` (codepoint→char via `lua-char-one`), `%q` (basic quote), width N (`%5d`), zero-pad (`%05d`), left-align (`%-5d`), `%.Ns` precision. Helpers `lua-fmt-pad` and `lua-fmt-int-base`. 393/393 green (+6 format tests).
- 2026-04-25: lua: scoreboard iteration — `lua-eval-ast` now SKIPS the top-level guard when the parsed chunk has no top-level `return` (recursive AST walk via `lua-has-top-return?` that descends through control-flow but stops at function-body boundaries). Without the guard, top-level user defines leak to the SX top env, and `loadstring`-captured closures can find them. Verified: `function fat(x)...loadstring("return fat(...)")...end; x=fat(5)` works (was undefined). Most PUC-Rio tests still have top-level returns elsewhere, so they still need the guard. Scoreboard unchanged at 1/16 but unblocks future work. - 2026-04-25: lua: scoreboard iteration — `lua-eval-ast` now SKIPS the top-level guard when the parsed chunk has no top-level `return` (recursive AST walk via `lua-has-top-return?` that descends through control-flow but stops at function-body boundaries). Without the guard, top-level user defines leak to the SX top env, and `loadstring`-captured closures can find them. Verified: `function fat(x)...loadstring("return fat(...)")...end; x=fat(5)` works (was undefined). Most PUC-Rio tests still have top-level returns elsewhere, so they still need the guard. Scoreboard unchanged at 1/16 but unblocks future work.