From 617aa7acc0d89d464b3a5f33f649419359c0ba5e Mon Sep 17 00:00:00 2001 From: Orual Date: Sat, 7 Mar 2026 12:22:14 -0500 Subject: [PATCH] feat: ALLOC_REMOTE reads fref+2 for data-driven ALLOC_SHARED Task 1 Phase 4a Subcomponent A: Updated ALLOC_REMOTE handler in emu/pe.py to read fref+2 from frame constants and conditionally emit ALLOC_SHARED vs ALLOC based on whether parent_act_id is non-zero. Implementation details: - Read fref+0 (target PE), fref+1 (target act_id), and new fref+2 (parent act_id) - If parent_act (fref+2) is non-zero: emit FrameControlToken with op=ALLOC_SHARED and payload=parent_act - If parent_act is zero/None: emit op=ALLOC and payload=0 (backwards compatible) - Frame slots at fref+0, fref+1, fref+2 are assumed to be int values per codegen contract - No runtime type checking added (consistent with existing ALLOC_REMOTE pattern) Accepts AC4.1 (data-driven shared allocation) and AC4.2 (no new opcodes). All 1290 tests pass. Backwards compatibility verified: existing tests with only fref+0/fref+1 populated default fref+2 to None/0 (falsy), so they emit op=ALLOC as before. --- emu/pe.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/emu/pe.py b/emu/pe.py index 2b34b35..24fc384 100644 --- a/emu/pe.py +++ b/emu/pe.py @@ -260,15 +260,27 @@ class ProcessingElement: yield self.env.timeout(1) # EMIT cycle self._do_emit_new(inst, result, False, token.act_id, frame_id) elif inst.opcode == RoutingOp.ALLOC_REMOTE: - # PE-level: read target PE and act_id from frame constants + # PE-level: read target PE, act_id, and optional parent act_id from frame constants + # fref+0: target PE + # fref+1: target act_id + # fref+2: parent act_id (0 = fresh ALLOC, non-zero = ALLOC_SHARED) # Total: 4 cycles (dequeue + IFETCH + EXECUTE + EMIT) target_pe = self.frames[frame_id][inst.fref] if inst.fref < len(self.frames[frame_id]) else 0 target_act = self.frames[frame_id][inst.fref + 1] if inst.fref + 1 < len(self.frames[frame_id]) else 0 + parent_act = self.frames[frame_id][inst.fref + 2] if inst.fref + 2 < len(self.frames[frame_id]) else 0 + + if parent_act: + alloc_op = FrameOp.ALLOC_SHARED + payload = parent_act + else: + alloc_op = FrameOp.ALLOC + payload = 0 + fct = FrameControlToken( target=target_pe, act_id=target_act, - op=FrameOp.ALLOC, - payload=0, + op=alloc_op, + payload=payload, ) self._on_event(Executed( time=self.env.now, component=self._component, -- 2.51.2