omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / tests / universal / c_import_preproc_controls.py
| 1 | #!/usr/bin/env python3 |
| 2 | """Exact-code controls for extra C preprocessing (c-u64-import-v1: refusal 72). |
| 3 | |
| 4 | Added after the #623 re-validation at c6316d4b found `#define`/`#include`/`#if` refused with 66 |
| 5 | and `#pragma` with 69. Kept separate from the frozen c_import_controls.py, which the G1 validator pins. |
| 6 | """ |
| 7 | from pathlib import Path |
| 8 | import argparse,json,subprocess |
| 9 | ROOT=Path(__file__).resolve().parents[2] |
| 10 | HEADER='#include <stdint.h>\n' |
| 11 | ap=argparse.ArgumentParser();ap.add_argument('--importer',required=True);ap.add_argument('--out',required=True);a=ap.parse_args() |
| 12 | out=Path(a.out).resolve();out.mkdir(parents=True,exist_ok=False);exe=Path(a.importer).resolve() |
| 13 | refuse=[('define','#define X 1ULL\nuint64_t calc(uint64_t a){return a+X;}\n'), |
| 14 | ('include','#include <stddef.h>\nuint64_t calc(uint64_t a){return a;}\n'), |
| 15 | ('if','#if 1\nuint64_t calc(uint64_t a){return a;}\n#endif\n'), |
| 16 | ('pragma','#pragma once\nuint64_t calc(uint64_t a){return a;}\n'), |
| 17 | ('body-directive','uint64_t calc(uint64_t a){\n#define Y 2\nreturn a;}\n'), |
| 18 | ('stringize-token','uint64_t calc(uint64_t a){return a # a;}\n')] |
| 19 | accept=[('hash-in-block-comment','/* #define X 1 */ uint64_t calc(uint64_t a){return a;}\n'), |
| 20 | ('hash-in-line-comment','uint64_t calc(uint64_t a){return a; // #pragma once\n}\n')] |
| 21 | checks=[] |
| 22 | for name,body in refuse: |
| 23 | r=subprocess.run([str(exe)],input=(HEADER+body).encode(),capture_output=True,timeout=10) |
| 24 | ok=r.returncode==72 and r.stdout==b'' and r.stderr==b'C_IMPORT_UNSUPPORTED_PREPROCESSOR\n' |
| 25 | checks.append({'name':name,'exit':r.returncode,'stderr':r.stderr.decode(errors='replace'),'result':'PASS' if ok else 'FAIL'}) |
| 26 | for name,body in accept: |
| 27 | r=subprocess.run([str(exe)],input=(HEADER+body).encode(),capture_output=True,timeout=10) |
| 28 | ok=r.returncode==0 and r.stdout[:5]==b'OMSB\x01' |
| 29 | checks.append({'name':name,'exit':r.returncode,'result':'PASS' if ok else 'FAIL'}) |
| 30 | (out/'preproc-controls.json').write_text(json.dumps(checks,indent=1)+'\n') |
| 31 | bad=[c for c in checks if c['result']!='PASS'] |
| 32 | for c in bad:print('FAIL',json.dumps(c)) |
| 33 | if bad:raise SystemExit(1) |
| 34 | print('PASS preprocessing refusals=%d comment_hash_accepts=%d'%(len(refuse),len(accept))) |