srdatalog.ir.hir.emit

Canonical JSON emitter for HIR, matching src/srdatalog/hir/json_printer.nim output byte-for-byte (minus the hirSExpr debug field).

Strategy:

  • Build a dict tree that matches the key ordering json_printer emits.

  • Serialize with json.dumps(indent=2, ensure_ascii=False); tests compare after structural canonicalization so field order matters but pretty-print formatting does not.

The hirSExpr field is intentionally skipped: it’s a debug text that Nim produces for VSCode display, and reproducing it in Python adds surface area with no verification value. Tests strip it from the golden fixture before comparing.

Module Contents

Functions

emit_hir_json

Emit canonical JSON string.

hir_to_obj

Build the canonical dict tree for a HirProgram. Does not include hirSExpr (strip that from the Nim fixture when comparing).

API

srdatalog.ir.hir.emit.emit_hir_json(prog: srdatalog.ir.hir.types.HirProgram) str[source]

Emit canonical JSON string.

srdatalog.ir.hir.emit.hir_to_obj(prog: srdatalog.ir.hir.types.HirProgram) dict[source]

Build the canonical dict tree for a HirProgram. Does not include hirSExpr (strip that from the Nim fixture when comparing).