lua: tonumber(s, base) for bases 2-36 +3 tests; math.lua past assert #21
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled

This commit is contained in:
2026-04-24 23:44:08 +00:00
parent 2a4a4531b9
commit 0491f061c4
5 changed files with 104 additions and 52 deletions

View File

@@ -1538,12 +1538,50 @@
(else (lua-to-display v))))) (else (lua-to-display v)))))
(else (lua-to-display v))))) (else (lua-to-display v)))))
(define
lua-parse-int-base
(fn (s base)
(let ((trimmed (trim s)) (neg false) (i 0) (n 0) (valid false))
(begin
(when (and (> (len trimmed) 0) (= (char-at trimmed 0) "-"))
(begin (set! neg true) (set! i 1)))
(when (and (> (len trimmed) i) (= (char-at trimmed i) "+"))
(set! i (+ i 1)))
(define
pi-loop
(fn ()
(when (< i (len trimmed))
(let ((c (char-at trimmed i)))
(let ((d (cond
((and (>= c "0") (<= c "9")) (- (char-code c) (char-code "0")))
((and (>= c "a") (<= c "z")) (+ 10 (- (char-code c) (char-code "a"))))
((and (>= c "A") (<= c "Z")) (+ 10 (- (char-code c) (char-code "A"))))
(else -1))))
(cond
((or (< d 0) (>= d base)) (set! i (len trimmed)))
(else
(begin
(set! n (+ (* n base) d))
(set! valid true)
(set! i (+ i 1))
(pi-loop)))))))))
(pi-loop)
(cond
((not valid) nil)
((< i (len trimmed)) nil)
(neg (- 0 n))
(else n))))))
(define (define
lua-tonumber lua-tonumber
(fn (&rest args) (fn (&rest args)
(let ((v (first args)) (let ((v (first args))
(base (if (> (len args) 1) (nth args 1) nil))) (base (if (> (len args) 1) (nth args 1) nil)))
(cond (cond
((not (= base nil))
(cond
((= (type-of v) "string") (lua-parse-int-base v base))
(else nil)))
((= (type-of v) "number") v) ((= (type-of v) "number") v)
((= (type-of v) "string") (lua-to-number v)) ((= (type-of v) "string") (lua-to-number v))
(else nil))))) (else nil)))))

View File

