feat: bitops shim + Lua 5.1 verification finding (no rockspec change)#3
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-conditionaldependenciestable to pull in thebit32rock on Lua 5.1 only. That mechanism does not exist in modern LuaRocks: the rockspec sandbox (luarocks/core/persist.lua'spersist.load_into_table) exposes the rockspec output table as the env with no globals —_VERSION,table,pcall,ipairsare 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
bit32dep entirely.bitops_compat.luaimplementsband/rshift/lshiftin 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/bitops.lua—_VERSION-based dispatcher (~6 lines, parses on any Lua ≥ 5.1)parse_sdp/grammar/bitops_53.lua— native&/>>/<<, loaded on 5.3+ onlyparse_sdp/grammar/bitops_compat.lua— pure-Lua arithmetic, loaded on 5.1/5.2 onlyparse_sdp/grammar/addresses.lua'sint_to_ipv4andipv6_addnow callbitops.band/bitops.rshift. No&/>>remain in addresses.lua source.Tests.
spec/grammar_bitops_spec.lua(+11 cases) exercises the dispatcher and directly importsbitops_compatso 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 inbuild.modules, fix the onetable.unpackspec call, add the matrix CI job, and bump to 1.3.0.Test plan
docker compose run --rm test→ 1208 successes / 0 failures / 0 errors (Lua 5.5)busted spec/grammar_bitops_spec.luaunder hererocks Lua 5.1 → 11 successes / 0 failuresbusted spec/grammar_addresses_spec.luaunder hererocks Lua 5.1 → 29 successes / 0 failures🤖 Generated with Claude Code