Preserve structured diagnostics, source attribution, phase outcomes and revision context through compiler, Studio, LSP, MCP and JavaFX. Add project service discovery and resilient VS Code reconnection. Correct all eight reproduced PBS production failures in expression context, sibling executable bindings and nominal owner identity. Consolidate specs, lessons, immutable baseline evidence and the maintained source-to-guest qualification runner. Validation: required Gradle gate recorded 724 tests, with 711 passed and 13 skipped. Full corpus passed 168 compilation observations and 108 guest runs (104 successes and four deliberate faults); supplemental controls passed 42 compilations and 16 guest runs. TypeScript compilation, two Node discovery tests and discussion validation passed.
135 lines
7.9 KiB
Java
135 lines
7.9 KiB
Java
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import p.studio.compiler.FrontendRegistryService;
|
|
import p.studio.compiler.messages.BuildingIssue;
|
|
import p.studio.compiler.messages.BuilderPipelineConfig;
|
|
import p.studio.compiler.models.BuilderPipelineContext;
|
|
import p.studio.compiler.source.identifiers.FileId;
|
|
import p.studio.compiler.workspaces.BuilderPipelineService;
|
|
import p.studio.compiler.workspaces.PipelineStage;
|
|
import p.studio.compiler.workspaces.stages.*;
|
|
import p.studio.utilities.logs.LogAggregator;
|
|
|
|
import java.nio.file.*;
|
|
import java.security.MessageDigest;
|
|
import java.util.*;
|
|
|
|
/** Research-only probe: production stages, isolated source projects, no compiler changes. */
|
|
public final class Agd113Probe {
|
|
static final ObjectMapper MAPPER = new ObjectMapper();
|
|
static final List<String> LOG = new ArrayList<>();
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
Path root = Path.of(args[0]).toRealPath();
|
|
boolean optimize = args[1].equals("optimized");
|
|
boolean publicEntry = args.length > 3 && args[3].equals("public");
|
|
var result = new LinkedHashMap<String, Object>();
|
|
result.put("projectRoot", root.toString());
|
|
result.put("optimization", optimize ? "optimized" : "unoptimized");
|
|
result.put("entrypoint", publicEntry ? "BuilderPipelineService.compile" : "public analysis + production compile stages");
|
|
result.put("frontendOrigin", FrontendRegistryService.require("pbs").getClass().getProtectionDomain().getCodeSource().getLocation().toString());
|
|
result.put("pipelineOrigin", BuilderPipelineService.class.getProtectionDomain().getCodeSource().getLocation().toString());
|
|
var ctx = BuilderPipelineContext.fromConfig(new BuilderPipelineConfig(false, root.toString()));
|
|
var logs = LogAggregator.with(LOG::add);
|
|
var phases = new ArrayList<Map<String, Object>>();
|
|
result.put("phases", phases);
|
|
result.put("status", "infrastructure_failure");
|
|
try {
|
|
if (publicEntry) {
|
|
var compiled = BuilderPipelineService.INSTANCE.compile(ctx, logs);
|
|
result.put("diagnostics", compiled.diagnostics().stream().map(i -> issue(i, ctx)).toList());
|
|
result.put("status", "compiled");
|
|
} else {
|
|
var analyzed = BuilderPipelineService.INSTANCE.analyze(ctx, logs);
|
|
var phase = new LinkedHashMap<String, Object>();
|
|
phase.put("phase", "analysis");
|
|
phase.put("diagnostics", analyzed.diagnostics().stream().map(i -> issue(i, ctx)).toList());
|
|
boolean failed = analyzed.diagnostics().stream().anyMatch(BuildingIssue::isError);
|
|
phase.put("status", failed ? "failed" : "passed");
|
|
phases.add(phase);
|
|
if (failed) result.put("status", "analysis_failed");
|
|
else {
|
|
var stages = new ArrayList<PipelineStage>();
|
|
stages.add(new LowerToIRVMPipelineStage());
|
|
if (optimize) stages.add(new OptimizeIRVMPipelineStage());
|
|
stages.add(new EmitBytecodePipelineStage());
|
|
stages.add(new LinkBytecodePipelineStage());
|
|
stages.add(new VerifyBytecodePipelineStage());
|
|
result.put("status", "compiled");
|
|
for (var stage : stages) {
|
|
if (!optimize && stage instanceof EmitBytecodePipelineStage) ctx.optimizedIrvm = ctx.irvm;
|
|
var issues = stage.run(ctx, logs).asCollection();
|
|
var item = new LinkedHashMap<String, Object>();
|
|
item.put("phase", stage.getClass().getSimpleName());
|
|
item.put("diagnostics", issues.stream().map(i -> issue(i, ctx)).toList());
|
|
boolean errors = issues.stream().anyMatch(BuildingIssue::isError);
|
|
item.put("status", errors ? "failed" : "passed");
|
|
phases.add(item);
|
|
if (errors) { result.put("status", "compile_failed"); break; }
|
|
}
|
|
}
|
|
}
|
|
if (result.get("status").equals("compiled")) {
|
|
Path cartridge = root.resolve("cartridge");
|
|
Files.createDirectories(cartridge);
|
|
Files.write(cartridge.resolve("program.pbx"), ctx.bytecodeBytes);
|
|
var manifest = new LinkedHashMap<String, Object>();
|
|
manifest.put("magic", "PMTU"); manifest.put("cartridge_version", 1);
|
|
manifest.put("app_id", 113); manifest.put("title", "AGD113 isolated assertion fixture");
|
|
manifest.put("app_version", "1.0.0"); manifest.put("app_mode", "Game");
|
|
manifest.put("capabilities", List.of()); manifest.put("asset_table", List.of()); manifest.put("preload", List.of());
|
|
MAPPER.writerWithDefaultPrettyPrinter().writeValue(cartridge.resolve("manifest.json").toFile(), manifest);
|
|
result.put("cartridge", cartridge.toString());
|
|
result.put("bytecodeBytes", ctx.bytecodeBytes.length);
|
|
result.put("bytecodeSha256", HexFormat.of().formatHex(MessageDigest.getInstance("SHA-256").digest(ctx.bytecodeBytes)));
|
|
}
|
|
} catch (Throwable failure) {
|
|
result.put("status", failure instanceof p.studio.compiler.exceptions.BuildException
|
|
? "public_compile_rejected" : "pipeline_exception");
|
|
result.put("exception", causes(failure));
|
|
}
|
|
if (ctx.fileTable != null) {
|
|
var files = new LinkedHashMap<String, Object>();
|
|
for (int i = 0; i < ctx.fileTable.size(); i++) {
|
|
var f = ctx.fileTable.get(new FileId(i));
|
|
files.put(Integer.toString(i), f.getCanonPath().toString());
|
|
}
|
|
result.put("files", files);
|
|
}
|
|
if (ctx.irBackend != null) {
|
|
var functions = new ArrayList<Map<String, Object>>();
|
|
for (var fn : ctx.irBackend.getExecutableFunctions()) {
|
|
var file = ctx.fileTable.get(fn.fileId()).getCanonPath();
|
|
if (!file.startsWith(root)) continue;
|
|
var f = new LinkedHashMap<String, Object>();
|
|
f.put("callableId", fn.callableId().toString()); f.put("name", fn.callableName());
|
|
f.put("file", root.relativize(file).toString());
|
|
f.put("instructions", fn.instructions().stream().map(Object::toString).toList());
|
|
functions.add(f);
|
|
}
|
|
result.put("projectFunctions", functions);
|
|
}
|
|
result.put("logs", LOG);
|
|
Path report = Path.of(args[2]); Files.createDirectories(report.getParent());
|
|
MAPPER.writerWithDefaultPrettyPrinter().writeValue(report.toFile(), result);
|
|
System.out.println(result.get("status") + " " + root.getFileName());
|
|
}
|
|
|
|
static Map<String, Object> issue(BuildingIssue i, BuilderPipelineContext ctx) {
|
|
var out = new LinkedHashMap<String, Object>();
|
|
out.put("error", i.isError()); out.put("code", i.getCode()); out.put("phase", i.getPhase());
|
|
out.put("message", i.getMessage()); out.put("fileId", i.getFileId());
|
|
out.put("start", i.getStart()); out.put("end", i.getEnd());
|
|
out.put("functionIndex", i.getFunctionIndex()); out.put("pc", i.getPc());
|
|
if (i.getFileId() != null && i.getFileId() >= 0 && ctx.fileTable != null && i.getFileId() < ctx.fileTable.size())
|
|
out.put("file", ctx.fileTable.get(new FileId(i.getFileId())).getCanonPath().toString());
|
|
if (i.getException() != null) out.put("exception", causes(i.getException()));
|
|
return out;
|
|
}
|
|
static List<Map<String, String>> causes(Throwable t) {
|
|
var result = new ArrayList<Map<String, String>>();
|
|
for (int n = 0; t != null && n < 8; n++, t = t.getCause())
|
|
result.add(Map.of("class", t.getClass().getName(), "message", String.valueOf(t.getMessage())));
|
|
return result;
|
|
}
|
|
}
|