Skip to content

feat(stdlib): utf8 library + align integer-arith error wording#258

Open
davydog187 wants to merge 1 commit into
mainfrom
stdlib/utf8-and-error-wording
Open

feat(stdlib): utf8 library + align integer-arith error wording#258
davydog187 wants to merge 1 commit into
mainfrom
stdlib/utf8-and-error-wording

Conversation

@davydog187
Copy link
Copy Markdown
Contributor

Bundles two T1 suite-progress issues: implements the utf8 stdlib (#253) and normalises a handful of stdlib/executor error templates to match PUC-Lua wording (#252).

Summary

  • New utf8 standard library (lib/lua/vm/stdlib/utf8.ex): full Lua 5.3 §6.5 surface — char, codepoint, codes, len, offset, charpattern. Validates the 0x0..0x10FFFF range, rejects overlong sequences, continuation-byte starts, and codepoints above U+10FFFF. The official suite's utf8.lua now passes outright and is removed from test/lua53_skips.exs.
  • Error wording normalisation for integer divide/modulo by zero:
    • 1 // 0"attempt to perform 'n//0'" (was "attempt to divide by zero")
    • 1 % 0"attempt to perform 'n%0'" (was "attempt to perform modulo by zero")
  • ArgumentError.wrong_number_of_arguments/1 constructor: shared helper for the PUC-Lua "wrong number of arguments to 'X'" runtime-error template. table.insert now routes through it; other variadic stdlib sites can adopt as they're audited.
  • Each touched template is pinned with a unit test in test/lua/vm/error_format_test.exs.

Out of scope (follow-ups for #252)

Threading (field 'X') / (global 'X') / (local 'X') target hints into arithmetic-type errors (e.g. so math.huge << 1 surfaces field 'huge') requires plumbing a hint parameter through every raise_arith_type_error caller — eight callsites, plus the VM dispatcher that knows the operand's lexical origin. Left for a follow-up because it's a larger refactor than the wording fixes in this PR.

The other :all-deferred suite files (math.lua, sort.lua, errors.lua, strings.lua) still fail at early, non-wording-related assertions and stay :all-skipped; further narrowing depends on the field-hint work above plus other behavioural fixes.

Test plan

  • mix test — 1953 passed (was 1914 on baseline), 25 skipped (was 26 — utf8.lua promoted out)
  • mix format --check-formatted
  • mix dialyzer — no new errors (one pre-existing on main in tasks/suite_runner.ex)
  • test/lua/vm/stdlib/utf8_test.exs — 29 tests covering happy path + every error template
  • test/lua/vm/error_format_test.exs — 9 tests pinning every PUC-aligned template

Closes #253. Progresses #252.

Implements the Lua 5.3 §6.5 `utf8` standard library — `char`,
`codepoint`, `codes`, `len`, `offset`, `charpattern` — covering the
0x0..0x10FFFF range with overlong/invalid-sequence detection. The
official suite's `utf8.lua` now passes outright and is promoted out
of the skip list.

Also normalises integer-arithmetic error phrasing to match PUC-Lua:
"attempt to perform 'n//0'" (was "attempt to divide by zero") and
"attempt to perform 'n%0'" (was "attempt to perform modulo by zero").
Adds an `ArgumentError.wrong_number_of_arguments/1` helper as the
shared constructor for the variadic-stdlib runtime-error template.
Each touched template is pinned with a unit test in
`test/lua/vm/error_format_test.exs`.

Closes #253. Progresses #252 (the listed `n//0`, `n%0`, and "wrong
number of arguments" templates; field-hint threading on arithmetic
sites deferred to a follow-up — requires plumbing target hints through
all `raise_arith_type_error` callsites).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement utf8 standard library

1 participant