feat(tracker): map script types through runner_map

Types follow CMC_RunnerFactory when the snapshot has it, so the shared
variable runner no longer forms a VARIABLE pseudo-type. Base CMC_Runner
verbs are listed once under * and referenced via inherits; type 0 becomes
the @ scope, matched against CodeParser.dispatchSpecialCall.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Patryk Gensch
2026-10-24 18:37:17 +02:00
co-authored by Claude Opus 5.5
parent 5c597a3a52
commit 87fcefa877
3 changed files with 185 additions and 33 deletions
+74 -3
View File
@@ -72,9 +72,80 @@ def test_inheritance_aliases_and_globals_are_not_implementation_proof(tmp_path):
assert row(result)["verification"] == "unverified"
assert row(result)["original"][0]["owner"] == "CMC_Bool"
assert len(row(result)["original"]) == 1 # child wins over SET on base
assert row(result, method="CLONE")["source"]["owner"] == "*"
assert row(result, method="CLONE")["original"][0]["inherited"]
assert next(t for t in result["types"] if t["name"] == "UNKNOWN")["methods"] == []
assert row(result, "*", "CLONE")["source"]["owner"] == "*"
assert not row(result, "*", "CLONE")["original"][0]["inherited"]
assert typ(result, "BOOLEAN")["inherits"] == ["*"]
assert "CLONE" not in {m["name"] for m in typ(result, "BOOLEAN")["methods"]} # listed once, under *
assert typ(result, "UNKNOWN")["methods"] == []
def factory_snapshot():
"""Piklib 8 shape: five variable types share one runner, VECTOR's runner has no symbol."""
return Snapshot({"binary": {"name": "p8.dll", "sha256": SHA},
"types": [{"script_name": "INTEGER", "cpp_class": "CMC_Integer", "type_id": 1},
{"script_name": "STRING", "cpp_class": "CMC_String", "type_id": 2},
{"script_name": "VECTOR", "cpp_class": None, "type_id": 0x7e0}],
"methods": [{"owner": "CMC_Variable", "runner": "CMC_Variable_Runner", "name": "ADD", "id": 6},
{"owner": "CMC_Vector", "runner": "CMC_Vector_Runner", "name": "NORMALIZE", "id": 8},
{"owner": "CMC_Dummy", "runner": "CMC_Dummy_Runner", "name": "IF", "id": 1},
{"owner": "CMC_Dummy", "runner": "CMC_Dummy_Runner", "name": "MSGBOX", "id": 6},
{"owner": "CMC", "runner": "CMC_Runner", "name": "CLONE", "id": 100}],
"method_inheritance": [{"runner": "CMC_Variable_Runner", "base_runner": "CMC_Runner"},
{"runner": "CMC_Vector_Runner", "base_runner": "CMC_Runner"}],
"runner_map": {"by_type_id": [{"type_id": 0, "runner": "CMC_Dummy_Runner"},
{"type_id": 1, "runner": "CMC_Variable_Runner"},
{"type_id": 2, "runner": "CMC_Variable_Runner"},
{"type_id": 0x7e0, "runner": "CMC_Vector_Runner"}]}})
def typ(result, name):
return next(t for t in result["types"] if t["name"] == name)
def test_runner_factory_maps_shared_and_unnamed_runners(tmp_path):
result = build_tracker([factory_snapshot()], emulator(tmp_path))
names = {t["name"] for t in result["types"]}
assert {"INTEGER", "STRING", "VECTOR", "@", "*"} <= names
assert not {"VARIABLE", "VECTOR_RUNNER", "DUMMY"} & names # no pseudo-types from runner classes
for name in ("INTEGER", "STRING"):
add = row(result, name, "ADD")["original"][0]
assert (add["owner"], add["mapping"], add["inherited"]) == ("CMC_Variable", "runner_factory", False)
assert any("Wspólny runner CMC_Variable_Runner" in n for n in typ(result, name)["mapping_notes"])
assert row(result, "VECTOR", "NORMALIZE")["original"]
assert {m["name"] for m in typ(result, "@")["methods"]} == {"IF", "MSGBOX"}
assert "inherits" not in typ(result, "@") # built-ins do not chain to CMC_Runner
def test_builtin_statements_are_read_from_the_parser(tmp_path):
parser = tmp_path / "core/src/pl/genschu/bloomooemulator/interpreter/parser"
parser.mkdir(parents=True)
(parser / "CodeParser.java").write_text('''class CodeParser {
private static ASTNode dispatchSpecialCall(String name, SourceSpan argsText) {
return switch (name) {
case "INT", "BOOL" -> new VarDefNode(name);
case "IF" -> buildIf(args); // "case" in a comment: "FAKE" ->
case "FOR" -> throw new ParseException("@FOR not implemented yet", location);
default -> throw new ParseException("Unknown special call: @" + name, location);
};
}
}''')
emu = emulator(tmp_path)
builtins = emu["types"]["@"]["methods"]
assert set(builtins) == {"INT", "BOOL", "IF", "FOR"}
assert builtins["FOR"]["status"] == "stub_candidate"
assert builtins["IF"]["status"] == "registered"
result = build_tracker([factory_snapshot()], emu)
assert row(result, "@", "IF")["status"] == "registered"
assert row(result, "@", "MSGBOX")["status"] == "missing"
def test_local_registration_of_a_base_verb_is_flagged(tmp_path):
snap = factory_snapshot()
emu = emulator(tmp_path)
emu["types"]["STRING"] = {"mapping_notes": [], "methods": {
"CLONE": {"status": "registered", "notes": [], "source": {"owner": "STRING"}}}}
result = build_tracker([snap], emu)
assert any("metoda bazowa (*)" in n for n in row(result, "STRING", "CLONE")["notes"])
def test_unknown_hash_not_fabricated_and_method_ids_are_binary_local(tmp_path):