tricu

A lazy functional language based on Tree Calculus
Log | Files | Refs | README | LICENSE

compiler_io_version.py (2816B)


      1 #!/usr/bin/env python3
      2 """Explicit compiler protocol selection, through the real CLI and retained compiler.
      3 
      4 This is a synthetic worker boundary control, not a rebuilt v2 compiler generation.
      5 """
      6 import argparse
      7 import json
      8 import subprocess
      9 from pathlib import Path
     10 from source_order import Runner
     11 
     12 
     13 def main():
     14     parser = argparse.ArgumentParser(description=__doc__)
     15     parser.add_argument('tricu', type=Path)
     16     parser.add_argument('--directory', type=Path, required=True)
     17     args = parser.parse_args()
     18     root = args.directory.resolve()
     19     root.mkdir(parents=True, exist_ok=False)
     20     runner = Runner(args.tricu, root)
     21     # No imports: explicitly construct the bare current-scope core action. The
     22     # returned scope token is deliberately not a compiler publication Result.
     23     worker = root/'worker.tri'
     24     worker.write_text('!export sourceBuildGraph\nsourceBuildGraph _ _ _ _ = t 4 t\n')
     25     bundle = root/'worker.arboricx'
     26     runner.run('compile-worker', ['compile','--file',worker,'--store',runner.store,'--output',bundle])
     27     pin = runner.imported(bundle, 'import-worker')
     28     source = root/'input.tri'
     29     source.write_text('!export main\nmain = 42\n')
     30     base = ['eval',str(source),'--store',str(root/'application')]
     31     selected = ['--toolchain',pin,'--tool-store',str(runner.store)]
     32     controls = []
     33     def check(label, options, expected, success=False):
     34         command = [str(runner.exe),*base,*options,'+RTS','-N1','-M256m','-RTS']
     35         completed = subprocess.run(command, capture_output=True, text=True, timeout=30)
     36         output = completed.stdout + completed.stderr
     37         assert (completed.returncode == 0) == success, (label, output)
     38         assert expected in output, (label,output)
     39         (root/f'{label}.log').write_text(output)
     40         controls.append(dict(label=label, command=command, returncode=completed.returncode))
     41     check('packaged-v2',['--format','number'],'42',True)
     42     check('v2-default',selected,'Invalid portable compiler Result')
     43     check('explicit-v1',[*selected,'--toolchain-io-version','1'],'IO v1 compilers require a retained v1 runtime')
     44     check('explicit-v2',[*selected,'--toolchain-io-version','2'],'Invalid portable compiler Result')
     45     for version in ['0','3','-1','01','+1','18446744073709551617']:
     46         check(f'invalid-version-{version}',[*selected,'--toolchain-io-version',version],
     47               '--toolchain-io-version must be 1 or 2')
     48     check('no-packaged-relabel',['--toolchain-io-version','1'],'IO v1 compilers require a retained v1 runtime')
     49     assert source.read_text() == '!export main\nmain = 42\n'
     50     (root/'report.json').write_text(json.dumps(dict(controls=controls, preparation=runner.records),indent=2)+'\n')
     51     print(f'{len(controls)} compiler IO-version CLI controls passed')
     52 
     53 if __name__ == '__main__':
     54     main()