(args: list[str], output: TextIO)
| 458 | |
| 459 | |
| 460 | def generate(args: list[str], output: TextIO) -> None: |
| 461 | printer = Printer(output) |
| 462 | for arg in args: |
| 463 | file, modname = arg.rsplit(':', 1) |
| 464 | with open(file, "r", encoding="utf8") as fd: |
| 465 | source = fd.read() |
| 466 | if is_frozen_header(source): |
| 467 | code = decode_frozen_data(source) |
| 468 | else: |
| 469 | code = compile(fd.read(), f"<frozen {modname}>", "exec") |
| 470 | printer.generate_file(modname, code) |
| 471 | with printer.block(f"void\n_Py_Deepfreeze_Fini(void)"): |
| 472 | for p in printer.deallocs: |
| 473 | printer.write(p) |
| 474 | with printer.block(f"int\n_Py_Deepfreeze_Init(void)"): |
| 475 | for p in printer.interns: |
| 476 | with printer.block(f"if ({p} < 0)"): |
| 477 | printer.write("return -1;") |
| 478 | printer.write("return 0;") |
| 479 | if verbose: |
| 480 | print(f"Cache hits: {printer.hits}, misses: {printer.misses}") |
| 481 | |
| 482 | |
| 483 | parser = argparse.ArgumentParser() |
no test coverage detected