Skip to content

feat: bitops shim + Lua 5.1 verification finding (no rockspec change)#3

Merged
andrewstarks merged 2 commits into
mainfrom
feat/lua51-bitops-shim
May 26, 2026
Merged

feat: bitops shim + Lua 5.1 verification finding (no rockspec change)#3
andrewstarks merged 2 commits into
mainfrom
feat/lua51-bitops-shim

Conversation

@andrewstarks
Copy link
Copy Markdown
Owner

Summary

Implements the shim slice of the Lua 5.1/5.2 compat plan and records the verification finding that reshaped the plan along the way.

  • Verification finding (slice 1, captured in PLAN.md). The original plan called for a _VERSION-conditional dependencies table to pull in the bit32 rock on Lua 5.1 only. That mechanism does not exist in modern LuaRocks: the rockspec sandbox (luarocks/core/persist.lua's persist.load_into_table) exposes the rockspec output table as the env with no globals_VERSION, table, pcall, ipairs are all absent. Confirmed against LuaRocks 3.8.0 under hererocks-built Lua 5.1 and 5.4 envs. There is also no Lua-version-conditional schema feature (platforms.* is OS-only).

  • Resolution (signed off): drop the bit32 dep entirely. bitops_compat.lua implements band / rshift / lshift in pure-Lua arithmetic. Operands are bounded (32-bit IPv4 ints / 16-bit IPv6 groups), comfortably inside Lua 5.1's double-precision mantissa.

  • Shim (slice 2, this PR). Three new files:

    parse_sdp/grammar/addresses.lua's int_to_ipv4 and ipv6_add now call bitops.band / bitops.rshift. No & / >> remain in addresses.lua source.

  • Tests. spec/grammar_bitops_spec.lua (+11 cases) exercises the dispatcher and directly imports bitops_compat so the arithmetic backend is covered even on Lua 5.3+ CI. Suite is now 1208 (was 1197).

  • Rockspec is unchanged in this PR — still lua >= 5.3, < 5.6. The compat slice (next PR) will relax the dep, register the three new modules in build.modules, fix the one table.unpack spec call, add the matrix CI job, and bump to 1.3.0.

Test plan

  • docker compose run --rm test1208 successes / 0 failures / 0 errors (Lua 5.5)
  • busted spec/grammar_bitops_spec.lua under hererocks Lua 5.1 → 11 successes / 0 failures
  • busted spec/grammar_addresses_spec.lua under hererocks Lua 5.1 → 29 successes / 0 failures
  • CI on this PR stays green (Lua 5.5 via Docker)
  • Full Lua 5.1 / 5.2 / 5.3 / 5.4 matrix run lands in the next PR (compat slice)

🤖 Generated with Claude Code

andrewstarks and others added 2 commits May 26, 2026 13:51
…itops

Verification slice found that the rockspec sandbox in modern LuaRocks
(3.x; confirmed against 3.8.0 under hererocks-built 5.1 + 5.4 envs)
exposes no globals — _VERSION, table, pcall, ipairs are all absent.
The original plan's `if _VERSION == "Lua 5.1" then table.insert(
dependencies, "bit32") end` pattern cannot work. There is also no
documented per-Lua-version conditional mechanism: rockspec
platforms.* is OS-only.

Resolution (signed off): drop the bit32 dep entirely. bitops_compat.lua
implements band/rshift/lshift in pure-Lua arithmetic. Operands are
bounded (32-bit IPv4 ints / 16-bit IPv6 groups), well within the
Lua 5.1 double-precision mantissa. Single rockspec, no new deps on
any Lua version.

Updates verification-finding section, revises rockspec section,
revises migration / risks / task-checklist accordingly. Verification
slice marked done; shim and compat slices remain.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Three-file shim so Lua 5.3+ native-operator syntax never reaches a
5.1/5.2 parser, and 5.1/5.2 get a pure-Lua arithmetic backend with
no extra rock to install:

- parse_sdp/grammar/bitops.lua         — dispatcher (_VERSION-based)
- parse_sdp/grammar/bitops_53.lua      — native `&` / `>>` / `<<`
- parse_sdp/grammar/bitops_compat.lua  — pure-Lua arithmetic

addresses.lua's int_to_ipv4 and ipv6_add now call bitops.band /
bitops.rshift; no `&` / `>>` remain in the source. Behavior unchanged
on Lua 5.3+ — the existing 1197 hermetic tests still pass under the
Docker 5.5 run; full suite is now 1208 with +11 bitops cases. Suite
also passes under a hererocks-built Lua 5.1 env, confirming the
arithmetic backend is correct.

Rockspec is unchanged in this commit — still `lua >= 5.3, < 5.6`.
The compat slice (next PR) relaxes the dep and adds the matrix CI
job.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@andrewstarks andrewstarks merged commit a321478 into main May 26, 2026
2 checks passed
@andrewstarks andrewstarks deleted the feat/lua51-bitops-shim branch May 26, 2026 19:52
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.

1 participant