tricu

An interpreted language for exploring Tree Calculus
Log | Files | Refs | README | LICENSE

scp_runtime_entrypoints.py (2051B)


      1 #!/usr/bin/env python3
      2 import json
      3 from pathlib import Path
      4 from research_session import ResearchSession
      5 import argparse
      6 parser=argparse.ArgumentParser(description='Haskell-only stored SCP file-adapter checks; no SCP compiler source build.')
      7 parser.add_argument('tricu',type=Path)
      8 parser.add_argument('generation',type=Path)
      9 parser.add_argument('prepared',type=Path)
     10 parser.add_argument('--directory',type=Path,required=True)
     11 args=parser.parse_args()
     12 s=ResearchSession(args.tricu,args.directory,[args.prepared],args.generation/'build.arboricx')
     13 r=json.loads((args.prepared/'migration.json').read_text());pins={x['legacy']:x['manifest'] for x in r}
     14 p=s.workspace/'probe.tri'
     15 p.write_text(f'''!import prelude *
     16 !import io *
     17 !import {pins['consumers.file']} as F
     18 !import {pins['consumers.file-effects']} as E
     19 !export *
     20 success path = F.program "probe" (_ : ok ["accepted"] t) path
     21 empty path = F.program "probe" (_ : ok [] t) path
     22 failure path = F.program "probe" (_ : err "bad input" t) path
     23 copy source target = (io (onResult_ (E.readBytes source)
     24   (problem : pure (err problem t))
     25   (bytes : E.writeBytesHandler (pair target bytes))))
     26 ''')
     27 b=s.root/'probe.arboricx';s.compile(p,['success','empty','failure','copy'],b)
     28 import re
     29 out,_=s.run([s.tricu,'arboricx','import','--file',b,'--store',s.store,'--indexed']);pin=re.search(rb'Created module alias .* -> ([0-9a-f]{64})',out)[1].decode()
     30 file=s.root/'input.bin';file.write_bytes(bytes([0,255,206,187,10,97]));missing=s.root/'missing';target=s.root/'copy.bin'
     31 for name,args,wanted in [('success',[file],b'probe=1\nfirst=accepted\n'),('empty',[file],b'probe=0\nfirst=<none>\n'),('failure',[file],b'failure-stage=consumer\nfailure-detail=bad input\n'),('success',[missing],b'failure-stage=read\n'),('copy',[file,target],b'')]:
     32  cmd=[s.tricu,'arboricx','run','--store',s.store,'--module',pin,'--name',name,'--io','--unsafe-io','--format','tree']
     33  for a in args:cmd+=['--arg',str(a)]
     34  out,_=s.run(cmd,30);assert wanted in out,(name,out);print(name,'passed')
     35 assert target.read_bytes()==file.read_bytes()