Skip to content

Refactor interpreter to policy-based library#583

Merged
kumarak merged 1 commit intomainfrom
feature/interpreter-refactor
Apr 17, 2026
Merged

Refactor interpreter to policy-based library#583
kumarak merged 1 commit intomainfrom
feature/interpreter-refactor

Conversation

@pgoodman
Copy link
Copy Markdown
Collaborator

Summary

  • Extract the 3500-line monolithic interpreter from InterpretIR.cpp into a reusable library at lib/IR/Interpret/ with policy interfaces (ValueFactory, Memory, Driver)
  • Replace the Interpreter class with InterpreterState struct + free functions (InitState/Step) — the interpreter is now a state transition function, not an object
  • CALL instructions push/pop frames on a shared call stack instead of creating recursive child interpreter instances; pointer provenance tracked globally in Memory instead of per-frame shadow maps
  • Includes codegen fixes for Duff's device, implicit switch defaults, goto-into-scope, va_copy, and sized integer opcodes

Test plan

  • All 34/34 interpreter tests pass (up from 31/34 baseline before restructure)
  • Builds clean on macOS/arm64 with Release config
  • CI build on Linux

🤖 Generated with Claude Code

Extract the interpreter from a 3500-line monolith in InterpretIR.cpp into
a reusable library at lib/IR/Interpret/ with policy interfaces (ValueFactory,
Memory, Driver). The interpreter is now a state transition function: InitState()
sets up the call stack, Step() advances one block, and the caller owns the loop.

Key design changes:
- InterpreterState struct + free functions replace the Interpreter class
- CALL pushes callee frames onto a shared call stack; RET pops them
  (no more recursive child interpreter instances)
- Pointer provenance tracked in Memory (WritePointer/ReadPointer) instead
  of per-frame pointer_shadow maps
- Global addresses stored on InterpreterState, not a shared_ptr map
- Suspension/Resolution variants for branch, call, global, and pointer
  resolution enable future symbolic/abstract drivers
- Frame layout (frameOffset, frameSizeBytes) computed at codegen time

Also includes codegen fixes for Duff's device, implicit switch defaults,
goto-into-scope, va_copy, CONSUME_VA_PARAM wrapping, and sized opcodes.

34/34 interpreter tests pass.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@pgoodman pgoodman requested a review from kumarak April 17, 2026 03:57
@kumarak kumarak merged commit 9970c91 into main Apr 17, 2026
2 checks passed
@pgoodman pgoodman deleted the feature/interpreter-refactor branch April 17, 2026 15:22
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.

2 participants