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 / src / allen / allen_core.om

76 lines · 1726 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note Pure seeded OM-2 helpers backing src/allen/allen_bind.c:
3note lineage validation, LE u64 intent-id unpack, and hex encode/decode.
4om2
5
6fn allen_hex_nib v ulong to uchar
7 if lt v 10
8 ret uchar add 48 v
9 end
10 ret uchar add 87 v
11end
12
13fn allen_unhex_char c ulong to long
14 if and ge c 48 le c 57
15 ret long sub c 48
16 end
17 if and ge c 97 le c 102
18 ret long add sub c 97 10
19 end
20 if and ge c 65 le c 70
21 ret long add sub c 65 10
22 end
23 ret -1
24end
25
26export fn allen_encode_hex src view uchar * out_hex edit uchar * to void
27requires eq len out_hex mul len src 2
28 for i ulong len src
29 b = ulong get src i
30 put out_hex mul i 2 allen_hex_nib shr b 4
31 put out_hex add mul i 2 1 allen_hex_nib and b 15
32 end
33end
34
35export fn allen_decode_hex in_hex view uchar * out_bytes edit uchar * to ulong
36requires eq len in_hex mul len out_bytes 2
37 for i ulong len out_bytes
38 hi = allen_unhex_char ulong get in_hex mul i 2
39 lo = allen_unhex_char ulong get in_hex add mul i 2 1
40 if or lt hi 0 lt lo 0
41 ret 0
42 end
43 put out_bytes i uchar or shl ulong hi 4 ulong lo
44 end
45 ret 1
46end
47
48note Return 0 if valid, -1 if cortex is all-zero, -2 if no genesis, -3 if mismatch.
49export fn allen_check_lineage cortex view uchar 32 genesis view uchar 32 has_genesis ulong to long
50 any_nz = ulong 0
51 for i ulong 32
52 if ne get cortex i 0
53 any_nz = 1
54 end
55 end
56 if eq any_nz 0
57 ret -1
58 end
59 if eq has_genesis 0
60 ret -2
61 end
62 for i ulong 32
63 if ne get cortex i get genesis i
64 ret -3
65 end
66 end
67 ret 0
68end
69
70export fn allen_le64 id view uchar 8 to ulong
71 v = ulong 0
72 for i ulong 8
73 v = or v shl ulong get id i mul i 8
74 end
75 ret v
76end