@@ -1,8 +1,8 @@
{ {
"totals": { "totals": {
"pass": 1, "pass": 1,
"fail": 12, "fail": 11,
"timeout": 3, "timeout": 4,
"skip": 8, "skip": 8,
"total": 24, "total": 24,
"runnable": 16, "runnable": 16,
@@ -11,11 +11,15 @@
"top_failure_modes": [ "top_failure_modes": [
[ [
"other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
8 6
], ],
[ [
"timeout", "timeout",
3 4
],
[
"other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio",
2
], ],
[ [
"other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: module 'C' not found\\\\\\\"\\", "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: module 'C' not found\\\\\\\"\\",
@@ -28,10 +32,6 @@
[ [
"other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to compare incompat", "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to compare incompat",
1 1
],
[
"other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio",
1
] ]
], ],
"results": [ "results": [
@@ -51,19 +51,19 @@
"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": 6137 "ms": 6133
}, },
{ {
"name": "big.lua", "name": "big.lua",
"status": "timeout", "status": "timeout",
"reason": "per-test timeout", "reason": "per-test timeout",
"ms": 8008 "ms": 8007
}, },
{ {
"name": "calls.lua", "name": "calls.lua",
"status": "fail", "status": "fail",
"reason": "undefined symbol: fat\\", "reason": "undefined symbol: fat\\",
"ms": 4744 "ms": 5786
}, },
{ {
"name": "checktable.lua", "name": "checktable.lua",
@@ -87,7 +87,7 @@
"name": "constructs.lua", "name": "constructs.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to compare incompat", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to compare incompat",
"ms": 6638 "ms": 7418
}, },
{ {
"name": "db.lua", "name": "db.lua",
@@ -99,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": 3109 "ms": 4168
}, },
{ {
"name": "events.lua", "name": "events.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 7069 "ms": 7884
}, },
{ {
"name": "files.lua", "name": "files.lua",
@@ -123,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": 1866 "ms": 1796
}, },
{ {
"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": 1612 "ms": 1655
}, },
{ {
"name": "main.lua", "name": "main.lua",
@@ -140,44 +140,44 @@
{ {
"name": "math.lua", "name": "math.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio",
"ms": 3983 "ms": 5457
}, },
{ {
"name": "nextvar.lua", "name": "nextvar.lua",
"status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 6968
},
{
"name": "pm.lua",
"status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 5852
},
{
"name": "sort.lua",
"status": "timeout", "status": "timeout",
"reason": "per-test timeout", "reason": "per-test timeout",
"ms": 8007 "ms": 8007
}, },
{
"name": "pm.lua",
"status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 6576
},
{
"name": "sort.lua",
"status": "timeout",
"reason": "per-test timeout",
"ms": 8008
},
{ {
"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": 3925 "ms": 4708
}, },
{ {
"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": 2195 "ms": 2227
}, },
{ {
"name": "verybig.lua", "name": "verybig.lua",
"status": "pass", "status": "pass",
"reason": "", "reason": "",
"ms": 930 "ms": 959
} }
] ]
} }

View File

@@ -1,16 +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=12 timeout=3 skip=8 total=24 fail=11 timeout=4 skip=8 total=24
## Top failure modes ## Top failure modes
- **8x** other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ - **6x** other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\
- **3x** timeout - **4x** timeout
- **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 - **1x** other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to compare incompat
- **1x** other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio
## Per-test results ## Per-test results
@@ -18,25 +18,25 @@ fail=12 timeout=3 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\\\"\ | 6137 | | attrib.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: module 'C' not found\\\"\ | 6133 |
| big.lua | timeout | per-test timeout | 8008 | | big.lua | timeout | per-test timeout | 8007 |
| calls.lua | fail | undefined symbol: fat\ | 4744 | | calls.lua | fail | undefined symbol: fat\ | 5786 |
| 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 | 8008 |
| code.lua | skip | bytecode inspection via debug library | 0 | | code.lua | skip | bytecode inspection via debug library | 0 |
| constructs.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to compare incompat | 6638 | | constructs.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to compare incompat | 7418 |
| db.lua | skip | debug library | 0 | | db.lua | skip | debug library | 0 |
| errors.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3109 | | errors.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4168 |
| events.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 7069 | | events.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 7884 |
| 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!\\\"\ | 1866 | | literals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 1796 |
| locals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 1612 | | locals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 1655 |
| main.lua | skip | standalone interpreter driver | 0 | | main.lua | skip | standalone interpreter driver | 0 |
| math.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3983 | | math.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 5457 |
| nextvar.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 6968 | | nextvar.lua | timeout | per-test timeout | 8007 |
| pm.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 5852 | | pm.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 6576 |
| sort.lua | timeout | per-test timeout | 8007 | | sort.lua | timeout | per-test timeout | 8008 |
| strings.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3925 | | strings.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4708 |
| vararg.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 2195 | | vararg.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 2227 |
| verybig.lua | pass | - | 930 | | verybig.lua | pass | - | 959 |

View File

@@ -978,6 +978,14 @@ cat > "$TMPFILE" << 'EPOCHS'
(epoch 1895) (epoch 1895)
(eval "(lua-eval-ast \"if string.find(\\\"hello\\\", \\\"^wor\\\") then return 0 else return 1 end\")") (eval "(lua-eval-ast \"if string.find(\\\"hello\\\", \\\"^wor\\\") then return 0 else return 1 end\")")
;; ── tonumber with base (Lua 5.1) ──────────────────────────────
(epoch 1900)
(eval "(lua-eval-ast \"return tonumber('1010', 2)\")")
(epoch 1901)
(eval "(lua-eval-ast \"return tonumber('FF', 16)\")")
(epoch 1902)
(eval "(lua-eval-ast \"if tonumber('99', 8) == nil then return 1 else return 0 end\")")
EPOCHS EPOCHS
OUTPUT=$(timeout 60 "$SX_SERVER" < "$TMPFILE" 2>/dev/null) OUTPUT=$(timeout 60 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
@@ -1482,6 +1490,11 @@ check 1893 "gsub %d → X" '"X + X = X:3"'
check 1894 "find ^ anchor hit" '1' check 1894 "find ^ anchor hit" '1'
check 1895 "find ^ anchor miss" '1' check 1895 "find ^ anchor miss" '1'
# ── tonumber with base ───────────────────────────────────────
check 1900 "tonumber('1010', 2)" '10'
check 1901 "tonumber('FF', 16)" '255'
check 1902 "tonumber('99', 8) → nil" '1'
TOTAL=$((PASS + FAIL)) TOTAL=$((PASS + FAIL))
if [ $FAIL -eq 0 ]; then if [ $FAIL -eq 0 ]; then
echo "ok $PASS/$TOTAL Lua-on-SX tests passed" echo "ok $PASS/$TOTAL Lua-on-SX tests passed"

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-24: lua: scoreboard iteration — `tonumber(s, base)` for bases 2-36. Validates digit ranges per base, supports leading `+`/`-`, trims whitespace. `math.lua` past assert #21. Asserts 8→6, timeouts 3→4. 384/384 green.
- 2026-04-24: lua: scoreboard iteration — added `lua-unwrap-final-return` (post-processor that rewrites top-level `(raise (list 'lua-ret V))``V` so top-level defines leak to SX top and loadstring closures can see them). Tried dropping the function-guard at top level, but too many tests use `if x then return 0 else return err end` at chunk tail, whose returns aren't at the *statement-list* tail — guard still needed. Kept guard + unwrap-as-no-op. Scoreboard unchanged. - 2026-04-24: lua: scoreboard iteration — added `lua-unwrap-final-return` (post-processor that rewrites top-level `(raise (list 'lua-ret V))``V` so top-level defines leak to SX top and loadstring closures can see them). Tried dropping the function-guard at top level, but too many tests use `if x then return 0 else return err end` at chunk tail, whose returns aren't at the *statement-list* tail — guard still needed. Kept guard + unwrap-as-no-op. Scoreboard unchanged.
- 2026-04-24: lua: scoreboard iteration — `lua-pat-strip-captures` helper lets patterns with `(...)` capture parens at least match (captures themselves aren't returned yet — match returns whole match). Unblocks common Lua pattern idioms like `(%a+)=(%d+)`. Scoreboard unchanged. - 2026-04-24: lua: scoreboard iteration — `lua-pat-strip-captures` helper lets patterns with `(...)` capture parens at least match (captures themselves aren't returned yet — match returns whole match). Unblocks common Lua pattern idioms like `(%a+)=(%d+)`. Scoreboard unchanged.
- 2026-04-24: lua: scoreboard iteration — extended pattern engine to `string.match`/`gmatch`/`gsub`. `gsub` now supports string/function/table replacement modes. 381/381 green (+6 pattern tests). - 2026-04-24: lua: scoreboard iteration — extended pattern engine to `string.match`/`gmatch`/`gsub`. `gsub` now supports string/function/table replacement modes. 381/381 green (+6 pattern tests).