From 675e209f5e838c33221985bbef4162e23741d202 Mon Sep 17 00:00:00 2001 From: Zaggy1024 Date: Wed, 29 Apr 2026 21:20:47 -0500 Subject: [PATCH] Meta: Simplify tracking the current op in libjs_bytecode_def.py The the presence of a value in the Optional[OpDef] already indicated whether the loop was in an op. The `in_op` variable was decoupling the check for a current op from the usage of the current op, so type checking couldn't determine that None was impossible where it was used. --- Meta/Generators/libjs_bytecode_def.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/Meta/Generators/libjs_bytecode_def.py b/Meta/Generators/libjs_bytecode_def.py index 0a3c9574cd..0fcb8bef24 100644 --- a/Meta/Generators/libjs_bytecode_def.py +++ b/Meta/Generators/libjs_bytecode_def.py @@ -28,8 +28,7 @@ def parse_bytecode_def(path: str) -> List[OpDef]: lines = f.readlines() ops: List[OpDef] = [] - current: Optional[OpDef] = None - in_op = False + current_op: Optional[OpDef] = None for raw_line in lines: stripped = raw_line.strip() @@ -39,9 +38,8 @@ def parse_bytecode_def(path: str) -> List[OpDef]: continue if stripped.startswith("op "): - if in_op: + if current_op is not None: raise RuntimeError("Nested op blocks are not allowed") - in_op = True rest = stripped[len("op ") :].strip() if "<" in rest: @@ -52,25 +50,24 @@ def parse_bytecode_def(path: str) -> List[OpDef]: name = rest.strip() base = "Instruction" - current = OpDef(name=name, base=base) + current_op = OpDef(name=name, base=base) continue if stripped == "endop": - if not in_op or current is None: + if current_op is None: raise RuntimeError("endop without corresponding op") - ops.append(current) - current = None - in_op = False + ops.append(current_op) + current_op = None continue - if not in_op: + if current_op is None: continue if stripped.startswith("@"): if stripped == "@terminator": - current.is_terminator = True + current_op.is_terminator = True elif stripped == "@nothrow": - current.is_nothrow = True + current_op.is_nothrow = True continue if ":" not in stripped: @@ -82,9 +79,9 @@ def parse_bytecode_def(path: str) -> List[OpDef]: if field_type.endswith("[]"): is_array = True field_type = field_type[:-2].strip() - current.fields.append(Field(name=field_name, type=field_type, is_array=is_array)) + current_op.fields.append(Field(name=field_name, type=field_type, is_array=is_array)) - if in_op or current is not None: + if current_op is not None: raise RuntimeError("Unclosed op block at end of file") return ops