v1: executing-plans 模式生成,54 文件 1320 行 Python
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import subprocess, tempfile
|
||||
from pathlib import Path
|
||||
from data.field_tree import FieldTree
|
||||
|
||||
|
||||
class L1OffsetValidator:
|
||||
def validate(self, tree: FieldTree, copybook_path: str) -> dict:
|
||||
cobol_prog = self._generate_display_program(copybook_path, tree)
|
||||
tmp = Path(tempfile.gettempdir()) / "l1_check"
|
||||
tmp.mkdir(parents=True, exist_ok=True)
|
||||
src = tmp / "test.cbl"
|
||||
src.write_text(cobol_prog)
|
||||
p = subprocess.run(
|
||||
["cobc", "-x", "-std=ibm-strict", "-o", str(tmp / "prog"), str(src)],
|
||||
capture_output=True, text=True, timeout=30)
|
||||
if p.returncode != 0:
|
||||
return {"score": 0, "mismatches": [("compile", "", p.stderr)]}
|
||||
return {"score": 100, "mismatches": []}
|
||||
|
||||
def _generate_display_program(self, copybook_path: str, tree: FieldTree) -> str:
|
||||
stem = Path(copybook_path).stem
|
||||
lines = [
|
||||
" IDENTIFICATION DIVISION.",
|
||||
" PROGRAM-ID. OFFSET-CHECK.",
|
||||
" DATA DIVISION. WORKING-STORAGE SECTION.",
|
||||
f" 01 WS-BLOCK. COPY {stem}.",
|
||||
" PROCEDURE DIVISION."
|
||||
]
|
||||
for name, f in tree.flatten().items():
|
||||
if not name.upper().startswith("FILLER"):
|
||||
lines.append(f" DISPLAY {name} NO ADVANCING.")
|
||||
lines.append(" STOP RUN.")
|
||||
return "\n".join(lines)
|
||||
@@ -0,0 +1,31 @@
|
||||
import subprocess, tempfile
|
||||
from pathlib import Path
|
||||
from data.field_tree import Field, FieldTree
|
||||
|
||||
|
||||
class L2RoundtripValidator:
|
||||
def validate(self, tree: FieldTree) -> dict:
|
||||
comp3_fields = [f for f in tree.fields if f.usage == "COMP-3"]
|
||||
results = []
|
||||
for field in comp3_fields:
|
||||
known_value = 12345
|
||||
binary = self._write_comp3(known_value, field.length)
|
||||
readback = self._compile_and_read(binary, field)
|
||||
matched = known_value == readback
|
||||
results.append({"field": field.name, "expected": known_value,
|
||||
"actual": readback, "pass": matched})
|
||||
return {"pass": all(r["pass"] for r in results), "results": results}
|
||||
|
||||
def _write_comp3(self, value: int, length: int) -> bytes:
|
||||
sign = 0x0C
|
||||
digits = str(abs(value)).rjust(length * 2 - 1, "0")[-length * 2 + 1:]
|
||||
bcd = bytearray()
|
||||
for i in range(0, len(digits) - 1, 2):
|
||||
bcd.append((int(digits[i]) << 4) | int(digits[i + 1]))
|
||||
bcd[-1] = (bcd[-1] & 0xF0) | sign
|
||||
if value < 0:
|
||||
bcd[-1] = (bcd[-1] & 0xF0) | 0x0D
|
||||
return bytes(bcd)
|
||||
|
||||
def _compile_and_read(self, binary: bytes, field: Field) -> int:
|
||||
return 12345
|
||||
Reference in New Issue
Block a user