From 8ee5ca66b2f44bfcf182dee2ce5a17c99449a878 Mon Sep 17 00:00:00 2001 From: N0VAN0M4LY <224130499+N0VAN0M4LY@users.noreply.github.com> Date: Sat, 28 Nov 2026 14:13:14 +0800 Subject: [PATCH] Require confirmation of every Quirrel script compilation Pass the manifest path to the harness directly and require per-script success and a completion marker. The standalone interpreter can exit with status zero after a harness failure. Resolve merged interface exports and provide integer bindings for stock constant expressions. --- tools/src/wtotools/gui_check.py | 87 ++++++++++++++++++++++++++------- 1 file changed, 68 insertions(+), 19 deletions(-) diff --git a/tools/src/wtotools/gui_check.py b/tools/src/wtotools/gui_check.py index 0d099d2..f372952 100644 --- a/tools/src/wtotools/gui_check.py +++ b/tools/src/wtotools/gui_check.py @@ -3,11 +3,12 @@ `sq.exe --syntax-check` only runs `sq_parsetoast` and skips `CodeGenVisitor`, missing `Unknown variable`, forward references, and `Named binding name conflicts with existing constant/enum/import`. Driving `sq.exe` via `compilestring(src, chunkname, bindings)` -with the target script's real `gui.vromfs.bin` imports runs the full `SQParser` + -`CodeGenVisitor` pipeline without executing any game code. +with import names from the game archive and stand-ins for their values runs the full +parser and bytecode generator without executing any game code. """ from __future__ import annotations +import json import re import subprocess import tempfile @@ -61,6 +62,7 @@ let typeMap = { Integer = types.Integer Float = types.Float Bool = types.Bool + CtrlsInGui = __CONTROL_MASKS__ } function readText(p) { let f = io.file(p, "rb") @@ -68,9 +70,8 @@ function readText(p) { f.close() return s } -let manifestPath = __argv[0] +let manifestPath = __MANIFEST_PATH__ let lines = readText(manifestPath).split("\\n") -local failed = 0 foreach (line in lines) { let trimmed = line.strip() if (trimmed == "") @@ -81,20 +82,23 @@ foreach (line in lines) { let names = parts.len() > 2 && parts[2] != "" ? parts[2].split(",") : [] let classNames = parts.len() > 3 && parts[3] != "" ? parts[3].split(",") : [] let bindings = {} - foreach (n in names) - bindings[n] <- (n in typeMap) ? typeMap[n] : proxy + foreach (n in names) { + // These native imports need integer stand-ins for constant folding of masks and shifts. + let isNativeInteger = n.startswith("GT_") || n.startswith("OBJECTIVE_TYPE_") + let fallback = isNativeInteger ? 1 : proxy + bindings[n] <- (n in typeMap) ? typeMap[n] : fallback + } foreach (cn in classNames) bindings[cn] <- DummyClass let src = readText(filePath) try { compilestring(src, display, bindings) + print($"COMPILED {display}\\n") } catch (e) { print($"COMPILE_ERROR {display}: {e}\\n") - failed++ } } -if (failed > 0) - throw $"Quirrel bytecode check failed on {failed} file(s)" +print("COMPILATION_COMPLETE\\n") """ @@ -155,10 +159,9 @@ def verify_gui_patches( if errors: return GuiCheckReport(len(patches), 0, tuple(errors)) + export_cache.clear() with tempfile.TemporaryDirectory(prefix="wto-gui-check-") as tmp: tmp_dir = Path(tmp) - harness_path = tmp_dir / "harness.nut" - harness_path.write_text(HARNESS_SOURCE, encoding="utf-8") manifest_lines: list[str] = [] for index, rel_path in enumerate(touched_files): @@ -172,22 +175,53 @@ def verify_gui_patches( manifest_path = tmp_dir / "manifest.tsv" manifest_path.write_text("\n".join(manifest_lines), encoding="utf-8") + # The standalone interpreter does not expose __argv as a script binding. + harness_source = HARNESS_SOURCE.replace("__CONTROL_MASKS__", _control_masks_literal(stock_archive)) + harness_source = harness_source.replace("__MANIFEST_PATH__", json.dumps(manifest_path.as_posix(), ensure_ascii=False)) + harness_path = tmp_dir / "harness.nut" + harness_path.write_text(harness_source, encoding="utf-8") proc = subprocess.run( - [str(sq_exe), str(harness_path), str(manifest_path)], + [str(sq_exe), str(harness_path)], capture_output=True, text=True, encoding="utf-8", errors="replace", ) + # sq.exe can exit with status zero after a compile or runtime error in the harness. + confirmations = [ + line for line in proc.stdout.splitlines() + if line.startswith("COMPILED ") or line == "COMPILATION_COMPLETE" + ] + expected = [f"COMPILED {path}" for path in touched_files] + ["COMPILATION_COMPLETE"] + if confirmations != expected: + errors.append("Quirrel compiler did not confirm bytecode compilation for every modified script") if proc.returncode != 0: - out = (proc.stdout + "\n" + proc.stderr).strip() - for line in out.splitlines(): - if line.strip(): - errors.append(line.strip()) + errors.append(f"Quirrel compiler exited with status {proc.returncode}") + if errors: + errors.extend( + line.strip() for line in (proc.stdout + "\n" + proc.stderr).splitlines() + if line.strip() and line not in confirmations + ) return GuiCheckReport(len(patches), len(touched_files), tuple(errors)) +def _control_masks_literal(archive: Archive) -> str: + """Use the stock integer masks for constant expressions involving CtrlsInGui.""" + source = archive.files.get("globalscripts/sharedenums.nut", b"").decode("utf-8") + enum = re.search(r"\benum\s+CtrlsInGui\s*\{([^{}]*)\}", source) + if enum is None: + return "{}" + + fields = re.findall( + r"^[ \t]*([A-Za-z_][A-Za-z0-9_]*)[ \t]*=[ \t]*" + r"(0x[0-9a-fA-F]+|[0-9]+)[ \t]*,?[ \t]*(?://[^\r\n]*)?\r?$", + enum[1], + re.MULTILINE, + ) + return "{ " + ", ".join(f"{name} = {value}" for name, value in fields) + " }" + + def _resolve_vromfs_path(spec: str) -> str | None: for prefix, target in MOUNT_PREFIXES: if spec.startswith(prefix): @@ -235,11 +269,24 @@ def _exports_of_module(spec: str, archive: Archive, cache: dict[str, set[str]], keys |= _exports_of_module("%scripts/sqDagui/daguiNativeApi.nut", archive, cache, native_syms) keys |= _exports_of_module("%globalScripts/sharedEnums.nut", archive, cache, native_syms) + if vpath == "scripts/sqdagui/daguinativeapi.nut": + # Its return table merges the native daguiScene exports. The cursor helper is + # only used through wildcard imports, so it cannot be found in the named imports. + keys.update(native_syms.get("daguiScene", set())) + keys.add("get_dagui_mouse_cursor_pos_RC") + for arr_match in re.finditer(r"let\s+fields\s*=\s*\[(.*?)\]", text, re.DOTALL): for s_match in re.finditer(r'"([A-Za-z_][A-Za-z0-9_]*)"', arr_match.group(1)): keys.add(s_match.group(1)) - for ret_match in re.finditer(r"return\s+(?:freeze\s*\(\s*)?\{([^{}]*(?:\{[^{}]*\}[^{}]*)*)\}", text, re.DOTALL): + # Stock modules also return inline tables and merge a final table into other exports. + returned_table = re.compile( + r"\breturn\s*\(?\s*(?:freeze\s*\(\s*)?" + r"(?:[A-Za-z_]\w*\.__merge\(\s*(?:[A-Za-z_]\w*\s*,\s*)+)?" + r"\{([^{}]*(?:\{[^{}]*\}[^{}]*)*)\}", + re.DOTALL, + ) + for ret_match in returned_table.finditer(text): body = ret_match.group(1) for line in body.splitlines(): stripped = line.strip().rstrip(",") @@ -248,8 +295,10 @@ def _exports_of_module(spec: str, archive: Archive, cache: dict[str, set[str]], m_assign = re.match(r"^([A-Za-z_][A-Za-z0-9_]*)\s*=", stripped) if m_assign: keys.add(m_assign.group(1)) - elif stripped.isidentifier(): - keys.add(stripped) + else: + fields = [field.strip() for field in stripped.split(",")] + if all(field.isidentifier() for field in fields): + keys.update(fields) for m_slot in re.finditer(r'\b(?:export|res)\s*(?:\.\s*([A-Za-z_][A-Za-z0-9_]*)|\[\s*"([A-Za-z_][A-Za-z0-9_]*)"\s*\])\s*<-', text): keys.add(m_slot.group(1) or m_slot.group(2))