@salang/sa 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/sa.js +19 -1
- package/package.json +8 -7
- package/sa_std/alloc/layout.sal +12 -0
- package/sa_std/alloc/prelude.sa +1 -0
- package/sa_std/alloc/prelude.sal +1 -0
- package/sa_std/alloc/string.sa +3 -0
- package/sa_std/alloc/vec.sa +684 -0
- package/sa_std/alloc/vec.sal +4 -0
- package/sa_std/any.sa +130 -0
- package/sa_std/any.sal +23 -0
- package/sa_std/array.sa +1876 -0
- package/sa_std/ascii.sa +2 -0
- package/sa_std/ascii.sal +1 -0
- package/sa_std/async.sla +116 -0
- package/sa_std/binary_heap.sa +3003 -0
- package/sa_std/binary_heap.sal +7 -0
- package/sa_std/borrow.sa +171 -0
- package/sa_std/borrow.sal +13 -0
- package/sa_std/btree_map.sa +2210 -0
- package/sa_std/btree_map.sal +11 -0
- package/sa_std/btree_set.sa +1072 -0
- package/sa_std/btree_set.sal +6 -0
- package/sa_std/char.sa +1309 -0
- package/sa_std/char.sal +50 -0
- package/sa_std/cmp.sa +554 -0
- package/sa_std/cmp.sal +14 -0
- package/sa_std/collections/binary_heap.sa +1 -0
- package/sa_std/collections/btree_map.sa +1 -0
- package/sa_std/collections/btree_set.sa +1 -0
- package/sa_std/collections/hashmap.sa +1 -0
- package/sa_std/collections/hashset.sa +1 -0
- package/sa_std/collections/linked_list.sa +1120 -0
- package/sa_std/collections/linked_list.sal +10 -0
- package/sa_std/collections/prelude.sa +7 -0
- package/sa_std/collections/prelude.sal +1 -0
- package/sa_std/collections/vec_deque.sa +1 -0
- package/sa_std/collections.sal +13 -0
- package/sa_std/convert.sa +1115 -0
- package/sa_std/convert.sal +24 -0
- package/sa_std/core/arc.sa +233 -0
- package/sa_std/core/arc.sal +4 -0
- package/sa_std/core/ascii.sa +784 -0
- package/sa_std/core/ascii.sal +34 -0
- package/sa_std/core/bit.sa +41 -0
- package/sa_std/core/box.sa +1 -0
- package/sa_std/core/box.sal +2 -0
- package/sa_std/core/cell.sa +108 -0
- package/sa_std/core/cell.sal +5 -0
- package/sa_std/core/cleanup.sa +26 -0
- package/sa_std/core/control.sa +20 -0
- package/sa_std/core/derive.sa +60 -0
- package/sa_std/core/derive.sal +1 -0
- package/sa_std/core/dispatch.sa +7 -0
- package/sa_std/core/dispatch.sal +5 -0
- package/sa_std/core/future.sa +777 -0
- package/sa_std/core/future.sal +73 -0
- package/sa_std/core/hash.sa +48 -0
- package/sa_std/core/iter.sa +2805 -0
- package/sa_std/core/iter.sal +4 -0
- package/sa_std/core/loop.sa +60 -0
- package/sa_std/core/mem.sa +220 -0
- package/sa_std/core/option.sa +825 -0
- package/sa_std/core/option.sal +11 -0
- package/sa_std/core/panic.sa +23 -0
- package/sa_std/core/panic.sal +12 -0
- package/sa_std/core/prelude.sa +18 -0
- package/sa_std/core/prelude.sal +18 -0
- package/sa_std/core/rc.sa +225 -0
- package/sa_std/core/rc.sal +4 -0
- package/sa_std/core/refcell.sa +283 -0
- package/sa_std/core/refcell.sal +13 -0
- package/sa_std/core/result.sa +708 -0
- package/sa_std/core/result.sal +6 -0
- package/sa_std/core/rust_patterns.sal +295 -0
- package/sa_std/core/sa_core.sa +84 -0
- package/sa_std/core/slice.sa +4021 -0
- package/sa_std/core/slice.sal +7 -0
- package/sa_std/core/task.sa +112 -0
- package/sa_std/core/task.sal +15 -0
- package/sa_std/core/trait_object.sa +26 -0
- package/sa_std/core/trait_object.sal +4 -0
- package/sa_std/core/waker.sa +289 -0
- package/sa_std/core/waker.sal +31 -0
- package/sa_std/core/weak.sa +2 -0
- package/sa_std/core/weak.sal +4 -0
- package/sa_std/cow.sa +3 -0
- package/sa_std/cow.sal +2 -0
- package/sa_std/cstring.sa +3 -0
- package/sa_std/cstring.sal +2 -0
- package/sa_std/default.sa +99 -0
- package/sa_std/duration.sa +3 -0
- package/sa_std/duration.sal +2 -0
- package/sa_std/encoding/json.sa +259 -0
- package/sa_std/encoding/json.sai +54 -0
- package/sa_std/encoding/json.sal +35 -0
- package/sa_std/encoding/prelude.sa +1 -0
- package/sa_std/encoding/prelude.sal +0 -0
- package/sa_std/env.sa +390 -0
- package/sa_std/env.sai +25 -0
- package/sa_std/error.sa +253 -0
- package/sa_std/error.sal +44 -0
- package/sa_std/ffi/cstring.sa +3 -0
- package/sa_std/ffi/cstring.sal +1 -0
- package/sa_std/ffi/prelude.sa +2 -0
- package/sa_std/ffi/prelude.sal +2 -0
- package/sa_std/ffi.sa +635 -0
- package/sa_std/ffi.sal +51 -0
- package/sa_std/fmt.sa +2 -0
- package/sa_std/fmt.sai +18 -0
- package/sa_std/fmt.sal +35 -0
- package/sa_std/fs.sa +1023 -0
- package/sa_std/fs.sai +127 -0
- package/sa_std/fs.sal +51 -0
- package/sa_std/future.sa +2 -0
- package/sa_std/future.sal +1 -0
- package/sa_std/hash.sa +1486 -0
- package/sa_std/hash.sal +13 -0
- package/sa_std/hashmap.sa +1962 -0
- package/sa_std/hashmap.sal +20 -0
- package/sa_std/hashset.sa +1004 -0
- package/sa_std/hashset.sal +18 -0
- package/sa_std/http2.sa +78 -0
- package/sa_std/http2.sai +26 -0
- package/sa_std/http2.sal +36 -0
- package/sa_std/instant.sa +3 -0
- package/sa_std/instant.sal +2 -0
- package/sa_std/io/buf_reader.sa +43 -0
- package/sa_std/io/buf_writer.sa +35 -0
- package/sa_std/io/bufio.sa +4 -0
- package/sa_std/io/bufio.sal +4 -0
- package/sa_std/io/prelude.sa +1 -0
- package/sa_std/io/prelude.sal +1 -0
- package/sa_std/io/print.sa +2 -0
- package/sa_std/io/print.sai +3 -0
- package/sa_std/io.sa +925 -0
- package/sa_std/io.sai +25 -0
- package/sa_std/io.sal +84 -0
- package/sa_std/iter.sa +2 -0
- package/sa_std/iter.sal +1 -0
- package/sa_std/join_handle.sa +3 -0
- package/sa_std/join_handle.sal +2 -0
- package/sa_std/libsa_async.sa +80 -0
- package/sa_std/m_async.sa +137 -0
- package/sa_std/m_async.sal +30 -0
- package/sa_std/m_async.sla +2 -0
- package/sa_std/manually_drop.sa +3 -0
- package/sa_std/manually_drop.sal +2 -0
- package/sa_std/marker/phantom_data.sa +3 -0
- package/sa_std/marker/phantom_data.sal +1 -0
- package/sa_std/marker/prelude.sa +4 -0
- package/sa_std/marker/prelude.sal +4 -0
- package/sa_std/marker.sa +220 -0
- package/sa_std/marker.sal +15 -0
- package/sa_std/math.sa +84 -0
- package/sa_std/math.sai +10 -0
- package/sa_std/mem/manually_drop.sa +3 -0
- package/sa_std/mem/manually_drop.sal +1 -0
- package/sa_std/mem/prelude.sa +2 -0
- package/sa_std/mem/prelude.sal +2 -0
- package/sa_std/mem.sa +564 -0
- package/sa_std/mem.sal +40 -0
- package/sa_std/modstate.sai +19 -0
- package/sa_std/net.sa +4227 -0
- package/sa_std/net.sai +239 -0
- package/sa_std/net.sal +159 -0
- package/sa_std/netx.sa +85 -0
- package/sa_std/netx.sai +11 -0
- package/sa_std/netx.sal +39 -0
- package/sa_std/nonzero.sa +3 -0
- package/sa_std/nonzero.sal +2 -0
- package/sa_std/num/nonzero.sa +3 -0
- package/sa_std/num/nonzero.sal +1 -0
- package/sa_std/num/prelude.sa +3 -0
- package/sa_std/num/prelude.sal +3 -0
- package/sa_std/num.sa +17302 -0
- package/sa_std/num.sai +11 -0
- package/sa_std/num.sal +341 -0
- package/sa_std/ops.sa +1884 -0
- package/sa_std/ops.sal +68 -0
- package/sa_std/option.sa +2 -0
- package/sa_std/option.sal +1 -0
- package/sa_std/os/fd.sa +96 -0
- package/sa_std/os/fd.sai +7 -0
- package/sa_std/os/fd.sal +11 -0
- package/sa_std/os/prelude.sa +2 -0
- package/sa_std/os/prelude.sal +1 -0
- package/sa_std/os/unix_ffi.sa +271 -0
- package/sa_std/panic.sa +1 -0
- package/sa_std/panic.sal +1 -0
- package/sa_std/path.sa +3170 -0
- package/sa_std/path.sal +12 -0
- package/sa_std/phantom_data.sa +3 -0
- package/sa_std/phantom_data.sal +2 -0
- package/sa_std/pin.sa +79 -0
- package/sa_std/pin.sal +5 -0
- package/sa_std/plugin_async.sa +90 -0
- package/sa_std/plugin_async.sal +29 -0
- package/sa_std/plugin_async.sla +4 -0
- package/sa_std/plugin_http_async.sa +46 -0
- package/sa_std/plugin_http_server.sa +61 -0
- package/sa_std/plugin_http_server.sla +2 -0
- package/sa_std/plugin_sqlite.sa +106 -0
- package/sa_std/plugin_sqlite.sla +2 -0
- package/sa_std/prelude.sa +60 -0
- package/sa_std/prelude.sal +55 -0
- package/sa_std/process.sa +916 -0
- package/sa_std/process.sai +57 -0
- package/sa_std/process.sal +27 -0
- package/sa_std/ptr.sa +503 -0
- package/sa_std/ptr.sal +2 -0
- package/sa_std/result.sa +2 -0
- package/sa_std/result.sal +1 -0
- package/sa_std/rust_core.sa +51 -0
- package/sa_std/rust_core.sal +26 -0
- package/sa_std/sa.mod +7 -0
- package/sa_std/sort.sa +156 -0
- package/sa_std/str.sla +13 -0
- package/sa_std/string.sa +12240 -0
- package/sa_std/string.sai +25 -0
- package/sa_std/string.sal +17 -0
- package/sa_std/string_format.sa +269 -0
- package/sa_std/sync/atomic.sa +1500 -0
- package/sa_std/sync/atomic.sal +45 -0
- package/sa_std/sync/barrier.sa +105 -0
- package/sa_std/sync/barrier.sal +7 -0
- package/sa_std/sync/condvar.sa +240 -0
- package/sa_std/sync/condvar.sal +4 -0
- package/sa_std/sync/mpsc.sa +758 -0
- package/sa_std/sync/mpsc.sal +42 -0
- package/sa_std/sync/mpsc_list.sa +255 -0
- package/sa_std/sync/mpsc_list.sal +3 -0
- package/sa_std/sync/mutex.sa +182 -0
- package/sa_std/sync/mutex.sal +7 -0
- package/sa_std/sync/once.sa +371 -0
- package/sa_std/sync/once.sal +31 -0
- package/sa_std/sync/poison.sa +36 -0
- package/sa_std/sync/poison.sal +11 -0
- package/sa_std/sync/prelude.sa +8 -0
- package/sa_std/sync/prelude.sal +7 -0
- package/sa_std/sync/rwlock.sa +369 -0
- package/sa_std/sync/rwlock.sal +13 -0
- package/sa_std/task.sa +2 -0
- package/sa_std/task.sal +1 -0
- package/sa_std/term.sa +2 -0
- package/sa_std/term.sai +10 -0
- package/sa_std/term.sal +33 -0
- package/sa_std/testing/assert.sai +4 -0
- package/sa_std/testing/mock_io.sa +174 -0
- package/sa_std/testing/mock_io.sal +5 -0
- package/sa_std/testing/prelude.sa +2 -0
- package/sa_std/testing/prelude.sal +1 -0
- package/sa_std/text/prelude.sa +1 -0
- package/sa_std/text/prelude.sal +1 -0
- package/sa_std/text/regex.sa +2 -0
- package/sa_std/text/regex.sai +9 -0
- package/sa_std/text/regex.sal +33 -0
- package/sa_std/thread/join_handle.sa +3 -0
- package/sa_std/thread/join_handle.sal +1 -0
- package/sa_std/thread/prelude.sa +4 -0
- package/sa_std/thread/prelude.sal +3 -0
- package/sa_std/thread.sa +160 -0
- package/sa_std/thread.sai +11 -0
- package/sa_std/thread.sal +4 -0
- package/sa_std/thread_local.sa +45 -0
- package/sa_std/thread_local.sai +9 -0
- package/sa_std/time/duration.sa +3 -0
- package/sa_std/time/duration.sal +1 -0
- package/sa_std/time/instant.sa +3 -0
- package/sa_std/time/instant.sal +1 -0
- package/sa_std/time/prelude.sa +4 -0
- package/sa_std/time/prelude.sal +4 -0
- package/sa_std/time.sa +850 -0
- package/sa_std/time.sai +37 -0
- package/sa_std/time.sal +35 -0
- package/sa_std/time.sla +67 -0
- package/sa_std/tls_client.sai +39 -0
- package/sa_std/vec.sa +5754 -0
- package/sa_std/vec.sal +1 -0
- package/sa_std/vec_deque.sa +4925 -0
- package/sa_std/vec_deque.sal +8 -0
- package/sa_std/vec_runtime_macros.sa +11 -0
- package/sa_std/ws_client.sai +57 -0
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
// Concrete OnceCell helpers built on an explicit three-state machine.
|
|
2
|
+
// The payload is stored as raw u64 bits so callers can round-trip ptr or
|
|
3
|
+
// integer values without hidden type magic.
|
|
4
|
+
@import "once.sal"
|
|
5
|
+
@import "../time.sai"
|
|
6
|
+
|
|
7
|
+
@__once_wait_ready(&once: ptr) -> void:
|
|
8
|
+
L_ENTRY:
|
|
9
|
+
state = atomic_load once+Once_state as u32 acquire
|
|
10
|
+
ready = eq state, Once_STATE_READY
|
|
11
|
+
br ready -> L_ONCE_WAIT_READY_DONE, L_ONCE_WAIT_READY_SPIN
|
|
12
|
+
|
|
13
|
+
L_ONCE_WAIT_READY_SPIN:
|
|
14
|
+
!ready
|
|
15
|
+
!state
|
|
16
|
+
call @sa_time_sleep_ns(1)
|
|
17
|
+
jmp L_ENTRY
|
|
18
|
+
|
|
19
|
+
L_ONCE_WAIT_READY_DONE:
|
|
20
|
+
!ready
|
|
21
|
+
!state
|
|
22
|
+
!once
|
|
23
|
+
return
|
|
24
|
+
|
|
25
|
+
@__once_try_claim(&once: ptr) -> i32:
|
|
26
|
+
L_ENTRY:
|
|
27
|
+
state = atomic_load once+Once_state as u32 acquire
|
|
28
|
+
ready = eq state, Once_STATE_READY
|
|
29
|
+
br ready -> L_ONCE_TRY_READY, L_ONCE_TRY_CHECK
|
|
30
|
+
|
|
31
|
+
L_ONCE_TRY_CHECK:
|
|
32
|
+
is_uninit = eq state, Once_STATE_UNINIT
|
|
33
|
+
br is_uninit -> L_ONCE_TRY_CLAIM, L_ONCE_TRY_WAIT
|
|
34
|
+
|
|
35
|
+
L_ONCE_TRY_CLAIM:
|
|
36
|
+
old, ok = cmpxchg once+Once_state, Once_STATE_UNINIT, Once_STATE_RUNNING as u32 acq_rel acquire
|
|
37
|
+
br ok -> L_ONCE_TRY_OWNER, L_ONCE_TRY_RETRY
|
|
38
|
+
|
|
39
|
+
L_ONCE_TRY_RETRY:
|
|
40
|
+
!old
|
|
41
|
+
!ok
|
|
42
|
+
!is_uninit
|
|
43
|
+
!ready
|
|
44
|
+
!state
|
|
45
|
+
call @sa_time_sleep_ns(1)
|
|
46
|
+
jmp L_ENTRY
|
|
47
|
+
|
|
48
|
+
L_ONCE_TRY_WAIT:
|
|
49
|
+
!is_uninit
|
|
50
|
+
!ready
|
|
51
|
+
!state
|
|
52
|
+
call @sa_time_sleep_ns(1)
|
|
53
|
+
jmp L_ENTRY
|
|
54
|
+
|
|
55
|
+
L_ONCE_TRY_OWNER:
|
|
56
|
+
!old
|
|
57
|
+
!ok
|
|
58
|
+
!is_uninit
|
|
59
|
+
!ready
|
|
60
|
+
!state
|
|
61
|
+
!once
|
|
62
|
+
return 1
|
|
63
|
+
|
|
64
|
+
L_ONCE_TRY_READY:
|
|
65
|
+
!ready
|
|
66
|
+
!state
|
|
67
|
+
!once
|
|
68
|
+
return 0
|
|
69
|
+
|
|
70
|
+
[MACRO] ONCE_NEW %out_once
|
|
71
|
+
%out_once = alloc Once_SIZE
|
|
72
|
+
store %out_once+Once_state, Once_STATE_UNINIT as u32
|
|
73
|
+
store %out_once+Once_value, 0 as u64
|
|
74
|
+
[END_MACRO]
|
|
75
|
+
|
|
76
|
+
[MACRO] ONCE_IS_READY %out_ready, %once_reg
|
|
77
|
+
__once_state = atomic_load %once_reg+Once_state as u32 acquire
|
|
78
|
+
%out_ready = eq __once_state, Once_STATE_READY
|
|
79
|
+
!__once_state
|
|
80
|
+
[END_MACRO]
|
|
81
|
+
|
|
82
|
+
[MACRO] ONCE_STATE %out_state, %once_reg
|
|
83
|
+
%out_state = atomic_load %once_reg+Once_state as u32 acquire
|
|
84
|
+
[END_MACRO]
|
|
85
|
+
|
|
86
|
+
[MACRO] ONCE_STATE_NEW %state_ptr, %poisoned
|
|
87
|
+
store %state_ptr+OnceState_poisoned, %poisoned as u8
|
|
88
|
+
store %state_ptr+OnceState_set_state_to, OnceState_STATE_COMPLETE as u32
|
|
89
|
+
[END_MACRO]
|
|
90
|
+
|
|
91
|
+
[MACRO] ONCE_STATE_IS_POISONED %out_bool, %state_ptr
|
|
92
|
+
__once_state_poisoned_%out_bool = load %state_ptr+OnceState_poisoned as u8
|
|
93
|
+
%out_bool = ne __once_state_poisoned_%out_bool, 0
|
|
94
|
+
!__once_state_poisoned_%out_bool
|
|
95
|
+
[END_MACRO]
|
|
96
|
+
|
|
97
|
+
[MACRO] ONCE_STATE_POISON %state_ptr
|
|
98
|
+
store %state_ptr+OnceState_set_state_to, OnceState_STATE_POISONED as u32
|
|
99
|
+
[END_MACRO]
|
|
100
|
+
|
|
101
|
+
[MACRO] ONCE_STATE_SET_STATE_TO %out_state, %state_ptr
|
|
102
|
+
%out_state = load %state_ptr+OnceState_set_state_to as u32
|
|
103
|
+
[END_MACRO]
|
|
104
|
+
|
|
105
|
+
[MACRO] ONCE_IS_UNINIT %out_bool, %once_reg
|
|
106
|
+
__once_uninit_state_%out_bool = atomic_load %once_reg+Once_state as u32 acquire
|
|
107
|
+
%out_bool = eq __once_uninit_state_%out_bool, Once_STATE_UNINIT
|
|
108
|
+
!__once_uninit_state_%out_bool
|
|
109
|
+
[END_MACRO]
|
|
110
|
+
|
|
111
|
+
[MACRO] ONCE_IS_RUNNING %out_bool, %once_reg
|
|
112
|
+
__once_running_state_%out_bool = atomic_load %once_reg+Once_state as u32 acquire
|
|
113
|
+
%out_bool = eq __once_running_state_%out_bool, Once_STATE_RUNNING
|
|
114
|
+
!__once_running_state_%out_bool
|
|
115
|
+
[END_MACRO]
|
|
116
|
+
|
|
117
|
+
[MACRO] ONCE_TRY_CLAIM %out_owned, %once_reg
|
|
118
|
+
__once_owned = call @__once_try_claim(&%once_reg)
|
|
119
|
+
%out_owned = __once_owned
|
|
120
|
+
[END_MACRO]
|
|
121
|
+
|
|
122
|
+
[MACRO] ONCE_WAIT_READY %once_reg
|
|
123
|
+
call @__once_wait_ready(&%once_reg)
|
|
124
|
+
[END_MACRO]
|
|
125
|
+
|
|
126
|
+
[MACRO] ONCE_PUBLISH %once_reg, %value
|
|
127
|
+
store %once_reg+Once_value, %value as u64
|
|
128
|
+
atomic_store %once_reg+Once_state, Once_STATE_READY as u32 release
|
|
129
|
+
[END_MACRO]
|
|
130
|
+
|
|
131
|
+
[MACRO] ONCE_SET %out_ok, %once_reg, %value
|
|
132
|
+
__once_set_ok_slot_%out_ok = stack_alloc 8
|
|
133
|
+
__once_set_owner_%out_ok = call @__once_try_claim(&%once_reg)
|
|
134
|
+
br __once_set_owner_%out_ok -> L_ONCE_SET_STORE_%out_ok, L_ONCE_SET_READY_%out_ok
|
|
135
|
+
L_ONCE_SET_STORE_%out_ok:
|
|
136
|
+
EXPAND ONCE_PUBLISH %once_reg, %value
|
|
137
|
+
store __once_set_ok_slot_%out_ok+0, 1 as u64
|
|
138
|
+
!__once_set_owner_%out_ok
|
|
139
|
+
jmp L_ONCE_SET_DONE_%out_ok
|
|
140
|
+
L_ONCE_SET_READY_%out_ok:
|
|
141
|
+
store __once_set_ok_slot_%out_ok+0, 0 as u64
|
|
142
|
+
!__once_set_owner_%out_ok
|
|
143
|
+
jmp L_ONCE_SET_DONE_%out_ok
|
|
144
|
+
L_ONCE_SET_DONE_%out_ok:
|
|
145
|
+
%out_ok = load __once_set_ok_slot_%out_ok+0 as u64
|
|
146
|
+
[END_MACRO]
|
|
147
|
+
|
|
148
|
+
[MACRO] ONCE_TRY_GET %out_ok, %out_value, %once_reg
|
|
149
|
+
__once_try_get_ok_slot_%out_ok = stack_alloc 8
|
|
150
|
+
__once_try_get_value_slot_%out_ok = stack_alloc 8
|
|
151
|
+
__once_try_get_state_%out_ok = atomic_load %once_reg+Once_state as u32 acquire
|
|
152
|
+
__once_try_get_ready_%out_ok = eq __once_try_get_state_%out_ok, Once_STATE_READY
|
|
153
|
+
br __once_try_get_ready_%out_ok -> L_ONCE_TRY_GET_READY_%out_ok, L_ONCE_TRY_GET_EMPTY_%out_ok
|
|
154
|
+
L_ONCE_TRY_GET_READY_%out_ok:
|
|
155
|
+
__once_try_get_value_%out_ok = load %once_reg+Once_value as u64
|
|
156
|
+
store __once_try_get_value_slot_%out_ok+0, __once_try_get_value_%out_ok as u64
|
|
157
|
+
store __once_try_get_ok_slot_%out_ok+0, 1 as u64
|
|
158
|
+
!__once_try_get_value_%out_ok
|
|
159
|
+
jmp L_ONCE_TRY_GET_DONE_%out_ok
|
|
160
|
+
L_ONCE_TRY_GET_EMPTY_%out_ok:
|
|
161
|
+
store __once_try_get_value_slot_%out_ok+0, 0 as u64
|
|
162
|
+
store __once_try_get_ok_slot_%out_ok+0, 0 as u64
|
|
163
|
+
jmp L_ONCE_TRY_GET_DONE_%out_ok
|
|
164
|
+
L_ONCE_TRY_GET_DONE_%out_ok:
|
|
165
|
+
%out_value = load __once_try_get_value_slot_%out_ok+0 as u64
|
|
166
|
+
%out_ok = load __once_try_get_ok_slot_%out_ok+0 as u64
|
|
167
|
+
!__once_try_get_ready_%out_ok
|
|
168
|
+
!__once_try_get_state_%out_ok
|
|
169
|
+
[END_MACRO]
|
|
170
|
+
|
|
171
|
+
[MACRO] ONCE_GET_UNCHECKED %out_value, %once_reg
|
|
172
|
+
%out_value = load %once_reg+Once_value as u64
|
|
173
|
+
[END_MACRO]
|
|
174
|
+
|
|
175
|
+
[MACRO] ONCE_GET_MUT %out_ok, %out_ptr, %once_reg
|
|
176
|
+
__once_get_mut_ok_slot_%out_ok = stack_alloc 8
|
|
177
|
+
__once_get_mut_ptr_slot_%out_ok = stack_alloc 8
|
|
178
|
+
__once_get_mut_state_%out_ok = atomic_load %once_reg+Once_state as u32 acquire
|
|
179
|
+
__once_get_mut_ready_%out_ok = eq __once_get_mut_state_%out_ok, Once_STATE_READY
|
|
180
|
+
br __once_get_mut_ready_%out_ok -> L_ONCE_GET_MUT_READY_%out_ok, L_ONCE_GET_MUT_EMPTY_%out_ok
|
|
181
|
+
L_ONCE_GET_MUT_READY_%out_ok:
|
|
182
|
+
__once_get_mut_ptr_%out_ok = ptr_add %once_reg, Once_value
|
|
183
|
+
store __once_get_mut_ptr_slot_%out_ok+0, __once_get_mut_ptr_%out_ok as ptr
|
|
184
|
+
store __once_get_mut_ok_slot_%out_ok+0, 1 as u64
|
|
185
|
+
!__once_get_mut_ptr_%out_ok
|
|
186
|
+
jmp L_ONCE_GET_MUT_DONE_%out_ok
|
|
187
|
+
L_ONCE_GET_MUT_EMPTY_%out_ok:
|
|
188
|
+
store __once_get_mut_ptr_slot_%out_ok+0, 0 as ptr
|
|
189
|
+
store __once_get_mut_ok_slot_%out_ok+0, 0 as u64
|
|
190
|
+
jmp L_ONCE_GET_MUT_DONE_%out_ok
|
|
191
|
+
L_ONCE_GET_MUT_DONE_%out_ok:
|
|
192
|
+
%out_ptr = load __once_get_mut_ptr_slot_%out_ok+0 as ptr
|
|
193
|
+
%out_ok = load __once_get_mut_ok_slot_%out_ok+0 as u64
|
|
194
|
+
!__once_get_mut_ready_%out_ok
|
|
195
|
+
!__once_get_mut_state_%out_ok
|
|
196
|
+
[END_MACRO]
|
|
197
|
+
|
|
198
|
+
[MACRO] ONCE_GET %out_value, %once_reg
|
|
199
|
+
EXPAND ONCE_WAIT_READY %once_reg
|
|
200
|
+
%out_value = load %once_reg+Once_value as u64
|
|
201
|
+
[END_MACRO]
|
|
202
|
+
|
|
203
|
+
[MACRO] ONCE_TAKE %out_ok, %out_value, %once_reg
|
|
204
|
+
__once_take_ok_slot_%out_ok = stack_alloc 8
|
|
205
|
+
__once_take_value_slot_%out_ok = stack_alloc 8
|
|
206
|
+
store __once_take_ok_slot_%out_ok+0, 0 as u64
|
|
207
|
+
store __once_take_value_slot_%out_ok+0, 0 as u64
|
|
208
|
+
__once_take_state_%out_ok = atomic_load %once_reg+Once_state as u32 acquire
|
|
209
|
+
__once_take_ready_%out_ok = eq __once_take_state_%out_ok, Once_STATE_READY
|
|
210
|
+
br __once_take_ready_%out_ok -> L_ONCE_TAKE_CLAIM_%out_ok, L_ONCE_TAKE_EMPTY_%out_ok
|
|
211
|
+
L_ONCE_TAKE_CLAIM_%out_ok:
|
|
212
|
+
__once_take_claimed_state_%out_ok, __once_take_claimed_%out_ok = cmpxchg %once_reg+Once_state, Once_STATE_READY, Once_STATE_RUNNING as u32 acq_rel acquire
|
|
213
|
+
br __once_take_claimed_%out_ok -> L_ONCE_TAKE_READY_%out_ok, L_ONCE_TAKE_CLAIM_FAILED_%out_ok
|
|
214
|
+
L_ONCE_TAKE_READY_%out_ok:
|
|
215
|
+
__once_take_value_%out_ok = load %once_reg+Once_value as u64
|
|
216
|
+
store __once_take_value_slot_%out_ok+0, __once_take_value_%out_ok as u64
|
|
217
|
+
store %once_reg+Once_value, 0 as u64
|
|
218
|
+
atomic_store %once_reg+Once_state, Once_STATE_UNINIT as u32 release
|
|
219
|
+
store __once_take_ok_slot_%out_ok+0, 1 as u64
|
|
220
|
+
!__once_take_value_%out_ok
|
|
221
|
+
!__once_take_claimed_state_%out_ok
|
|
222
|
+
!__once_take_claimed_%out_ok
|
|
223
|
+
jmp L_ONCE_TAKE_DONE_%out_ok
|
|
224
|
+
L_ONCE_TAKE_CLAIM_FAILED_%out_ok:
|
|
225
|
+
!__once_take_claimed_state_%out_ok
|
|
226
|
+
!__once_take_claimed_%out_ok
|
|
227
|
+
jmp L_ONCE_TAKE_EMPTY_%out_ok
|
|
228
|
+
L_ONCE_TAKE_EMPTY_%out_ok:
|
|
229
|
+
jmp L_ONCE_TAKE_DONE_%out_ok
|
|
230
|
+
L_ONCE_TAKE_DONE_%out_ok:
|
|
231
|
+
%out_value = load __once_take_value_slot_%out_ok+0 as u64
|
|
232
|
+
%out_ok = load __once_take_ok_slot_%out_ok+0 as u64
|
|
233
|
+
!__once_take_ready_%out_ok
|
|
234
|
+
!__once_take_state_%out_ok
|
|
235
|
+
[END_MACRO]
|
|
236
|
+
|
|
237
|
+
[MACRO] ONCE_INTO_INNER %out_ok, %out_value, %once_reg
|
|
238
|
+
__once_inner_ok_slot_%out_ok = stack_alloc 8
|
|
239
|
+
__once_inner_value_slot_%out_ok = stack_alloc 8
|
|
240
|
+
__once_inner_state_%out_ok = atomic_load %once_reg+Once_state as u32 acquire
|
|
241
|
+
__once_inner_ready_%out_ok = eq __once_inner_state_%out_ok, Once_STATE_READY
|
|
242
|
+
br __once_inner_ready_%out_ok -> L_ONCE_INNER_READY_%out_ok, L_ONCE_INNER_EMPTY_%out_ok
|
|
243
|
+
L_ONCE_INNER_READY_%out_ok:
|
|
244
|
+
__once_inner_value_%out_ok = load %once_reg+Once_value as u64
|
|
245
|
+
store __once_inner_value_slot_%out_ok+0, __once_inner_value_%out_ok as u64
|
|
246
|
+
store __once_inner_ok_slot_%out_ok+0, 1 as u64
|
|
247
|
+
!__once_inner_value_%out_ok
|
|
248
|
+
jmp L_ONCE_INNER_DONE_%out_ok
|
|
249
|
+
L_ONCE_INNER_EMPTY_%out_ok:
|
|
250
|
+
store __once_inner_value_slot_%out_ok+0, 0 as u64
|
|
251
|
+
store __once_inner_ok_slot_%out_ok+0, 0 as u64
|
|
252
|
+
jmp L_ONCE_INNER_DONE_%out_ok
|
|
253
|
+
L_ONCE_INNER_DONE_%out_ok:
|
|
254
|
+
%out_value = load __once_inner_value_slot_%out_ok+0 as u64
|
|
255
|
+
%out_ok = load __once_inner_ok_slot_%out_ok+0 as u64
|
|
256
|
+
!__once_inner_ready_%out_ok
|
|
257
|
+
!__once_inner_state_%out_ok
|
|
258
|
+
!%once_reg
|
|
259
|
+
[END_MACRO]
|
|
260
|
+
|
|
261
|
+
[MACRO] ONCE_GET_OR_INIT %out_value, %once_reg, %init_fn
|
|
262
|
+
__once_owner = call @__once_try_claim(&%once_reg)
|
|
263
|
+
br __once_owner -> L_ONCE_GET_OR_INIT_INIT_%out_value, L_ONCE_GET_OR_INIT_READY_%out_value
|
|
264
|
+
L_ONCE_GET_OR_INIT_INIT_%out_value:
|
|
265
|
+
__once_init_value = call %init_fn()
|
|
266
|
+
EXPAND ONCE_PUBLISH %once_reg, __once_init_value
|
|
267
|
+
%out_value = __once_init_value
|
|
268
|
+
!__once_owner
|
|
269
|
+
jmp L_ONCE_GET_OR_INIT_DONE_%out_value
|
|
270
|
+
L_ONCE_GET_OR_INIT_READY_%out_value:
|
|
271
|
+
%out_value = load %once_reg+Once_value as u64
|
|
272
|
+
!__once_owner
|
|
273
|
+
jmp L_ONCE_GET_OR_INIT_DONE_%out_value
|
|
274
|
+
L_ONCE_GET_OR_INIT_DONE_%out_value:
|
|
275
|
+
[END_MACRO]
|
|
276
|
+
|
|
277
|
+
// Concrete LazyLock-style aliases over the existing Once/OnceLock u64 cell.
|
|
278
|
+
// Callers still provide an explicit init function register; this is not a
|
|
279
|
+
// generic type holding a function pointer object.
|
|
280
|
+
|
|
281
|
+
[MACRO] LAZY_LOCK_NEW %out_lazy
|
|
282
|
+
EXPAND ONCE_NEW %out_lazy
|
|
283
|
+
[END_MACRO]
|
|
284
|
+
|
|
285
|
+
[MACRO] LAZY_LOCK_FORCE %out_value, %lazy_reg, %init_fn
|
|
286
|
+
EXPAND ONCE_GET_OR_INIT %out_value, %lazy_reg, %init_fn
|
|
287
|
+
[END_MACRO]
|
|
288
|
+
|
|
289
|
+
[MACRO] LAZY_LOCK_GET %out_ok, %out_value, %lazy_reg
|
|
290
|
+
EXPAND ONCE_TRY_GET %out_ok, %out_value, %lazy_reg
|
|
291
|
+
[END_MACRO]
|
|
292
|
+
|
|
293
|
+
[MACRO] LAZY_LOCK_IS_READY %out_ready, %lazy_reg
|
|
294
|
+
EXPAND ONCE_IS_READY %out_ready, %lazy_reg
|
|
295
|
+
[END_MACRO]
|
|
296
|
+
|
|
297
|
+
[MACRO] LAZY_LOCK_INTO_INNER %out_ok, %out_value, %lazy_reg
|
|
298
|
+
EXPAND ONCE_INTO_INNER %out_ok, %out_value, %lazy_reg
|
|
299
|
+
[END_MACRO]
|
|
300
|
+
|
|
301
|
+
// OnceLock-named aliases over the concrete ONCE_* u64 cell facade.
|
|
302
|
+
|
|
303
|
+
[MACRO] ONCE_LOCK_NEW %out_once
|
|
304
|
+
EXPAND ONCE_NEW %out_once
|
|
305
|
+
[END_MACRO]
|
|
306
|
+
|
|
307
|
+
[MACRO] ONCE_LOCK_IS_READY %out_ready, %once_reg
|
|
308
|
+
EXPAND ONCE_IS_READY %out_ready, %once_reg
|
|
309
|
+
[END_MACRO]
|
|
310
|
+
|
|
311
|
+
[MACRO] ONCE_LOCK_SET %out_ok, %once_reg, %value
|
|
312
|
+
EXPAND ONCE_SET %out_ok, %once_reg, %value
|
|
313
|
+
[END_MACRO]
|
|
314
|
+
|
|
315
|
+
[MACRO] ONCE_LOCK_TRY_GET %out_ok, %out_value, %once_reg
|
|
316
|
+
EXPAND ONCE_TRY_GET %out_ok, %out_value, %once_reg
|
|
317
|
+
[END_MACRO]
|
|
318
|
+
|
|
319
|
+
[MACRO] ONCE_LOCK_GET %out_value, %once_reg
|
|
320
|
+
EXPAND ONCE_GET %out_value, %once_reg
|
|
321
|
+
[END_MACRO]
|
|
322
|
+
|
|
323
|
+
[MACRO] ONCE_LOCK_GET_OR_INIT %out_value, %once_reg, %init_fn
|
|
324
|
+
EXPAND ONCE_GET_OR_INIT %out_value, %once_reg, %init_fn
|
|
325
|
+
[END_MACRO]
|
|
326
|
+
|
|
327
|
+
[MACRO] ONCE_LOCK_TAKE %out_ok, %out_value, %once_reg
|
|
328
|
+
EXPAND ONCE_TAKE %out_ok, %out_value, %once_reg
|
|
329
|
+
[END_MACRO]
|
|
330
|
+
|
|
331
|
+
[MACRO] ONCE_LOCK_INTO_INNER %out_ok, %out_value, %once_reg
|
|
332
|
+
EXPAND ONCE_INTO_INNER %out_ok, %out_value, %once_reg
|
|
333
|
+
[END_MACRO]
|
|
334
|
+
|
|
335
|
+
[MACRO] ONCE_DEFAULT %out_once
|
|
336
|
+
EXPAND ONCE_NEW %out_once
|
|
337
|
+
[END_MACRO]
|
|
338
|
+
|
|
339
|
+
[MACRO] ONCE_LOCK_DEFAULT %out_once
|
|
340
|
+
EXPAND ONCE_LOCK_NEW %out_once
|
|
341
|
+
[END_MACRO]
|
|
342
|
+
|
|
343
|
+
[MACRO] LAZY_LOCK_DEFAULT %out_once
|
|
344
|
+
EXPAND LAZY_LOCK_NEW %out_once
|
|
345
|
+
[END_MACRO]
|
|
346
|
+
|
|
347
|
+
// Rust-style call_once / call_once_force name aliases over get_or_init / publish paths.
|
|
348
|
+
[MACRO] ONCE_CALL_ONCE %out_value, %once_reg, %init_fn
|
|
349
|
+
EXPAND ONCE_GET_OR_INIT %out_value, %once_reg, %init_fn
|
|
350
|
+
[END_MACRO]
|
|
351
|
+
|
|
352
|
+
[MACRO] ONCE_LOCK_CALL_ONCE %out_value, %once_reg, %init_fn
|
|
353
|
+
EXPAND ONCE_LOCK_GET_OR_INIT %out_value, %once_reg, %init_fn
|
|
354
|
+
[END_MACRO]
|
|
355
|
+
|
|
356
|
+
// Force-style: always invoke init when not ready; same as get_or_init for concrete cell.
|
|
357
|
+
[MACRO] ONCE_CALL_ONCE_FORCE %out_value, %once_reg, %init_fn
|
|
358
|
+
EXPAND ONCE_GET_OR_INIT %out_value, %once_reg, %init_fn
|
|
359
|
+
[END_MACRO]
|
|
360
|
+
|
|
361
|
+
[MACRO] ONCE_LOCK_WAIT %out_value, %once_reg
|
|
362
|
+
EXPAND ONCE_LOCK_GET %out_value, %once_reg
|
|
363
|
+
[END_MACRO]
|
|
364
|
+
|
|
365
|
+
[MACRO] ONCE_IS_COMPLETED %out_ready, %once_reg
|
|
366
|
+
EXPAND ONCE_IS_READY %out_ready, %once_reg
|
|
367
|
+
[END_MACRO]
|
|
368
|
+
|
|
369
|
+
[MACRO] ONCE_LOCK_IS_COMPLETED %out_ready, %once_reg
|
|
370
|
+
EXPAND ONCE_LOCK_IS_READY %out_ready, %once_reg
|
|
371
|
+
[END_MACRO]
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#def Once_SIZE = 16
|
|
2
|
+
#def Once_state = +0
|
|
3
|
+
#def Once_value = +8
|
|
4
|
+
#def Once_STATE_UNINIT = 0
|
|
5
|
+
#def Once_STATE_RUNNING = 1
|
|
6
|
+
#def Once_STATE_READY = 2
|
|
7
|
+
|
|
8
|
+
#def OnceState_SIZE = 8
|
|
9
|
+
#def OnceState_ALIGN = 4
|
|
10
|
+
#def OnceState_poisoned = +0
|
|
11
|
+
#def OnceState_set_state_to = +4
|
|
12
|
+
#def OnceState_STATE_COMPLETE = 0
|
|
13
|
+
#def OnceState_STATE_RUNNING = 1
|
|
14
|
+
#def OnceState_STATE_POISONED = 2
|
|
15
|
+
#def OnceState_STATE_INCOMPLETE = 3
|
|
16
|
+
#def OnceState_STATE_QUEUED = 4
|
|
17
|
+
#def OnceState_STATE_MASK = 3
|
|
18
|
+
|
|
19
|
+
#def OnceLock_SIZE = 16
|
|
20
|
+
#def OnceLock_state = +0
|
|
21
|
+
#def OnceLock_value = +8
|
|
22
|
+
#def ONCE_LOCK_STATE_UNINIT = Once_STATE_UNINIT
|
|
23
|
+
#def ONCE_LOCK_STATE_RUNNING = Once_STATE_RUNNING
|
|
24
|
+
#def ONCE_LOCK_STATE_READY = Once_STATE_READY
|
|
25
|
+
|
|
26
|
+
#def LazyLock_SIZE = 16
|
|
27
|
+
#def LazyLock_state = +0
|
|
28
|
+
#def LazyLock_value = +8
|
|
29
|
+
#def LAZY_LOCK_STATE_UNINIT = Once_STATE_UNINIT
|
|
30
|
+
#def LAZY_LOCK_STATE_RUNNING = Once_STATE_RUNNING
|
|
31
|
+
#def LAZY_LOCK_STATE_READY = Once_STATE_READY
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
@import "poison.sal"
|
|
2
|
+
|
|
3
|
+
[MACRO] POISON_ERROR_NEW %out_error, %data
|
|
4
|
+
%out_error = alloc PoisonErrorU64_SIZE
|
|
5
|
+
store %out_error+PoisonErrorU64_data, %data as u64
|
|
6
|
+
[END_MACRO]
|
|
7
|
+
|
|
8
|
+
[MACRO] POISON_ERROR_DATA %out_data, %error_reg
|
|
9
|
+
%out_data = load %error_reg+PoisonErrorU64_data as u64
|
|
10
|
+
[END_MACRO]
|
|
11
|
+
|
|
12
|
+
[MACRO] TRY_LOCK_ERROR_NEW %out_error, %kind, %data
|
|
13
|
+
%out_error = alloc TryLockErrorU64_SIZE
|
|
14
|
+
store %out_error+TryLockErrorU64_kind, %kind as u64
|
|
15
|
+
store %out_error+TryLockErrorU64_data, %data as u64
|
|
16
|
+
[END_MACRO]
|
|
17
|
+
|
|
18
|
+
[MACRO] TRY_LOCK_ERROR_KIND %out_kind, %error_reg
|
|
19
|
+
%out_kind = load %error_reg+TryLockErrorU64_kind as u64
|
|
20
|
+
[END_MACRO]
|
|
21
|
+
|
|
22
|
+
[MACRO] TRY_LOCK_ERROR_DATA %out_data, %error_reg
|
|
23
|
+
%out_data = load %error_reg+TryLockErrorU64_data as u64
|
|
24
|
+
[END_MACRO]
|
|
25
|
+
|
|
26
|
+
[MACRO] TRY_LOCK_ERROR_IS_POISONED %out_bool, %error_reg
|
|
27
|
+
__try_lock_error_kind_%out_bool = load %error_reg+TryLockErrorU64_kind as u64
|
|
28
|
+
%out_bool = eq __try_lock_error_kind_%out_bool, TRY_LOCK_ERROR_POISONED
|
|
29
|
+
!__try_lock_error_kind_%out_bool
|
|
30
|
+
[END_MACRO]
|
|
31
|
+
|
|
32
|
+
[MACRO] TRY_LOCK_ERROR_IS_WOULD_BLOCK %out_bool, %error_reg
|
|
33
|
+
__try_lock_error_kind_block_%out_bool = load %error_reg+TryLockErrorU64_kind as u64
|
|
34
|
+
%out_bool = eq __try_lock_error_kind_block_%out_bool, TRY_LOCK_ERROR_WOULD_BLOCK
|
|
35
|
+
!__try_lock_error_kind_block_%out_bool
|
|
36
|
+
[END_MACRO]
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#def PoisonErrorU64_SIZE = 8
|
|
2
|
+
#def PoisonErrorU64_ALIGN = 8
|
|
3
|
+
#def PoisonErrorU64_data = +0
|
|
4
|
+
|
|
5
|
+
#def TryLockErrorU64_SIZE = 16
|
|
6
|
+
#def TryLockErrorU64_ALIGN = 8
|
|
7
|
+
#def TryLockErrorU64_kind = +0
|
|
8
|
+
#def TryLockErrorU64_data = +8
|
|
9
|
+
#def TryLockErrorU64_poison = +8
|
|
10
|
+
#def TRY_LOCK_ERROR_POISONED = 0
|
|
11
|
+
#def TRY_LOCK_ERROR_WOULD_BLOCK = 1
|