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 / compiler / osc_pool.om

163 lines · 4617 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note Definite pool usage for OSC versioned handles. Crossing a conditional
3note free invalidates the live-slot bound. The generation budget still applies.
4note bridge c-type poolstat OscCheckedPool
5note bridge c-define OSC_POOL_FULL 1
6note bridge c-define OSC_POOL_RETIRED 2
7note bridge c-type handles OscHandleState
8note bridge c-define OSC_HANDLE_UNKNOWN 0
9note bridge c-define OSC_HANDLE_LIVE 1
10note bridge c-define OSC_HANDLE_STALE 2
11note bridge c-define OSC_HANDLE_STALE_COPY 3
12om2
13
14note Each allocation creates exactly one provenance, one model slot and one
15note model handle. Model IDs are one-based. Bindings have their own monotonically
16note assigned indices so a branch snapshot visits only actual handle bindings.
17layout handles 2952
18field count uint at 0 little
19field nbind uint at 4 little
20field freed uchar 1024 at 8 little
21field binding int 480 at 1032 little
22end
23
24layout poolstat 32
25field gbase ulong at 0 little
26field dallocs ulong at 8 little
27field loop int at 16 little
28field branch int at 20 little
29field cap ushort at 24 little
30field dlive ushort at 26 little
31field cap_off uchar at 28 little
32end
33
34export fn osc_pool_init p edit poolstat cap ulong base ulong loop_depth long cond_depth long to void
35 put p gbase base
36 put p dallocs 0
37 put p loop int loop_depth
38 put p branch int cond_depth
39 put p cap ushort cap
40 put p dlive 0
41 put p cap_off 0
42end
43
44fn definite p view poolstat loop_depth long cond_depth long to bool
45 ret and eq long get p loop loop_depth eq long get p branch cond_depth
46end
47
48export fn osc_pool_alloc p edit poolstat loop_depth long cond_depth long to ulong
49 if not definite p loop_depth cond_depth
50 ret 0
51 end
52 live = ulong get p dlive
53 slots = ulong get p cap
54 if and eq get p cap_off 0 ge live slots
55 ret 1
56 end
57 remaining = sub ulong 18446744073709551615 get p gbase
58 allocations = add get p dallocs 1
59 if and lt remaining 4294967296 gt allocations mul slots add remaining 1
60 ret 2
61 end
62 put p dallocs allocations
63 if eq get p cap_off 0
64 put p dlive ushort add live 1
65 end
66 ret 0
67end
68
69export fn osc_pool_free p edit poolstat loop_depth long cond_depth long to void
70 if not definite p loop_depth cond_depth
71 put p cap_off 1
72 else
73 live = get p dlive
74 if ne live 0
75 put p dlive sub live 1
76 end
77 end
78end
79
80export fn osc_handle_allocate h edit handles to long
81 p = ulong get h count
82 if ge p 1024
83 ret -1
84 end
85 put h count uint add p 1
86 put h freed p 0
87 ret long p
88end
89
90export fn osc_handle_bind h edit handles provenance long to ulong
91requires lt get h nbind 480
92 b = ulong get h nbind
93 put h nbind uint add b 1
94 put h binding b int provenance
95 ret b
96end
97
98note An unknown provenance produces no model event. A refused free retains
99note the first free site, including when the second access is through a copy.
100export fn osc_handle_visit h edit handles sites edit ulong 1024 b ulong freeing ulong symbol long line ulong to ulong
101requires lt b ulong get h nbind
102 provenance = get h binding b
103 if lt provenance 0
104 ret 0
105 end
106 p = ulong provenance
107 if ne get h freed p 0
108 if ne shr get sites p 32 ulong symbol
109 ret 3
110 end
111 ret 2
112 end
113 if ne freeing 0
114 put h freed p 1
115 put sites p or shl ulong symbol 32 ulong uint line
116 end
117 ret 1
118end
119
120export fn osc_handles_save h view handles s edit handles to void
121 put s count get h count
122 put s nbind get h nbind
123 for p ulong ulong get h count
124 put s freed p get h freed p
125 end
126 for b ulong ulong get h nbind
127 put s binding b get h binding b
128 end
129end
130
131note Restoring a branch retains fresh allocation and binding IDs. A loop
132note restores definite frees only, then settles possible binding assignments.
133export fn osc_handles_restore h edit handles s view handles bindings ulong to void
134 for p ulong ulong get s count
135 put h freed p get s freed p
136 end
137 if ne bindings 0
138 for b ulong ulong get s nbind
139 put h binding b get s binding b
140 end
141 end
142end
143
144export fn osc_handles_settle h edit handles before view handles other view handles to void
145 for b ulong ulong get before nbind
146 initial = get before binding b
147 if or ne get h binding b initial ne get other binding b initial
148 put h binding b -1
149 end
150 end
151end
152
153note Return newly definite frees in original model-event order.
154export fn osc_handle_frees h view handles before view handles ids edit uint 1024 to ulong
155 count = ulong 0
156 for p ulong ulong get before count
157 if and ne get h freed p 0 eq get before freed p 0
158 put ids count uint add p 1
159 count = add count 1
160 end
161 end
162 ret count
163end