feat: type_fields in diff and tracker, joined with emulator property reads

The tracker lists each scope's original properties (constructor chain,
or class fields up the chain for Piklib 6.1 and singletons such as
SCENE) and where the emulator reads them: a CNVParser.createVariable
case arm, an attribute read in the type's class or Variable.java, or
other code. The switch-arm parser is shared with the @ statements.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Patryk Gensch
2026-10-24 20:30:36 +02:00
co-authored by Claude Opus 5.5
parent 9d5a600d6b
commit aee8f17417
9 changed files with 198 additions and 25 deletions
+41
View File
@@ -313,3 +313,44 @@ def test_events_per_type_and_emulator_signal_literals(tmp_path):
"ONCHANGED": "emitted"}
assert [e["name"] for e in typ(result, "STRING")["events"]] == ["ONCHANGED"] # via CMC_Variable
assert result["summary"]["event_status"]["not_found"] >= 1
def test_fields_per_type_and_emulator_property_literals(tmp_path):
root = tmp_path
variables = root / "core/src/pl/genschu/bloomooemulator/interpreter/variable"
variables.mkdir(parents=True)
(variables / "Variable.java").write_text(
'interface Variable { void r(Context c) { c.getAttributeInHierarchy(name(), "TOINI"); } }')
(variables / "TextVariable.java").write_text('''record TextVariable() {
VariableType type() { return VariableType.TEXT; }
void load(Context context) { context.attributes().get(name, "RECT"); log("FONT"); }
}''')
loader = root / "core/src/pl/genschu/bloomooemulator/loader"
loader.mkdir(parents=True)
(loader / "CNVParser.java").write_text('''class CNVParser {
private Variable createVariable(String type, String objectName, Map<String, String> properties) {
return switch (type) {
case "TIMER" -> new TimerVariable(properties.get(objectName + ":ELAPSE"));
case "INTEGER", "INT" -> make(properties.get(objectName + ":VALUE"));
default -> null;
};
}
void other(String n, Map<String, String> p) { p.get(n + ":PRIORITY"); }
}''')
emu = scan_emulator(root)
props = {scope: sorted(v) for scope, v in emu["properties"].items()}
assert props == {"*": ["TOINI"], "TEXT": ["RECT"], "TIMER": ["ELAPSE"], "INTEGER": ["VALUE"],
"engine": ["PRIORITY"]}
snap = Snapshot({"binary": {"name": "p8.dll", "sha256": SHA},
"types": [{"script_name": "TEXT", "cpp_class": "CMC_Text"}, {"script_name": "INTEGER", "cpp_class": None}],
"type_fields": [{"type": "TEXT", "name": n, "value_types": ["string"], "order": i}
for i, n in enumerate(["RECT", "FONT", "PRIORITY"])],
"fields": [{"owner": "CMC_Variable", "name": "TOINI", "type": "bool", "order": 0},
{"owner": "CMC_Integer", "name": "VALUE", "type": "int", "order": 0}],
"field_inheritance": [{"class": "CMC_Integer", "base_class": "CMC_Variable"}]})
result = build_tracker([snap], emu)
assert {f["name"]: f["status"] for f in typ(result, "TEXT")["fields"]} == {
"RECT": "read", "FONT": "not_found", "PRIORITY": "engine_literal"}
integer = {f["name"]: f for f in typ(result, "INTEGER")["fields"]} # class chain, base first
assert [f["name"] for f in typ(result, "INTEGER")["fields"]] == ["TOINI", "VALUE"]
assert integer["TOINI"]["status"] == "read_base" and integer["VALUE"]["value_types"] == ["int"]