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 / seed / omc / sites / hunt.py

80 lines · 3959 bytes Raw Blame History
1# hunt.py REPO SITES_TSV OUT: one-token mutations of small accepted programs; keep each one that reaches
2# an unreached omc error site (proved by that site's mutant compiler exiting 97). Test harness only (python3 -I),
3# never part of an Omega build. SEEDS=DIR seeds from DIR instead of the tracked programs (how the IR-mode
4# fixtures were found: tests/one_layer/omegese/dev/*.omegese with an "ir" line first, plus two small IR
5# programs). SITES_TSV is seed/omc/sitecov.sh's build/seed/sitecov/sites.tsv. Found
6# files still need a refuse line in sites.cases and a sitecov.sh rerun; target lines must stay first.
7import os, subprocess, sys, random
8from concurrent.futures import ThreadPoolExecutor
9repo, sites_tsv, out = sys.argv[1:4]
10omc = os.path.join(repo, "seed/out/omc")
11src = open(os.path.join(repo, "seed/omc/omc.om")).read().split("\n")
12mdir = os.path.join(out, "m"); os.makedirs(mdir, exist_ok=True)
13un = {}
14for row in open(sites_tsv):
15 ln, fn, w, code, by = row.rstrip("\n").split("\t")
16 if by == "-":
17 un.setdefault(int(code), []).append(int(ln))
18def build(ln):
19 p = os.path.join(mdir, str(ln))
20 if not os.path.exists(p):
21 s = list(src); w = s[ln - 1].split()[0]; s[ln - 1] = w + " 97"
22 r = subprocess.run([omc], input="\n".join(s).encode(), capture_output=True)
23 open(p, "wb").write(r.stdout); os.chmod(p, 0o755)
24 return p
25with ThreadPoolExecutor(8) as ex:
26 list(ex.map(build, [l for v in un.values() for l in v]))
27def run(exe, data):
28 try:
29 return subprocess.run([exe], input=data, capture_output=True, timeout=5).returncode
30 except subprocess.TimeoutExpired:
31 return -1
32seeds = []
33sd = os.environ.get("SEEDS") # optional directory of seed programs, e.g. the dev IR programs with "ir" first
34names = sorted(os.path.join(sd, f) for f in os.listdir(sd)) if sd else \
35 subprocess.run(["git", "-C", repo, "ls-files", "*.om"], capture_output=True, text=True).stdout.split()
36for f in names:
37 t = open(os.path.join(repo, f), "rb").read()
38 if (sd or t.count(b"\n") <= 40) and run(omc, t) == 0: # a SEEDS directory is taken whole
39 seeds.append((f, t.decode("utf-8", "replace")))
40vocab = "ulong long uchar uint bool f64 f32 int 0 1 -1 255 256 65536 4294967296 1.5f64 1.5f32 \"a\" x a b s if end ret get put len new seal open view edit add sub eq lt not neg min max and shl rotr part fork trap 5 9999999 abcdefghij".split()
41if sd: # the IR-mode search also used these words and 20 picks per token
42 vocab = "short ushort not xor or mul div rem shr for while bound true false g f y z 100 1000 15 64".split() + vocab
43k = 20 if sd else 12
44rnd = random.Random(20261108)
45found = {}
46print("seeds", len(seeds), "unreached", sum(len(v) for v in un.values()), flush=True)
47def cands():
48 for f, t in seeds:
49 lines = t.split("\n")
50 for i, l in enumerate(lines):
51 toks = l.split(" ")
52 if not l.strip() or toks[0] == "note":
53 continue
54 for j in range(len(toks)):
55 for v in rnd.sample(vocab, k):
56 nt = list(toks); nt[j] = v
57 nl = list(lines); nl[i] = " ".join(nt)
58 yield f, "\n".join(nl).encode()
59 nl = list(lines); nl[i] = " ".join(toks[:j]); yield f, "\n".join(nl).encode()
60def test(c):
61 f, data = c
62 rc = run(omc, data)
63 if rc not in un:
64 return None
65 for ln in un[rc]:
66 if ln in found:
67 continue
68 if run(os.path.join(mdir, str(ln)), data) == 97:
69 return ln, rc, f, data
70 return None
71n = 0
72with ThreadPoolExecutor(8) as ex:
73 for r in ex.map(test, cands(), chunksize=64):
74 n += 1
75 if r and r[0] not in found:
76 ln, rc, f, data = r
77 found[ln] = 1
78 open(os.path.join(out, "h%d-c%d.om" % (ln, rc)), "wb").write(data)
79 print("site", ln, "code", rc, "from", f, flush=True)
80print("candidates", n, "found", len(found))