feat(studio): integrate memcard persistence and headless controls
Persist cartridge identity and slot configuration, add MemcardBoot and the MemcardBuffer SDK, and consume the runtime's negotiated memcard host controls with protected teardown. Qualify save/reopen and version upgrades through distinct configured runtime processes. Include specs, examples, regression evidence and the consolidated discussion lesson.
This commit is contained in:
+16
-1
@@ -156,6 +156,15 @@ public final class LifecycleAssemblerService {
|
||||
0,
|
||||
frameExecutable.span()));
|
||||
}
|
||||
for (final var bootstrap : declaration.bootstrapCalls()) {
|
||||
wrapperInstructions.add(new IRBackendExecutableFunction.Instruction(
|
||||
IRBackendExecutableFunction.InstructionKind.CALL_HOST, "", null, bootstrap, null,
|
||||
bootstrap.argSlots(), bootstrap.retSlots(), frameExecutable.span()));
|
||||
for (int i = 0; i < bootstrap.retSlots(); i++) {
|
||||
wrapperInstructions.add(new IRBackendExecutableFunction.Instruction(
|
||||
IRBackendExecutableFunction.InstructionKind.POP, "", null, null, frameExecutable.span()));
|
||||
}
|
||||
}
|
||||
wrapperInstructions.add(pushBoolInstruction(true, frameExecutable.span()));
|
||||
wrapperInstructions.add(setGlobalInstruction(bootGuardSlot, frameExecutable.span()));
|
||||
wrapperInstructions.add(labelInstruction("bootstrap_done", frameExecutable.span()));
|
||||
@@ -171,7 +180,7 @@ public final class LifecycleAssemblerService {
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
2,
|
||||
Math.max(2, declaration.bootstrapCalls().stream().mapToInt(IRBackendExecutableFunction.HostCallMetadata::retSlots).max().orElse(0)),
|
||||
ReadOnlyList.wrap(wrapperInstructions),
|
||||
frameExecutable.span()));
|
||||
syntheticFunctions.add(new IRSyntheticFunction(
|
||||
@@ -221,6 +230,12 @@ public final class LifecycleAssemblerService {
|
||||
final IRLifecycleDeclaration declaration,
|
||||
final BuildingIssueSink issues) {
|
||||
var valid = true;
|
||||
for (final var bootstrap : declaration.bootstrapCalls()) {
|
||||
if (bootstrap.argSlots() != 0) {
|
||||
report(issues, null, "bootstrap boundary must not require operands from initialization");
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
for (final var synthetic : backend.getSyntheticFunctions()) {
|
||||
if (synthetic.kind() != IRSyntheticCallableKind.FILE_INIT_FRAGMENT) {
|
||||
report(issues, synthetic.origin().span(),
|
||||
|
||||
+21
@@ -22,6 +22,27 @@ public final class AssembleLifecyclePipelineStage implements PipelineStage {
|
||||
@Override
|
||||
public BuildingIssueSink run(final BuilderPipelineContext ctx, final LogAggregator logs) {
|
||||
final var issues = BuildingIssueSink.empty();
|
||||
if (ctx.rootProjectPathCanon != null && ctx.irBackend != null) {
|
||||
final var slots = p.studio.compiler.utilities.PrometeuManifestUtils.memcardSlots(
|
||||
ctx.rootProjectPathCanon.resolve("prometeu.json"), issues);
|
||||
final var roles = ctx.irBackend.getExecutableFunctions().stream().filter(f -> f.metadata() != null
|
||||
&& f.metadata().role() == p.studio.compiler.models.registry.IRRegistry.Role.MEMCARD_BOOT).count();
|
||||
final var capability = ctx.irBackend.getReservedMetadata().requiredCapabilities().contains("memcard");
|
||||
final var boundary = ctx.irBackend.getLifecycleDeclaration() != null
|
||||
&& ctx.irBackend.getLifecycleDeclaration().bootstrapCalls().stream().anyMatch(c ->
|
||||
c.module().equals("mem") && c.name().equals("bootstrap") && c.version() == 1
|
||||
&& c.argSlots() == 0 && c.retSlots() == 1);
|
||||
if ((slots != null || roles != 0 || capability || boundary)
|
||||
&& (slots == null || roles != 1 || !capability || !boundary)) {
|
||||
issues.report(b -> b.error(true).phase("lifecycle-assembly").code("COMMON_MEMCARD_CONFIGURATION")
|
||||
.message("memcard requires memcard_slots (1..64), capability, one MemcardBoot role and a bootstrap boundary"));
|
||||
}
|
||||
if (slots != null && ctx.resolvedWorkspace != null && ctx.resolvedWorkspace.target() != p.studio.AppMode.Game) {
|
||||
issues.report(b -> b.error(true).phase("lifecycle-assembly").code("COMMON_MEMCARD_CONFIGURATION")
|
||||
.message("memcard is available only to the runtime Game profile"));
|
||||
}
|
||||
if (issues.hasErrors()) return issues;
|
||||
}
|
||||
final var assembled = assembler.assemble(ctx.irBackend, issues);
|
||||
if (!issues.hasErrors()) {
|
||||
ctx.irBackend = assembled;
|
||||
|
||||
+21
@@ -30,6 +30,27 @@ import java.util.Arrays;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class LifecycleAssemblerServiceTest {
|
||||
@Test void neutralHostBootstrapRunsAfterInitializersBeforeGuardAndFrame() {
|
||||
final var original = declarativeBackend().getLifecycleDeclaration();
|
||||
final var request = new IRBackendExecutableFunction.HostCallMetadata("neutral-provider", "prepare", 7, 0, 1);
|
||||
final var backend = backendWithDeclaration(new IRLifecycleDeclaration(original.modules(), original.projectInit(),
|
||||
original.frameRoot(), ReadOnlyList.from(request)));
|
||||
final var issues = BuildingIssueSink.empty();
|
||||
final var assembled = new LifecycleAssemblerService().assemble(backend, issues);
|
||||
assertFalse(issues.hasErrors(), issues.asCollection().toString());
|
||||
final var instructions = executable(assembled, assembled.getEntryPointCallableName()).instructions();
|
||||
int index = -1;
|
||||
for (int i = 0; i < instructions.size(); i++) {
|
||||
if (instructions.get(i).kind() == IRBackendExecutableFunction.InstructionKind.CALL_HOST) index = i;
|
||||
}
|
||||
assertTrue(index > 0);
|
||||
assertEquals(request, instructions.get(index).hostCall());
|
||||
assertEquals(IRBackendExecutableFunction.InstructionKind.CALL_FUNC, instructions.get(index - 1).kind());
|
||||
assertEquals(IRBackendExecutableFunction.InstructionKind.POP, instructions.get(index + 1).kind());
|
||||
assertEquals(IRBackendExecutableFunction.InstructionKind.SET_GLOBAL, instructions.get(index + 3).kind());
|
||||
assertEquals(IRBackendExecutableFunction.InstructionKind.LABEL, instructions.get(index + 4).kind());
|
||||
assertEquals("frame", instructions.get(index + 5).calleeCallableName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void assembleMustMaterializeNeutralLifecycleArtifactsInDeclaredOrder() {
|
||||
|
||||
Reference in New Issue
Block a user