Skip to content

refactor: drive opcode dispatch from the Registry#131

Merged
mw2000 merged 2 commits intomainfrom
refactor/opcode-registry-dispatch
Apr 28, 2026
Merged

refactor: drive opcode dispatch from the Registry#131
mw2000 merged 2 commits intomainfrom
refactor/opcode-registry-dispatch

Conversation

@mw2000
Copy link
Copy Markdown
Owner

@mw2000 mw2000 commented Apr 28, 2026

Summary

  • Each opcode entry in EEVM.Interpreter.Instructions.Registry now carries :module (the implementing module) and an optional :state_mutating flag.
  • EEVM.Interpreter.execute_opcode/2 is reduced from a ~60-line case table to a single registry lookup:
    • state-mutating opcode in a static frame → halt :reverted
    • module found → delegate execute(opcode, state)
    • unknown opcode → halt :invalid
  • One source of truth for opcode metadata + dispatch. Adding a new opcode now means one map entry instead of two synchronized places.

Test plan

  • mix test — 4 doctests, 613 tests, 0 failures (no behavior change)
  • mix credo --strict clean
  • mix format --check-formatted clean
  • mix compile --warnings-as-errors clean

🤖 Generated with Claude Code

mw2000 and others added 2 commits April 28, 2026 01:26
Replace the hand-maintained case-clause dispatch in `EEVM.Interpreter`
with a single registry lookup. Each opcode entry in
`EEVM.Interpreter.Instructions.Registry` now carries `:module` (the
implementing module) and an optional `:state_mutating` flag.

`execute_opcode/2` becomes:
- if the opcode is state-mutating and the frame is static → halt :reverted
- if the registry has a module → delegate `execute(opcode, state)`
- otherwise → halt :invalid

One source of truth for opcode metadata + dispatch, fewer places to
forget when adding a new opcode, and the static-context check is
expressed declaratively instead of as five separate guard clauses.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
ExDoc treats backtick-wrapped `Mod.fun/arity` as an autolink target and
warns when it points at a private function. Rephrase the Registry
moduledoc to reference `EEVM.Interpreter` (the module) instead.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@mw2000 mw2000 merged commit 22a1752 into main Apr 28, 2026
3 checks passed
@mw2000 mw2000 deleted the refactor/opcode-registry-dispatch branch April 28, 2026 08:50
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