feat: type_events in diff and tracker, joined with emulator signal literals

Diff gains a type_events axis keyed by (script type, event). The tracker
lists each type's original events (vftable list, or the nearest class
list up the constructor chain for Piklib 6.1) and where the emulator names
them: the type's class, Variable.java or other engine code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Patryk Gensch
2026-10-24 19:49:26 +02:00
co-authored by Claude Opus 5.5
parent cb03de47ac
commit 597733d8d7
9 changed files with 135 additions and 7 deletions
+11
View File
@@ -128,3 +128,14 @@ def test_golden_pair_piklib_to_bloomoo():
disp_new = {(r["owner"], r["id"]): r for r in new.method_dispatch}
assert disp_old[("CMC_Animo", 1)]["calls"][-1] == "vtbl+0xa0"
assert disp_new[("CMC_Animo", 1)]["calls"][-1] == "vtbl+0xa0"
def test_type_events_diff_by_script_type():
from ams.diff import compute_diff, filter_by_owner
from ams.snapshot import Snapshot
old = Snapshot({"type_events": [{"type": "MOVIE", "name": "ONSTARTED", "order": 3}]})
new = Snapshot({"type_events": [{"type": "MOVIE", "name": "ONSTARTED", "order": 3},
{"type": "MOVIE", "name": "ONFRAMEUPDATED", "order": 5}]})
block = compute_diff(old, new)["type_events"]
assert [e["name"] for e in block["added"]] == ["ONFRAMEUPDATED"] and not block["removed"]
assert filter_by_owner(compute_diff(old, new), "MOVIE")["type_events"]["added"]
+32
View File
@@ -281,3 +281,35 @@ def test_class_constructor_runners_map_piklib61_types(tmp_path):
assert row(result, "CONDITION", "CHECK")["original"]
assert "RUN" not in {m["name"] for m in typ(result, "INTEGER")["methods"]}
assert not {"VARIABLE", "BASICCONDITION"} & {t["name"] for t in result["types"]}
def test_events_per_type_and_emulator_signal_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 s() { emit("ONSIGNAL"); } }')
(variables / "IntegerVariable.java").write_text('''record IntegerVariable() {
VariableType type() { return VariableType.INTEGER; }
void set() { emitSignal("ONCHANGED"); } // emitSignal("ONDONE") in a comment does not count
}''')
engine = root / "core/src/pl/genschu/bloomooemulator/engine"
engine.mkdir(parents=True)
(engine / "Game.java").write_text('class Game { void tick() { emit("ONINIT"); } }')
emu = scan_emulator(root)
assert emu["signals"] == {
"*": {"ONSIGNAL": [{"path": "core/src/pl/genschu/bloomooemulator/interpreter/variable/Variable.java", "line": 1}]},
"INTEGER": {"ONCHANGED": [{"path": "core/src/pl/genschu/bloomooemulator/interpreter/variable/IntegerVariable.java", "line": 3}]},
"engine": {"ONINIT": [{"path": "core/src/pl/genschu/bloomooemulator/engine/Game.java", "line": 1}]}}
vftable = factory_snapshot()
vftable.raw["type_events"] = [{"type": "INTEGER", "name": n, "order": i}
for i, n in enumerate(["ONINIT", "ONDONE", "ONSIGNAL", "ONCHANGED"])]
classes = Snapshot({"binary": {"name": "p61.dll", "sha256": "b" * 64},
"types": [{"script_name": "STRING", "cpp_class": None}],
"events": [{"owner": "CMC_Variable", "name": "ONCHANGED", "order": 0}],
"field_inheritance": [{"class": "CMC_String", "base_class": "CMC_Variable"}]})
result = build_tracker([vftable, classes], emu)
status = {e["name"]: e["status"] for e in typ(result, "INTEGER")["events"]}
assert status == {"ONINIT": "engine_literal", "ONDONE": "not_found", "ONSIGNAL": "emitted_base",
"ONCHANGED": "emitted"}
assert [e["name"] for e in typ(result, "STRING")["events"]] == ["ONCHANGED"] # via CMC_Variable
assert result["summary"]["event_status"]["not_found"] >= 1