interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / tests / universal / c_import_preproc_controls.py

34 lines · 2208 bytes Raw Blame History
1#!/usr/bin/env python3
2"""Exact-code controls for extra C preprocessing (c-u64-import-v1: refusal 72).
3
4Added after the #623 re-validation at c6316d4b found `#define`/`#include`/`#if` refused with 66
5and `#pragma` with 69. Kept separate from the frozen c_import_controls.py, which the G1 validator pins.
6"""
7from pathlib import Path
8import argparse,json,subprocess
9ROOT=Path(__file__).resolve().parents[2]
10HEADER='#include <stdint.h>\n'
11ap=argparse.ArgumentParser();ap.add_argument('--importer',required=True);ap.add_argument('--out',required=True);a=ap.parse_args()
12out=Path(a.out).resolve();out.mkdir(parents=True,exist_ok=False);exe=Path(a.importer).resolve()
13refuse=[('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')]
19accept=[('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')]
21checks=[]
22for 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'})
26for 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')
31bad=[c for c in checks if c['result']!='PASS']
32for c in bad:print('FAIL',json.dumps(c))
33if bad:raise SystemExit(1)
34print('PASS preprocessing refusals=%d comment_hash_accepts=%d'%(len(refuse),len(accept)))