Skip to content

feat(isaspec): spec-driven mix over the 6502 — the dynarec on a real, memory-bearing ISA (shadow*) - #9336

Merged
AceHack merged 1 commit into
mainfrom
otto/spec-driven-mix-over-6502-memory
Jul 3, 2026
Merged

feat(isaspec): spec-driven mix over the 6502 — the dynarec on a real, memory-bearing ISA (shadow*)#9336
AceHack merged 1 commit into
mainfrom
otto/spec-driven-mix-over-6502-memory

Conversation

@AceHack

@AceHack AceHack commented Jul 3, 2026

Copy link
Copy Markdown
Member

What

The named #1 follow-on to the 6502 spec (#9333), under "build whatever you like": the actual Futamura 1st projection — partial evaluation (= dynarec) — on a real ISA's real memory model, not the CHIP-8 toy.

specializeMem extends the spec-driven mix to fold static zero-page memory as well as static registers, over any ISA given its spec + a register loadImm builder:

  • setreg with a static value (incl. a static mem read whose cell is known) folds; a dynamic value residualizes (static reg reads materialized via loadImm).
  • setmem addr,val (static addr): a static val folds into known memory; a dynamic val residualizes and marks that cell dynamic. A dynamic address is out of the fragment (zero-page ops address a constant cell).

tryStatic/readsInKnown now thread a knownMem model; the register-only specialize is untouched (passes empty mem). Added LDX_IMM/LDY_IMM (real 6502 A2/A0) + load6502 so the builder is total over A/X/Y, and the ADC_ZP constructor.

The extended S-m-n law (machine-checked, differential)

evalSpecFull spec residual dynReg dynMem  ⊕  (knownReg, knownMem)
   =  evalSpecFull spec p (staticReg ∪ dynReg) (staticMem ∪ dynMem)

Proven across dynamic cell values — the memory-aware mix is correct.

Tests — 2 new, 12 total green (build 0/0)

  1. the law over registers AND memory — A static, mem[20] dynamic; static ops (incl. a static memory read) fold, the dynamic ADC_ZP and everything after it residualize; residual+known overlay = full run, for cell ∈ {0,1,100,250}
  2. specialization reduces — an all-static program folds to an empty residual (all work done at mix time)

The ladder now

1st projection → 2nd → general mix → Column B (gates → CPU → synthesizable CPU) → the target knob (Code|Circuit) → ISA-as-data + memory + the 6502 → the mix folding a real ISA's memory (this). The dynarec is no longer toy-only.

🤖 Generated with Claude Code

… memory-bearing ISA (shadow*)

Aaron 2026-07-03 "build whatever you like" — the named #1 follow-on to the 6502
spec: the actual Futamura 1st projection (partial evaluation = dynarec) on a real
ISA's real memory model, not the CHIP-8 toy.

specializeMem extends the spec-driven mix to fold static ZERO-PAGE MEMORY as well
as static registers, over any ISA given its spec + a register loadImm builder:
  - setreg with a static value (incl. a static mem read whose cell is known) FOLDS;
    a dynamic value residualizes (static reg reads materialized via loadImm).
  - setmem addr,val (static addr): static val FOLDS into known memory; dynamic val
    residualizes and marks that cell dynamic. Dynamic addr is out of the fragment.
tryStatic/readsInKnown now thread a knownMem model (mem-read folds; the register-
only `specialize` is untouched, passes an empty mem). For the 6502's zero-page ops
the address is always a static field, so no dynamic-address materialization arises.

Added LDX_IMM/LDY_IMM (real 6502 A2/A0) + load6502 so the loadImm builder is total
over the ISA's A/X/Y registers, and the ADC_ZP constructor.

The EXTENDED S-m-n law is machine-checked differentially:
  evalSpecFull spec residual dynReg dynMem  ⊕  (knownReg, knownMem)
    =  evalSpecFull spec p (staticReg∪dynReg) (staticMem∪dynMem)

12 IsaSpec tests green (2 new: the law over regs+memory across dynamic cell values;
specialization reduces an all-static program to an EMPTY residual). Build 0/0.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

AgencySignature-v1:
  persona: otto
  actor: otto-column-b
  surface: src/Core/IsaSpec.fs
  topology: cowork-sandbox-clone
  intent: dynarec-over-a-real-memory-bearing-isa-partial-evaluation-folding-static-memory
  authorization: aaron-2026-07-03-build-whatever-you-like
  uncertainty: low
  measure: specializeMem-folds-static-regs-and-zero-page-mem-extended-s-m-n-law-differential-green-12-tests-build-0-0
  delta-u: the-futamura-1st-projection-now-runs-on-a-real-isas-memory-model-proven-correct-not-just-the-toy
  seed: S4
@AceHack
AceHack enabled auto-merge (squash) July 3, 2026 18:20
@AceHack
AceHack merged commit 7784fb7 into main Jul 3, 2026
2 checks passed
@AceHack
AceHack deleted the otto/spec-driven-mix-over-6502-memory branch July 3, 2026 18:20
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

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