- 신선한 탐사자(fable) 단일 컨텍스트, 지시서 -round10-brief.md §2 레인 A·C 완료, B 부분, D ALL PASS - audit/handtrace-round10-reference-impl/: round7 참조 구현을 현재 계약으로 갱신·재실행 (부수: round7/ref9 _recompute 첫 인자 오류 발견·정정) - base/·인덱스 레이어는 미변경 — 결정은 사용자 배치 회신 뒤 -round10-followup.md로 Co-authored-by: qwreey <me@qwreey.moe> Claude-Session: https://claude.ai/code/session_01546hjsYNLSMZdHdPyTZaGb
46 lines
1.8 KiB
Text
46 lines
1.8 KiB
Text
--!nocheck
|
|
-- base/dispatch-core-plan.md "Dispatch 체인" 절의 확정 의사코드 그대로
|
|
local C = {}
|
|
local chains = {}
|
|
local NOOP = function() end
|
|
local handlers = {}
|
|
function C.addHandler(h) table.insert(handlers, h) end
|
|
local function getHandler(inst, k, v)
|
|
for _, h in handlers do if h.isHandlable(inst, k, v) then return h end end
|
|
error("Dispatch: 매치되는 핸들러 없음")
|
|
end
|
|
function C.process(inst, k, v, index)
|
|
local list = chains[inst] and chains[inst][k]
|
|
if not list then
|
|
list = {}
|
|
chains[inst] = chains[inst] or {}
|
|
chains[inst][k] = list
|
|
end
|
|
local slot = list[index]
|
|
local h = getHandler(inst, k, v)
|
|
if slot ~= nil and slot.handler == h then
|
|
slot.retractor(v)
|
|
slot.retractor = NOOP
|
|
local retractor = h.process(inst, k, v, index)
|
|
if retractor == nil then error("Dispatch: 핸들러가 retractor 반환을 생략했음 — 생략 불가") end
|
|
slot.retractor = retractor
|
|
else
|
|
C.retractFrom(inst, k, index)
|
|
list[index] = { handler = h, retractor = NOOP }
|
|
local retractor = h.process(inst, k, v, index)
|
|
if retractor == nil then error("Dispatch: 핸들러가 retractor 반환을 생략했음 — 생략 불가") end
|
|
list[index] = { handler = h, retractor = retractor }
|
|
end
|
|
end
|
|
function C.retractFrom(inst, k, index)
|
|
local list = chains[inst] and chains[inst][k]
|
|
if not list then return end
|
|
for i = #list, index, -1 do
|
|
local slot = list[i]
|
|
if slot == nil then error("Dispatch: 인덱스 " .. i .. "에 슬롯이 없음 — 배열에 구멍이 뚫렸음") end
|
|
slot.retractor(nil)
|
|
list[i] = nil
|
|
end
|
|
end
|
|
C.dump = function(inst, k) return chains[inst] and chains[inst][k] end
|
|
return C
|