Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/om/compiler/osc_lifetimes.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / om / compiler / osc_lifetimes.om` 150 lines ยท 4107 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note End a range of lexical scopes, newest binding first. Emit one action for 3 note each destruction that the trace or lowering release list needs. A live 4 note borrow at arena exit stops the walk after all preceding actions. 5 note bridge c-define OSC_SCOPE_END_BORROW 1 6 note bridge c-define OSC_SCOPE_RELEASE_OWNER 2 7 note bridge c-define OSC_SCOPE_DESTROY_ARENA 3 8 note bridge c-define OSC_SCOPE_CLOSE_POOL 4 9 note bridge c-define OSC_SCOPE_REFUSE_ESCAPE 5 10 note bridge c-type exitwork OscScopeExit 11 om2 12 13 layout exitwork 1936 14 field first uint at 0 little 15 field count uint at 4 little 16 field objects uint at 8 little 17 field borrows uint at 12 little 18 field actions uint 480 at 16 little 19 end 20 21 fn load32 data view uchar * pos ulong to ulong 22 value = ulong 0 23 for j ulong 4 24 value = or value shl ulong get data add pos j mul j 8 25 end 26 ret value 27 end 28 29 fn dec16 data edit uchar * pos ulong to void 30 high = shl ulong get data add pos 1 8 31 value = sub or high ulong get data pos 1 32 put data pos uchar and value 255 33 put data add pos 1 uchar and shr value 8 255 34 end 35 36 fn end_borrow owners edit uchar * borrows edit uchar * id ulong to ulong 37 if eq id `4294967295` 38 ret 0 39 end 40 child = mul id 24 41 if eq get borrows child 0 42 ret 0 43 end 44 put borrows child 0 45 count_offset = ulong 0 46 if ne get borrows add child 1 0 47 count_offset = 2 48 end 49 parent = load32 borrows add child 8 50 if eq parent `4294967295` 51 object = mul load32 borrows add child 4 20 52 dec16 owners add add object 2 count_offset 53 else 54 dec16 borrows add add mul parent 24 12 count_offset 55 end 56 ret 1 57 end 58 59 fn end_owner owners edit uchar * id ulong to ulong 60 pos = mul id 20 61 if ne load32 owners add pos 16 0 62 ret 0 63 end 64 moved = get owners pos 65 if and ne moved 0 ne moved 3 66 ret 0 67 end 68 put owners pos 2 69 ret 2 70 end 71 72 fn end_arena owners edit uchar 5120 borrows view uchar 12288 symbol ulong work view exitwork to ulong 73 region = add symbol 1 74 for b ulong ulong get work borrows 75 pos = mul b 24 76 if ne get borrows pos 0 77 object = mul load32 borrows add pos 4 20 78 if eq load32 owners add object 16 region 79 ret 5 80 end 81 end 82 end 83 for o ulong ulong get work objects 84 pos = mul o 20 85 if and eq get owners pos 0 eq load32 owners add pos 16 region 86 put owners pos 2 87 end 88 end 89 ret 3 90 end 91 92 fn end_symbol symbols view uchar 76800 owners edit uchar 5120 borrows edit uchar 12288 id ulong work view exitwork to ulong 93 base = mul id 160 94 kind = get symbols add base 68 95 if eq kind 3 96 ret end_borrow owners borrows load32 symbols add base 96 97 end 98 if eq kind 2 99 ret end_owner owners load32 symbols add base 92 100 end 101 if eq kind 4 102 ret end_arena owners borrows id work 103 end 104 if eq kind 5 105 ret 4 106 end 107 ret 0 108 end 109 110 export fn osc_scope_exit visible view ushort 480 symbols view uchar 76800 owners edit uchar 5120 borrows edit uchar 12288 work edit exitwork to ulong 111 requires le get work count 480 112 requires le get work first get work count 113 requires le get work objects 256 114 requires le get work borrows 512 115 count = ulong 0 116 pos = ulong get work count 117 while gt pos ulong get work first bound 480 118 pos = sub pos 1 119 id = ulong get visible pos 120 action = end_symbol symbols owners borrows id work 121 if ne action 0 122 put work actions count uint or shl action 16 id 123 count = add count 1 124 if eq action 5 125 break 126 end 127 end 128 end 129 ret count 130 end 131 132 note Only an allocation at the declaration's loop and branch depth is 133 note guaranteed to consume cells. Refusals leave the arena counter intact. 134 export fn osc_reserve_arena symbol edit uchar 160 loop_depth ulong branch_depth ulong cells ulong to ulong 135 if or ne load32 symbol 88 loop_depth ne load32 symbol 108 branch_depth 136 ret 1 137 end 138 cap = or ulong get symbol 104 shl ulong get symbol 105 8 139 used = or ulong get symbol 106 shl ulong get symbol 107 8 140 if gt used cap 141 ret 0 142 end 143 if gt cells sub cap used 144 ret 0 145 end 146 total = add used cells 147 put symbol 106 uchar and total 255 148 put symbol 107 uchar shr total 8 149 ret 1 150 end