Examples · Export
export_cobol
Emit a COBOL program and read the integer arithmetic it performs. CI compiles the same program with GnuCOBOL and drives it with test rows.
Code#
export_cobol.py
from _setup import artifact from compileml.export import export_cobol cob = export_cobol(artifact, program_id="CMLSCORE")lines = cob.splitlines() print(f"generated {len(lines)} lines of COBOL")print()print("\n".join(lines[:16]))print("…") # The integer accumulation the spec describes, emitted verbatim.adds = [line for line in lines if "TO F-ACCUM-MICRO" in line]print()print(f"{len(adds)} integer ADD statements, e.g.:")for line in adds[:3]: print(" ", line.strip())Output#
Captured from an actual run against compileml 0.9.0 and the UCI credit panel. If this script stops working, the build fails.
captured in CIexport_cobol.py
generated 1088 lines of COBOL >>SOURCE FORMAT FREEIDENTIFICATION DIVISION.PROGRAM-ID. CMLSCORE.*> ------------------------------------------------------------*> CompileML decision artifact export (score + band + PD).*> artifact_hash: a31afc9bf476ce94714946a120a525f5b0049dcfe1461e4abf6c01cde434e66c*> micro_scale: 1000000 display scale: 1000*> Integer-exact: leaf values below are the artifact's integers.*> ------------------------------------------------------------DATA DIVISION.WORKING-STORAGE SECTION.01 F-ACCUM-MICRO PIC S9(15) COMP-5 VALUE 0.01 F-LATENT-MICRO PIC S9(15) COMP-5 VALUE 0.01 F-LATENT-INT PIC S9(9) COMP-5 VALUE 0.01 FINAL-BAND PIC X(3) VALUE SPACES.01 F-PD-STEP PIC S9(9) COMP-5 VALUE 0.… 73 integer ADD statements, e.g.: MOVE 221926 TO F-ACCUM-MICRO ADD 38890 TO F-ACCUM-MICRO ADD 49014 TO F-ACCUM-MICRONotes#
- driver_rows embeds a self-checking harness, which is how CI compares the mainframe path to the reference runtime.
- Default scope: score, band and calibrated PD. explain=True adds reason codes and display-scale integer impacts; message text is looked up from the reason dictionary outside COBOL.
- explain=True refuses an artifact whose attribution is not exact (EXPLAIN_NOT_EXACT), or whose reason codes are not printable ASCII (REASON_CODE_NOT_ASCII).