Files
hakorune/docs/archive/mir_25_instruction_mapping.md
Moe Charm ef7a0de3b0 feat: Prepare for code modularization and cleanup
- Archive old documentation and test files to `docs/archive/` and `local_tests/`.
- Remove various temporary and old files from the project root.
- Add `nekocode-rust` analysis tool and its output files (`nekocode/`, `.nekocode_sessions/`, `analysis.json`).
- Minor updates to `apps/chip8_nyash/chip8_emulator.nyash` and `local_tests` files.

This commit cleans up the repository and sets the stage for further code modularization efforts, particularly in the `src/interpreter` and `src/parser` modules, based on recent analysis.
2025-08-16 01:30:39 +09:00

3.1 KiB

MIR 25-Instruction Mapping Plan

Current State: 32 Instructions → Target: 25 Instructions

Tier-0: Universal Core (8 instructions)

  1. Const (already exists)
  2. BinOp (already exists)
  3. Compare (already exists)
  4. Branch (already exists)
  5. Jump (already exists)
  6. Phi (already exists)
  7. Call (already exists)
  8. Return (already exists)

Tier-1: Nyash Semantics (12 instructions)

  1. NewBox (already exists)
  2. BoxFieldLoad ← RENAME from Load/RefGet
  3. BoxFieldStore ← RENAME from Store/RefSet
  4. BoxCall (already exists)
  5. Safepoint (already exists as separate instruction)
  6. RefGet → RENAME to RefGet
  7. RefSet → RENAME to RefSet
  8. WeakNew (already exists)
  9. WeakLoad (already exists)
  10. WeakCheck ← NEW (check weak reference validity)
  11. Send ← NEW (Bus communication)
  12. Recv ← NEW (Bus communication)

Tier-2: Implementation Assistance (5 instructions)

  1. TailCall ← NEW (tail call optimization)
  2. Adopt ← NEW (ownership transfer)
  3. Release ← NEW (ownership release)
  4. MemCopy ← NEW (optimized memory operations)
  5. AtomicFence ← RENAME from BarrierRead/BarrierWrite

Instructions to Remove/Consolidate (7 instructions)

  • UnaryOp → Merge into BinOp or eliminate
  • Load → Consolidate into BoxFieldLoad
  • Store → Consolidate into BoxFieldStore
  • ArrayGet → Use BoxFieldLoad with array indexing
  • ArraySet → Use BoxFieldStore with array indexing
  • Cast → Eliminate or merge into BinOp
  • Copy → Eliminate (optimization-specific)
  • Debug → Remove from MIR (keep as separate system)
  • Print → Use Call with print function
  • Throw → Use Call with exception function
  • Catch → Use Call with catch handler
  • RefNew → Eliminate (use NewBox)
  • TypeCheck → Use Compare with type introspection
  • BarrierRead/BarrierWrite → Consolidate into AtomicFence
  • FutureNew/FutureSet/Await → Use BoxCall with Future methods

Effect System Mapping

Current → New Effect Categories

  • Pure: Const, BinOp, Compare, Phi, RefGet, WeakNew, WeakLoad, WeakCheck
  • Mut: BoxFieldStore, RefSet, Adopt, Release, MemCopy
  • Io: Send, Recv, Safepoint, AtomicFence
  • Control: Branch, Jump, Return, TailCall
  • Context-dependent: Call, BoxCall

Implementation Strategy

Phase 1: Core Instruction Consolidation

  1. Rename Load → BoxFieldLoad
  2. Rename Store → BoxFieldStore
  3. Remove eliminated instructions
  4. Add missing new instructions

Phase 2: Effect System Update

  1. Update effect classification to 4 categories
  2. Update all instruction effect mappings
  3. Implement effect-based optimization rules

Phase 3: Backend Updates

  1. Update Interpreter backend
  2. Update VM backend
  3. Update WASM backend
  4. Ensure all support exactly 25 instructions

Phase 4: Verification System

  1. Implement ownership forest verification
  2. Add strong cycle detection
  3. Add weak reference safety checks
  4. Implement RefSet ownership validation