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
omega-mv / om / runtime / rx_world_core.om
| 1 | om2 |
| 2 | note rx_world_core.om -- Reaction World lifecycle FSM, resource admission, |
| 3 | note and priority/fairness ordering in pure OM-2. |
| 4 | note Replaces rx_state_transition_legal, res_fits, and better_admit |
| 5 | note in src/runtime/rx_world.c. |
| 6 | note |
| 7 | note RxState enum: |
| 8 | note 0 DORMANT, 1 READY, 2 BLOCKED_AUTHORITY, 3 BLOCKED_RESOURCE, |
| 9 | note 4 RUNNING, 5 PUBLISHING, 6 COMMITTED, 7 INVALIDATED, |
| 10 | note 8 FAILED, 9 CANCELLED, 10 CONFLICT, 11 REJECTED. |
| 11 | |
| 12 | const ST_DORMANT ulong 0 |
| 13 | const ST_READY ulong 1 |
| 14 | const ST_BLOCKED_AUTH ulong 2 |
| 15 | const ST_BLOCKED_RES ulong 3 |
| 16 | const ST_RUNNING ulong 4 |
| 17 | const ST_PUBLISHING ulong 5 |
| 18 | const ST_COMMITTED ulong 6 |
| 19 | const ST_INVALIDATED ulong 7 |
| 20 | const ST_FAILED ulong 8 |
| 21 | const ST_CANCELLED ulong 9 |
| 22 | const ST_CONFLICT ulong 10 |
| 23 | const ST_REJECTED ulong 11 |
| 24 | |
| 25 | export fn rx_world_state_legal from ulong dest ulong to ulong |
| 26 | if eq from ST_DORMANT |
| 27 | if eq dest ST_READY |
| 28 | ret 1 |
| 29 | end |
| 30 | if eq dest ST_BLOCKED_RES |
| 31 | ret 1 |
| 32 | end |
| 33 | ret 0 |
| 34 | end |
| 35 | if eq from ST_READY |
| 36 | if eq dest ST_RUNNING |
| 37 | ret 1 |
| 38 | end |
| 39 | if eq dest ST_BLOCKED_AUTH |
| 40 | ret 1 |
| 41 | end |
| 42 | if eq dest ST_BLOCKED_RES |
| 43 | ret 1 |
| 44 | end |
| 45 | if eq dest ST_INVALIDATED |
| 46 | ret 1 |
| 47 | end |
| 48 | ret 0 |
| 49 | end |
| 50 | if eq from ST_RUNNING |
| 51 | if eq dest ST_PUBLISHING |
| 52 | ret 1 |
| 53 | end |
| 54 | if eq dest ST_FAILED |
| 55 | ret 1 |
| 56 | end |
| 57 | if eq dest ST_CANCELLED |
| 58 | ret 1 |
| 59 | end |
| 60 | if eq dest ST_INVALIDATED |
| 61 | ret 1 |
| 62 | end |
| 63 | if eq dest ST_READY |
| 64 | ret 1 |
| 65 | end |
| 66 | ret 0 |
| 67 | end |
| 68 | if eq from ST_PUBLISHING |
| 69 | if eq dest ST_COMMITTED |
| 70 | ret 1 |
| 71 | end |
| 72 | if eq dest ST_CONFLICT |
| 73 | ret 1 |
| 74 | end |
| 75 | if eq dest ST_REJECTED |
| 76 | ret 1 |
| 77 | end |
| 78 | if eq dest ST_INVALIDATED |
| 79 | ret 1 |
| 80 | end |
| 81 | ret 0 |
| 82 | end |
| 83 | if eq from ST_BLOCKED_RES |
| 84 | if eq dest ST_DORMANT |
| 85 | ret 1 |
| 86 | end |
| 87 | if eq dest ST_READY |
| 88 | ret 1 |
| 89 | end |
| 90 | ret 0 |
| 91 | end |
| 92 | if ge from ST_COMMITTED |
| 93 | if le from ST_REJECTED |
| 94 | if eq dest ST_DORMANT |
| 95 | ret 1 |
| 96 | end |
| 97 | ret 0 |
| 98 | end |
| 99 | end |
| 100 | if eq from ST_BLOCKED_AUTH |
| 101 | if eq dest ST_DORMANT |
| 102 | ret 1 |
| 103 | end |
| 104 | ret 0 |
| 105 | end |
| 106 | ret 0 |
| 107 | end |
| 108 | |
| 109 | note used[3]: 0=used_slots, 1=used_memory, 2=used_energy |
| 110 | note budget[6]: 0=slots, 1=memory_bytes, 2=energy_budget, 3=offered_locality, 4=offered_accel, 5=compute_mask |
| 111 | note need[5]: 0=memory_bytes, 1=energy_cost, 2=locality, 3=accelerator_features, 4=compute_class |
| 112 | export fn rx_world_res_fits used view ulong 4 budget view ulong 6 need view ulong 5 to ulong |
| 113 | if ge get used 0 get budget 0 |
| 114 | ret 0 |
| 115 | end |
| 116 | umem = get used 1 |
| 117 | bmem = get budget 1 |
| 118 | if gt umem bmem |
| 119 | ret 0 |
| 120 | end |
| 121 | ueng = get used 2 |
| 122 | beng = get budget 2 |
| 123 | if gt ueng beng |
| 124 | ret 0 |
| 125 | end |
| 126 | if gt get need 0 sub bmem umem |
| 127 | ret 0 |
| 128 | end |
| 129 | if gt get need 1 sub beng ueng |
| 130 | ret 0 |
| 131 | end |
| 132 | nloc = get need 2 |
| 133 | if ne nloc 0 |
| 134 | if ne and nloc get budget 3 nloc |
| 135 | ret 0 |
| 136 | end |
| 137 | end |
| 138 | nacc = get need 3 |
| 139 | if ne nacc 0 |
| 140 | if ne and nacc get budget 4 nacc |
| 141 | ret 0 |
| 142 | end |
| 143 | end |
| 144 | ncc = get need 4 |
| 145 | if ne ncc 0 |
| 146 | bit = shl ulong 1 and ncc 31 |
| 147 | if eq and get budget 5 bit 0 |
| 148 | ret 0 |
| 149 | end |
| 150 | end |
| 151 | ret 1 |
| 152 | end |
| 153 | |
| 154 | note a[3], b[3]: 0=priority, 1=wait_seq, 2=service. Returns 1 if a beats b. |
| 155 | export fn rx_world_better_admit a view ulong 3 b view ulong 3 to ulong |
| 156 | pa = get a 0 |
| 157 | pb = get b 0 |
| 158 | if ne pa pb |
| 159 | if lt pa pb |
| 160 | ret 1 |
| 161 | end |
| 162 | ret 0 |
| 163 | end |
| 164 | wa = get a 1 |
| 165 | wb = get b 1 |
| 166 | if ne wa wb |
| 167 | if lt wa wb |
| 168 | ret 1 |
| 169 | end |
| 170 | ret 0 |
| 171 | end |
| 172 | if lt get a 2 get b 2 |
| 173 | ret 1 |
| 174 | end |
| 175 | ret 0 |
| 176 | end |