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 / om / visor / validate_om2.om

146 lines · 3318 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note Pure seeded OM-2 semantic graph validation & iterative cycle detector backing src/omega_validate.c.
3om2
4
5export fn om_val_kind kind ulong to long
6 if or eq kind 0 gt kind 11
7 ret -1
8 end
9 ret 0
10end
11
12export fn om_val_rel_kind kind ulong to long
13 if or eq kind 0 gt kind 9
14 ret -1
15 end
16 ret 0
17end
18
19export fn om_val_const_kind kind ulong to long
20 if or eq kind 0 gt kind 9
21 ret -1
22 end
23 ret 0
24end
25
26note Validate TypePayload fields: 0 OK, 1 invalid tag, 2 uint width, 3 sint width, 4 fp32 width, 5 bv width, 6 seq len.
27export fn om_val_type_fields tag ulong width ulong slen ulong to long
28 if or eq tag 0 gt tag 14
29 ret 1
30 end
31 if eq tag 3
32 if or lt width 1 gt width 256
33 ret 2
34 end
35 end
36 if eq tag 4
37 if or lt width 2 gt width 256
38 ret 3
39 end
40 end
41 if eq tag 14
42 if ne width 32
43 ret 4
44 end
45 end
46 if eq tag 5
47 if or lt width 1 gt width 256
48 ret 5
49 end
50 end
51 if eq tag 7
52 if gt slen 65535
53 ret 6
54 end
55 end
56 ret 0
57end
58
59note Validate ValuePayload blen against integer/bitvector type width. Returns 0 OK, or expected bytes > 0 on mismatch.
60export fn om_val_val_bytes tag ulong width ulong blen ulong to long
61 if or eq tag 3 or eq tag 4 eq tag 5
62 exp = div add width 7 8
63 if ne blen exp
64 ret long exp
65 end
66 end
67 ret 0
68end
69
70note Validate OperationPayload fields: 0 OK, 1 invalid opcode, 2 invalid overflow policy.
71export fn om_val_op_fields opcode ulong overflow ulong to long
72 if or eq opcode 0 gt opcode 16
73 ret 1
74 end
75 if or eq overflow 0 gt overflow 3
76 ret 2
77 end
78 ret 0
79end
80
81note Validate graph object count: 0 OK, 1 empty, 2 exceeds max.
82export fn om_val_graph_count cnt ulong mcnt ulong to long
83 if eq cnt 0
84 ret 1
85 end
86 if gt cnt mcnt
87 ret 2
88 end
89 ret 0
90end
91
92fn dfs_from edges view ushort 32768 deg view ushort 256 col edit uchar 256 root ulong to ulong
93 frm = new ushort 512 0
94 put frm 0 ushort root
95 put frm 1 0
96 put col root 1
97 sp = ulong 1
98 while gt sp 0
99 u = ulong get frm mul sub sp 1 2
100 k = ulong get frm add mul sub sp 1 2 1
101 if ge k ulong get deg u
102 put col u 2
103 sp = sub sp 1
104 else
105 put frm add mul sub sp 1 2 1 ushort add k 1
106 ent = ulong get edges add mul u 128 k
107 tgt = and ent 511
108 if lt tgt 256
109 if eq get col tgt 0
110 put col tgt 1
111 put frm mul sp 2 ushort tgt
112 put frm add mul sp 2 1 0
113 sp = add sp 1
114 else
115 if eq get col tgt 1
116 ret add ent 1
117 end
118 end
119 end
120 end
121 end
122 ret 0
123end
124
125note Iterative 3-color DFS cycle detector matching check_cycle_dfs order.
126note edges[u*128 + k] packs (edge_kind << 9) | target_idx (edge_kind 0=relation, 1=operand).
127note deg[u] is edge count for object u (<= 128). n <= 256.
128note Returns 0 if acyclic, -1 if cycle found with info[0]=target_idx, info[1]=edge_kind.
129export fn om_val_find_cycle edges view ushort 32768 deg view ushort 256 n ulong info edit ulong 2 to long
130 if gt n 256
131 ret -2
132 end
133 col = new uchar 256 0
134 for root ulong n
135 if eq get col root 0
136 r = dfs_from edges deg col root
137 if ne r 0
138 ent = sub r 1
139 put info 0 and ent 511
140 put info 1 shr ent 9
141 ret -1
142 end
143 end
144 end
145 ret 0
146end