@salang/sa 0.1.3 → 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 +13 -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,369 @@
|
|
|
1
|
+
@import "rwlock.sal"
|
|
2
|
+
@import "../time.sai"
|
|
3
|
+
|
|
4
|
+
@__rwlock_release_read(lock: ptr) -> void:
|
|
5
|
+
L_ENTRY:
|
|
6
|
+
readers = atomic_load lock+RwLock_readers as i32 acquire
|
|
7
|
+
had_reader = sgt readers, 0
|
|
8
|
+
br had_reader -> L_RELEASE_CLAIM, L_RELEASE_UNDERFLOW
|
|
9
|
+
|
|
10
|
+
L_RELEASE_CLAIM:
|
|
11
|
+
next_readers = sub readers, 1
|
|
12
|
+
old_readers, released = cmpxchg lock+RwLock_readers, readers, next_readers as i32 acq_rel acquire
|
|
13
|
+
br released -> L_RELEASE_OK, L_RELEASE_RETRY
|
|
14
|
+
|
|
15
|
+
L_RELEASE_RETRY:
|
|
16
|
+
!released
|
|
17
|
+
!old_readers
|
|
18
|
+
!next_readers
|
|
19
|
+
!had_reader
|
|
20
|
+
!readers
|
|
21
|
+
jmp L_ENTRY
|
|
22
|
+
|
|
23
|
+
L_RELEASE_UNDERFLOW:
|
|
24
|
+
!had_reader
|
|
25
|
+
!readers
|
|
26
|
+
panic(1601)
|
|
27
|
+
|
|
28
|
+
L_RELEASE_OK:
|
|
29
|
+
!released
|
|
30
|
+
!old_readers
|
|
31
|
+
!next_readers
|
|
32
|
+
!had_reader
|
|
33
|
+
!readers
|
|
34
|
+
!lock
|
|
35
|
+
return
|
|
36
|
+
|
|
37
|
+
[MACRO] RWLOCK_NEW %out_lock
|
|
38
|
+
%out_lock = alloc RwLock_SIZE
|
|
39
|
+
store %out_lock+RwLock_readers, 0 as i32
|
|
40
|
+
store %out_lock+RwLock_writing, 0 as i32
|
|
41
|
+
[END_MACRO]
|
|
42
|
+
|
|
43
|
+
[MACRO] RWLOCK_NEW_I32 %out_lock, %value
|
|
44
|
+
%out_lock = alloc RwLockI32_SIZE
|
|
45
|
+
store %out_lock+RwLock_readers, 0 as i32
|
|
46
|
+
store %out_lock+RwLock_writing, 0 as i32
|
|
47
|
+
store %out_lock+RwLock_data, %value as i32
|
|
48
|
+
[END_MACRO]
|
|
49
|
+
|
|
50
|
+
[MACRO] RWLOCK_READER_COUNT %out_count, %lock_reg
|
|
51
|
+
%out_count = atomic_load %lock_reg+RwLock_readers as i32 acquire
|
|
52
|
+
[END_MACRO]
|
|
53
|
+
|
|
54
|
+
[MACRO] RWLOCK_IS_WRITING %out_bool, %lock_reg
|
|
55
|
+
__rwlock_writing_state_%out_bool = atomic_load %lock_reg+RwLock_writing as i32 acquire
|
|
56
|
+
%out_bool = ne __rwlock_writing_state_%out_bool, 0
|
|
57
|
+
!__rwlock_writing_state_%out_bool
|
|
58
|
+
[END_MACRO]
|
|
59
|
+
|
|
60
|
+
[MACRO] RWLOCK_IS_UNLOCKED %out_bool, %lock_reg
|
|
61
|
+
__rwlock_readers_state_%out_bool = atomic_load %lock_reg+RwLock_readers as i32 acquire
|
|
62
|
+
__rwlock_writing_state_%out_bool = atomic_load %lock_reg+RwLock_writing as i32 acquire
|
|
63
|
+
__rwlock_no_readers_%out_bool = eq __rwlock_readers_state_%out_bool, 0
|
|
64
|
+
__rwlock_no_writer_%out_bool = eq __rwlock_writing_state_%out_bool, 0
|
|
65
|
+
%out_bool = and __rwlock_no_readers_%out_bool, __rwlock_no_writer_%out_bool
|
|
66
|
+
!__rwlock_no_writer_%out_bool
|
|
67
|
+
!__rwlock_no_readers_%out_bool
|
|
68
|
+
!__rwlock_writing_state_%out_bool
|
|
69
|
+
!__rwlock_readers_state_%out_bool
|
|
70
|
+
[END_MACRO]
|
|
71
|
+
|
|
72
|
+
[MACRO] RWLOCK_TRY_READ_NOERR %out_ok, %out_guard, %lock_reg
|
|
73
|
+
__rwlock_read_ok_slot_%out_ok = alloc 8
|
|
74
|
+
__rwlock_read_guard_slot_%out_ok = alloc 8
|
|
75
|
+
__rwlock_read_writing_%out_ok = atomic_load %lock_reg+RwLock_writing as i32 acquire
|
|
76
|
+
__rwlock_read_can_read_%out_ok = eq __rwlock_read_writing_%out_ok, 0
|
|
77
|
+
br __rwlock_read_can_read_%out_ok -> L_RWLOCK_READ_NOERR_OK_%out_ok, L_RWLOCK_READ_NOERR_FAIL_%out_ok
|
|
78
|
+
L_RWLOCK_READ_NOERR_OK_%out_ok:
|
|
79
|
+
__rwlock_read_old_%out_ok = atomic_rmw_add %lock_reg+RwLock_readers, 1 as i32 acq_rel
|
|
80
|
+
__rwlock_read_after_writing_%out_ok = atomic_load %lock_reg+RwLock_writing as i32 acquire
|
|
81
|
+
__rwlock_read_still_ok_%out_ok = eq __rwlock_read_after_writing_%out_ok, 0
|
|
82
|
+
br __rwlock_read_still_ok_%out_ok -> L_RWLOCK_READ_NOERR_COMMIT_%out_ok, L_RWLOCK_READ_NOERR_ROLLBACK_%out_ok
|
|
83
|
+
L_RWLOCK_READ_NOERR_COMMIT_%out_ok:
|
|
84
|
+
store __rwlock_read_guard_slot_%out_ok+0, %lock_reg as ptr
|
|
85
|
+
store __rwlock_read_ok_slot_%out_ok+0, 1 as u64
|
|
86
|
+
!__rwlock_read_still_ok_%out_ok
|
|
87
|
+
!__rwlock_read_after_writing_%out_ok
|
|
88
|
+
!__rwlock_read_old_%out_ok
|
|
89
|
+
jmp L_RWLOCK_READ_NOERR_DONE_%out_ok
|
|
90
|
+
L_RWLOCK_READ_NOERR_ROLLBACK_%out_ok:
|
|
91
|
+
__rwlock_read_rollback_%out_ok = atomic_rmw_sub %lock_reg+RwLock_readers, 1 as i32 acq_rel
|
|
92
|
+
store __rwlock_read_guard_slot_%out_ok+0, 0 as ptr
|
|
93
|
+
store __rwlock_read_ok_slot_%out_ok+0, 0 as u64
|
|
94
|
+
!__rwlock_read_rollback_%out_ok
|
|
95
|
+
!__rwlock_read_still_ok_%out_ok
|
|
96
|
+
!__rwlock_read_after_writing_%out_ok
|
|
97
|
+
!__rwlock_read_old_%out_ok
|
|
98
|
+
jmp L_RWLOCK_READ_NOERR_DONE_%out_ok
|
|
99
|
+
L_RWLOCK_READ_NOERR_FAIL_%out_ok:
|
|
100
|
+
store __rwlock_read_guard_slot_%out_ok+0, 0 as ptr
|
|
101
|
+
store __rwlock_read_ok_slot_%out_ok+0, 0 as u64
|
|
102
|
+
jmp L_RWLOCK_READ_NOERR_DONE_%out_ok
|
|
103
|
+
L_RWLOCK_READ_NOERR_DONE_%out_ok:
|
|
104
|
+
%out_guard = load __rwlock_read_guard_slot_%out_ok+0 as ptr
|
|
105
|
+
%out_ok = load __rwlock_read_ok_slot_%out_ok+0 as u64
|
|
106
|
+
!__rwlock_read_guard_slot_%out_ok
|
|
107
|
+
!__rwlock_read_ok_slot_%out_ok
|
|
108
|
+
!__rwlock_read_can_read_%out_ok
|
|
109
|
+
!__rwlock_read_writing_%out_ok
|
|
110
|
+
[END_MACRO]
|
|
111
|
+
|
|
112
|
+
[MACRO] RWLOCK_TRY_WRITE_NOERR %out_ok, %out_guard, %lock_reg
|
|
113
|
+
__rwlock_write_ok_slot_%out_ok = alloc 8
|
|
114
|
+
__rwlock_write_guard_slot_%out_ok = alloc 8
|
|
115
|
+
__rwlock_write_writing_%out_ok, __rwlock_write_claim_ok_%out_ok = cmpxchg %lock_reg+RwLock_writing, 0, 1 as i32 acq_rel acquire
|
|
116
|
+
br __rwlock_write_claim_ok_%out_ok -> L_RWLOCK_WRITE_NOERR_CLAIMED_%out_ok, L_RWLOCK_WRITE_NOERR_FAIL_%out_ok
|
|
117
|
+
L_RWLOCK_WRITE_NOERR_CLAIMED_%out_ok:
|
|
118
|
+
__rwlock_write_readers_%out_ok = atomic_load %lock_reg+RwLock_readers as i32 acquire
|
|
119
|
+
__rwlock_write_no_readers_%out_ok = eq __rwlock_write_readers_%out_ok, 0
|
|
120
|
+
br __rwlock_write_no_readers_%out_ok -> L_RWLOCK_WRITE_NOERR_OK_%out_ok, L_RWLOCK_WRITE_NOERR_ROLLBACK_%out_ok
|
|
121
|
+
L_RWLOCK_WRITE_NOERR_OK_%out_ok:
|
|
122
|
+
store __rwlock_write_guard_slot_%out_ok+0, %lock_reg as ptr
|
|
123
|
+
store __rwlock_write_ok_slot_%out_ok+0, 1 as u64
|
|
124
|
+
!__rwlock_write_no_readers_%out_ok
|
|
125
|
+
!__rwlock_write_readers_%out_ok
|
|
126
|
+
jmp L_RWLOCK_WRITE_NOERR_DONE_%out_ok
|
|
127
|
+
L_RWLOCK_WRITE_NOERR_ROLLBACK_%out_ok:
|
|
128
|
+
atomic_store %lock_reg+RwLock_writing, 0 as i32 release
|
|
129
|
+
store __rwlock_write_guard_slot_%out_ok+0, 0 as ptr
|
|
130
|
+
store __rwlock_write_ok_slot_%out_ok+0, 0 as u64
|
|
131
|
+
!__rwlock_write_no_readers_%out_ok
|
|
132
|
+
!__rwlock_write_readers_%out_ok
|
|
133
|
+
jmp L_RWLOCK_WRITE_NOERR_DONE_%out_ok
|
|
134
|
+
L_RWLOCK_WRITE_NOERR_FAIL_%out_ok:
|
|
135
|
+
store __rwlock_write_guard_slot_%out_ok+0, 0 as ptr
|
|
136
|
+
store __rwlock_write_ok_slot_%out_ok+0, 0 as u64
|
|
137
|
+
jmp L_RWLOCK_WRITE_NOERR_DONE_%out_ok
|
|
138
|
+
L_RWLOCK_WRITE_NOERR_DONE_%out_ok:
|
|
139
|
+
%out_guard = load __rwlock_write_guard_slot_%out_ok+0 as ptr
|
|
140
|
+
%out_ok = load __rwlock_write_ok_slot_%out_ok+0 as u64
|
|
141
|
+
!__rwlock_write_guard_slot_%out_ok
|
|
142
|
+
!__rwlock_write_ok_slot_%out_ok
|
|
143
|
+
!__rwlock_write_claim_ok_%out_ok
|
|
144
|
+
!__rwlock_write_writing_%out_ok
|
|
145
|
+
[END_MACRO]
|
|
146
|
+
|
|
147
|
+
[MACRO] RWLOCK_TRY_READ %out_ok, %out_guard, %lock_reg, %err_label
|
|
148
|
+
__rwlock_writing_%out_ok = atomic_load %lock_reg+RwLock_writing as i32 acquire
|
|
149
|
+
__rwlock_can_read_%out_ok = eq __rwlock_writing_%out_ok, 0
|
|
150
|
+
br __rwlock_can_read_%out_ok -> L_RWLOCK_TRY_READ_OK_%out_ok, L_RWLOCK_TRY_READ_FAIL_%out_ok
|
|
151
|
+
L_RWLOCK_TRY_READ_OK_%out_ok:
|
|
152
|
+
__rwlock_readers_%out_ok = atomic_rmw_add %lock_reg+RwLock_readers, 1 as i32 acq_rel
|
|
153
|
+
__rwlock_after_writing_%out_ok = atomic_load %lock_reg+RwLock_writing as i32 acquire
|
|
154
|
+
__rwlock_still_can_read_%out_ok = eq __rwlock_after_writing_%out_ok, 0
|
|
155
|
+
br __rwlock_still_can_read_%out_ok -> L_RWLOCK_TRY_READ_COMMIT_%out_ok, L_RWLOCK_TRY_READ_ROLLBACK_%out_ok
|
|
156
|
+
L_RWLOCK_TRY_READ_COMMIT_%out_ok:
|
|
157
|
+
%out_guard = add %lock_reg, 0
|
|
158
|
+
%out_ok = add 0, 1
|
|
159
|
+
!__rwlock_still_can_read_%out_ok
|
|
160
|
+
!__rwlock_after_writing_%out_ok
|
|
161
|
+
!__rwlock_can_read_%out_ok
|
|
162
|
+
!__rwlock_writing_%out_ok
|
|
163
|
+
!__rwlock_readers_%out_ok
|
|
164
|
+
jmp L_RWLOCK_TRY_READ_END_%out_ok
|
|
165
|
+
L_RWLOCK_TRY_READ_ROLLBACK_%out_ok:
|
|
166
|
+
__rwlock_rollback_%out_ok = atomic_rmw_sub %lock_reg+RwLock_readers, 1 as i32 acq_rel
|
|
167
|
+
%out_guard = add 0, 0
|
|
168
|
+
%out_ok = add 0, 0
|
|
169
|
+
!__rwlock_rollback_%out_ok
|
|
170
|
+
!__rwlock_still_can_read_%out_ok
|
|
171
|
+
!__rwlock_after_writing_%out_ok
|
|
172
|
+
!__rwlock_can_read_%out_ok
|
|
173
|
+
!__rwlock_writing_%out_ok
|
|
174
|
+
!__rwlock_readers_%out_ok
|
|
175
|
+
jmp %err_label
|
|
176
|
+
L_RWLOCK_TRY_READ_FAIL_%out_ok:
|
|
177
|
+
%out_guard = add 0, 0
|
|
178
|
+
%out_ok = add 0, 0
|
|
179
|
+
!__rwlock_can_read_%out_ok
|
|
180
|
+
!__rwlock_writing_%out_ok
|
|
181
|
+
jmp %err_label
|
|
182
|
+
L_RWLOCK_TRY_READ_END_%out_ok:
|
|
183
|
+
[END_MACRO]
|
|
184
|
+
|
|
185
|
+
[MACRO] RWLOCK_TRY_WRITE %out_ok, %out_guard, %lock_reg, %err_label
|
|
186
|
+
__rwlock_writing_%out_ok, __rwlock_claim_ok_%out_ok = cmpxchg %lock_reg+RwLock_writing, 0, 1 as i32 acq_rel acquire
|
|
187
|
+
br __rwlock_claim_ok_%out_ok -> L_RWLOCK_TRY_WRITE_CLAIMED_%out_ok, L_RWLOCK_TRY_WRITE_FAIL_%out_ok
|
|
188
|
+
L_RWLOCK_TRY_WRITE_CLAIMED_%out_ok:
|
|
189
|
+
__rwlock_readers_%out_ok = atomic_load %lock_reg+RwLock_readers as i32 acquire
|
|
190
|
+
__rwlock_no_readers_%out_ok = eq __rwlock_readers_%out_ok, 0
|
|
191
|
+
br __rwlock_no_readers_%out_ok -> L_RWLOCK_TRY_WRITE_OK_%out_ok, L_RWLOCK_TRY_WRITE_ROLLBACK_%out_ok
|
|
192
|
+
L_RWLOCK_TRY_WRITE_OK_%out_ok:
|
|
193
|
+
%out_guard = add %lock_reg, 0
|
|
194
|
+
%out_ok = add 0, 1
|
|
195
|
+
!__rwlock_no_readers_%out_ok
|
|
196
|
+
!__rwlock_readers_%out_ok
|
|
197
|
+
!__rwlock_writing_%out_ok
|
|
198
|
+
!__rwlock_claim_ok_%out_ok
|
|
199
|
+
jmp L_RWLOCK_TRY_WRITE_END_%out_ok
|
|
200
|
+
L_RWLOCK_TRY_WRITE_ROLLBACK_%out_ok:
|
|
201
|
+
atomic_store %lock_reg+RwLock_writing, 0 as i32 release
|
|
202
|
+
%out_guard = add 0, 0
|
|
203
|
+
%out_ok = add 0, 0
|
|
204
|
+
!__rwlock_no_readers_%out_ok
|
|
205
|
+
!__rwlock_readers_%out_ok
|
|
206
|
+
!__rwlock_writing_%out_ok
|
|
207
|
+
!__rwlock_claim_ok_%out_ok
|
|
208
|
+
jmp %err_label
|
|
209
|
+
L_RWLOCK_TRY_WRITE_FAIL_%out_ok:
|
|
210
|
+
%out_guard = add 0, 0
|
|
211
|
+
%out_ok = add 0, 0
|
|
212
|
+
!__rwlock_writing_%out_ok
|
|
213
|
+
!__rwlock_claim_ok_%out_ok
|
|
214
|
+
jmp %err_label
|
|
215
|
+
L_RWLOCK_TRY_WRITE_END_%out_ok:
|
|
216
|
+
[END_MACRO]
|
|
217
|
+
|
|
218
|
+
[MACRO] RWLOCK_RELEASE_READ %lock_reg
|
|
219
|
+
call @__rwlock_release_read(%lock_reg)
|
|
220
|
+
[END_MACRO]
|
|
221
|
+
|
|
222
|
+
[MACRO] RWLOCK_TRY_RELEASE_READ %out_ok, %lock_reg
|
|
223
|
+
L_RWLOCK_TRY_RELEASE_READ_ENTRY_%out_ok:
|
|
224
|
+
__rwlock_try_release_read_state_%out_ok = atomic_load %lock_reg+RwLock_readers as i32 acquire
|
|
225
|
+
__rwlock_try_release_read_has_%out_ok = sgt __rwlock_try_release_read_state_%out_ok, 0
|
|
226
|
+
br __rwlock_try_release_read_has_%out_ok -> L_RWLOCK_TRY_RELEASE_READ_CLAIM_%out_ok, L_RWLOCK_TRY_RELEASE_READ_EMPTY_%out_ok
|
|
227
|
+
L_RWLOCK_TRY_RELEASE_READ_CLAIM_%out_ok:
|
|
228
|
+
__rwlock_try_release_read_next_%out_ok = sub __rwlock_try_release_read_state_%out_ok, 1
|
|
229
|
+
__rwlock_try_release_read_old_%out_ok, %out_ok = cmpxchg %lock_reg+RwLock_readers, __rwlock_try_release_read_state_%out_ok, __rwlock_try_release_read_next_%out_ok as i32 acq_rel acquire
|
|
230
|
+
br %out_ok -> L_RWLOCK_TRY_RELEASE_READ_DONE_%out_ok, L_RWLOCK_TRY_RELEASE_READ_RETRY_%out_ok
|
|
231
|
+
L_RWLOCK_TRY_RELEASE_READ_RETRY_%out_ok:
|
|
232
|
+
!__rwlock_try_release_read_old_%out_ok
|
|
233
|
+
!__rwlock_try_release_read_next_%out_ok
|
|
234
|
+
!__rwlock_try_release_read_has_%out_ok
|
|
235
|
+
!__rwlock_try_release_read_state_%out_ok
|
|
236
|
+
jmp L_RWLOCK_TRY_RELEASE_READ_ENTRY_%out_ok
|
|
237
|
+
L_RWLOCK_TRY_RELEASE_READ_EMPTY_%out_ok:
|
|
238
|
+
%out_ok = add 0, 0
|
|
239
|
+
L_RWLOCK_TRY_RELEASE_READ_DONE_%out_ok:
|
|
240
|
+
!__rwlock_try_release_read_old_%out_ok
|
|
241
|
+
!__rwlock_try_release_read_next_%out_ok
|
|
242
|
+
!__rwlock_try_release_read_has_%out_ok
|
|
243
|
+
!__rwlock_try_release_read_state_%out_ok
|
|
244
|
+
[END_MACRO]
|
|
245
|
+
[MACRO] RWLOCK_RELEASE_WRITE %lock_reg
|
|
246
|
+
atomic_store %lock_reg+RwLock_writing, 0 as i32 release
|
|
247
|
+
[END_MACRO]
|
|
248
|
+
|
|
249
|
+
[MACRO] RWLOCK_TRY_RELEASE_WRITE %out_ok, %lock_reg
|
|
250
|
+
__rwlock_release_state_%out_ok, %out_ok = cmpxchg %lock_reg+RwLock_writing, 1, 0 as i32 acq_rel acquire
|
|
251
|
+
!__rwlock_release_state_%out_ok
|
|
252
|
+
[END_MACRO]
|
|
253
|
+
|
|
254
|
+
[MACRO] RWLOCK_FORCE_UNLOCKED %lock_reg
|
|
255
|
+
atomic_store %lock_reg+RwLock_readers, 0 as i32 release
|
|
256
|
+
atomic_store %lock_reg+RwLock_writing, 0 as i32 release
|
|
257
|
+
[END_MACRO]
|
|
258
|
+
|
|
259
|
+
[MACRO] RWLOCK_DEFAULT %out_lock
|
|
260
|
+
EXPAND RWLOCK_NEW %out_lock
|
|
261
|
+
[END_MACRO]
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
@__rwlock_lock_read_spin(lock: ptr) -> void:
|
|
265
|
+
L_ENTRY:
|
|
266
|
+
backoff_slot = stack_alloc 8
|
|
267
|
+
store backoff_slot+0, 1 as u64
|
|
268
|
+
jmp L_TRY
|
|
269
|
+
L_TRY:
|
|
270
|
+
writing = atomic_load lock+RwLock_writing as i32 acquire
|
|
271
|
+
busy = ne writing, 0
|
|
272
|
+
!writing
|
|
273
|
+
br busy -> L_BUSY_WAIT, L_CLAIM
|
|
274
|
+
L_BUSY_WAIT:
|
|
275
|
+
!busy
|
|
276
|
+
jmp L_WAIT
|
|
277
|
+
L_CLAIM:
|
|
278
|
+
!busy
|
|
279
|
+
old = atomic_rmw_add lock+RwLock_readers, 1 as i32 acq_rel
|
|
280
|
+
writing2 = atomic_load lock+RwLock_writing as i32 acquire
|
|
281
|
+
still_busy = ne writing2, 0
|
|
282
|
+
!writing2
|
|
283
|
+
!old
|
|
284
|
+
br still_busy -> L_ROLLBACK, L_DONE
|
|
285
|
+
L_ROLLBACK:
|
|
286
|
+
rolled = atomic_rmw_sub lock+RwLock_readers, 1 as i32 acq_rel
|
|
287
|
+
!rolled
|
|
288
|
+
!still_busy
|
|
289
|
+
jmp L_WAIT
|
|
290
|
+
L_WAIT:
|
|
291
|
+
backoff_ns = load backoff_slot+0 as u64
|
|
292
|
+
call @sa_time_sleep_ns(backoff_ns)
|
|
293
|
+
at_limit = uge backoff_ns, 1024
|
|
294
|
+
br at_limit -> L_KEEP, L_GROW
|
|
295
|
+
L_GROW:
|
|
296
|
+
next = shl backoff_ns, 1
|
|
297
|
+
store backoff_slot+0, next as u64
|
|
298
|
+
!next
|
|
299
|
+
!at_limit
|
|
300
|
+
!backoff_ns
|
|
301
|
+
jmp L_TRY
|
|
302
|
+
L_KEEP:
|
|
303
|
+
!at_limit
|
|
304
|
+
!backoff_ns
|
|
305
|
+
jmp L_TRY
|
|
306
|
+
L_DONE:
|
|
307
|
+
!still_busy
|
|
308
|
+
!lock
|
|
309
|
+
return
|
|
310
|
+
|
|
311
|
+
@__rwlock_lock_write_spin(lock: ptr) -> void:
|
|
312
|
+
L_ENTRY:
|
|
313
|
+
backoff_slot = stack_alloc 8
|
|
314
|
+
store backoff_slot+0, 1 as u64
|
|
315
|
+
jmp L_WTRY
|
|
316
|
+
L_WTRY:
|
|
317
|
+
old_w, ok = cmpxchg lock+RwLock_writing, 0, 1 as i32 acq_rel acquire
|
|
318
|
+
br ok -> L_WCHECK, L_WFAIL
|
|
319
|
+
L_WFAIL:
|
|
320
|
+
!ok
|
|
321
|
+
!old_w
|
|
322
|
+
jmp L_WWAIT
|
|
323
|
+
L_WCHECK:
|
|
324
|
+
!ok
|
|
325
|
+
!old_w
|
|
326
|
+
readers = atomic_load lock+RwLock_readers as i32 acquire
|
|
327
|
+
no_readers = eq readers, 0
|
|
328
|
+
!readers
|
|
329
|
+
br no_readers -> L_WDONE, L_WABORT
|
|
330
|
+
L_WABORT:
|
|
331
|
+
atomic_store lock+RwLock_writing, 0 as i32 release
|
|
332
|
+
!no_readers
|
|
333
|
+
jmp L_WWAIT
|
|
334
|
+
L_WWAIT:
|
|
335
|
+
backoff_ns = load backoff_slot+0 as u64
|
|
336
|
+
call @sa_time_sleep_ns(backoff_ns)
|
|
337
|
+
at_limit = uge backoff_ns, 1024
|
|
338
|
+
br at_limit -> L_WKEEP, L_WGROW
|
|
339
|
+
L_WGROW:
|
|
340
|
+
next = shl backoff_ns, 1
|
|
341
|
+
store backoff_slot+0, next as u64
|
|
342
|
+
!next
|
|
343
|
+
!at_limit
|
|
344
|
+
!backoff_ns
|
|
345
|
+
jmp L_WTRY
|
|
346
|
+
L_WKEEP:
|
|
347
|
+
!at_limit
|
|
348
|
+
!backoff_ns
|
|
349
|
+
jmp L_WTRY
|
|
350
|
+
L_WDONE:
|
|
351
|
+
!no_readers
|
|
352
|
+
!lock
|
|
353
|
+
return
|
|
354
|
+
|
|
355
|
+
[MACRO] RWLOCK_READ %lock_reg
|
|
356
|
+
call @__rwlock_lock_read_spin(%lock_reg)
|
|
357
|
+
[END_MACRO]
|
|
358
|
+
|
|
359
|
+
[MACRO] RWLOCK_WRITE %lock_reg
|
|
360
|
+
call @__rwlock_lock_write_spin(%lock_reg)
|
|
361
|
+
[END_MACRO]
|
|
362
|
+
|
|
363
|
+
[MACRO] RWLOCK_LOCK_READ %lock_reg
|
|
364
|
+
EXPAND RWLOCK_READ %lock_reg
|
|
365
|
+
[END_MACRO]
|
|
366
|
+
|
|
367
|
+
[MACRO] RWLOCK_LOCK_WRITE %lock_reg
|
|
368
|
+
EXPAND RWLOCK_WRITE %lock_reg
|
|
369
|
+
[END_MACRO]
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#def RwLock_SIZE = 8
|
|
2
|
+
#def RwLock_readers = +0
|
|
3
|
+
#def RwLock_writing = +4
|
|
4
|
+
#def RwLock_data = +8
|
|
5
|
+
#def RwLockI32_SIZE = 16
|
|
6
|
+
|
|
7
|
+
#def RwLockReadGuard_SIZE = 8
|
|
8
|
+
#def RwLockReadGuard_rwlock = +0
|
|
9
|
+
#def RwLockReadGuard_data = +8
|
|
10
|
+
|
|
11
|
+
#def RwLockWriteGuard_SIZE = 8
|
|
12
|
+
#def RwLockWriteGuard_rwlock = +0
|
|
13
|
+
#def RwLockWriteGuard_data = +8
|
package/sa_std/task.sa
ADDED
package/sa_std/task.sal
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import "core/task.sal"
|
package/sa_std/term.sa
ADDED
package/sa_std/term.sai
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// SA-facing contracts for terminal control and epoll-backed event loops.
|
|
2
|
+
// Raw-mode sessions and epoll instances are opaque owned ptr values and must be closed explicitly.
|
|
3
|
+
@extern sa_term_raw_enter(handle: ptr) -> ^ptr!
|
|
4
|
+
@extern sa_term_raw_leave(^session: ptr) -> i32!
|
|
5
|
+
@extern sa_term_winsize(handle: ptr, &out_size: ptr) -> i32!
|
|
6
|
+
|
|
7
|
+
@extern sa_term_epoll_create(flags: u32) -> ^ptr!
|
|
8
|
+
@extern sa_term_epoll_ctl(epoll: ptr, op: u32, target: ptr, events: u32, data: u64) -> i32!
|
|
9
|
+
@extern sa_term_epoll_wait(epoll: ptr, &events: ptr, max_events: u64, timeout_ms: i32, &out_count: ptr) -> i32!
|
|
10
|
+
@extern sa_term_epoll_close(^epoll: ptr) -> i32!
|
package/sa_std/term.sal
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#def SA_TERM_OK = 0
|
|
2
|
+
#def SA_TERM_ERR_UNKNOWN = 1
|
|
3
|
+
#def SA_TERM_ERR_INVALID_ARGUMENT = 2
|
|
4
|
+
#def SA_TERM_ERR_INVALID_HANDLE = 3
|
|
5
|
+
#def SA_TERM_ERR_UNSUPPORTED = 4
|
|
6
|
+
#def SA_TERM_ERR_NO_MEMORY = 5
|
|
7
|
+
#def SA_TERM_ERR_IO = 6
|
|
8
|
+
|
|
9
|
+
#def SA_TERM_EPOLL_CTL_ADD = 1
|
|
10
|
+
#def SA_TERM_EPOLL_CTL_DEL = 2
|
|
11
|
+
#def SA_TERM_EPOLL_CTL_MOD = 3
|
|
12
|
+
|
|
13
|
+
#def SA_TERM_EPOLL_CLOEXEC = 1
|
|
14
|
+
#def SA_TERM_EPOLLIN = 0x001
|
|
15
|
+
#def SA_TERM_EPOLLPRI = 0x002
|
|
16
|
+
#def SA_TERM_EPOLLOUT = 0x004
|
|
17
|
+
#def SA_TERM_EPOLLERR = 0x008
|
|
18
|
+
#def SA_TERM_EPOLLHUP = 0x010
|
|
19
|
+
#def SA_TERM_EPOLLRDHUP = 0x2000
|
|
20
|
+
#def SA_TERM_EPOLLEXCLUSIVE = 0x10000000
|
|
21
|
+
#def SA_TERM_EPOLLWAKEUP = 0x20000000
|
|
22
|
+
#def SA_TERM_EPOLLONESHOT = 0x40000000
|
|
23
|
+
#def SA_TERM_EPOLLET = 0x80000000
|
|
24
|
+
|
|
25
|
+
#def SaTermWinsize_SIZE = 8
|
|
26
|
+
#def SaTermWinsize_row = +0
|
|
27
|
+
#def SaTermWinsize_col = +2
|
|
28
|
+
#def SaTermWinsize_xpixel = +4
|
|
29
|
+
#def SaTermWinsize_ypixel = +6
|
|
30
|
+
|
|
31
|
+
#def SaTermEpollEvent_SIZE = 16
|
|
32
|
+
#def SaTermEpollEvent_events = +0
|
|
33
|
+
#def SaTermEpollEvent_data = +8
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
@extern sa_assert_eq_i64(actual: i64, expected: i64, code: i32) -> void
|
|
2
|
+
@extern sa_assert_eq_i64_at(actual: i64, expected: i64, code: i32, &file: ptr, file_len: u64, line: u32, col: u32) -> void
|
|
3
|
+
@extern sa_test_debug_i64(&name: ptr, name_len: u64, value: i64) -> void
|
|
4
|
+
@extern sa_test_fallible_i32_value(value: i32) -> i32!
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
@import "mock_io.sal"
|
|
2
|
+
|
|
3
|
+
@export sa_mock_io_init(&mock: ptr, &buf: ptr, cap: u64) -> void:
|
|
4
|
+
L_ENTRY:
|
|
5
|
+
store mock+MockIo_buf, buf as ptr
|
|
6
|
+
store mock+MockIo_cap, cap as u64
|
|
7
|
+
store mock+MockIo_len, 0 as u64
|
|
8
|
+
store mock+MockIo_pos, 0 as u64
|
|
9
|
+
!cap
|
|
10
|
+
!buf
|
|
11
|
+
!mock
|
|
12
|
+
return
|
|
13
|
+
|
|
14
|
+
@export sa_mock_io_rewind(&mock: ptr) -> void:
|
|
15
|
+
L_ENTRY:
|
|
16
|
+
store mock+MockIo_pos, 0 as u64
|
|
17
|
+
!mock
|
|
18
|
+
return
|
|
19
|
+
|
|
20
|
+
@export sa_mock_io_len(&mock: ptr) -> u64:
|
|
21
|
+
L_ENTRY:
|
|
22
|
+
len = load mock+MockIo_len as u64
|
|
23
|
+
!mock
|
|
24
|
+
return len
|
|
25
|
+
|
|
26
|
+
@export sa_mock_io_pos(&mock: ptr) -> u64:
|
|
27
|
+
L_ENTRY:
|
|
28
|
+
pos = load mock+MockIo_pos as u64
|
|
29
|
+
!mock
|
|
30
|
+
return pos
|
|
31
|
+
|
|
32
|
+
@export sa_mock_io_write(&mock: ptr, &src: ptr, requested: u64) -> u64:
|
|
33
|
+
L_ENTRY:
|
|
34
|
+
cap = load mock+MockIo_cap as u64
|
|
35
|
+
len = load mock+MockIo_len as u64
|
|
36
|
+
room = sub cap, len
|
|
37
|
+
fits = ule requested, room
|
|
38
|
+
br fits -> L_USE_REQUESTED, L_USE_ROOM
|
|
39
|
+
|
|
40
|
+
L_USE_REQUESTED:
|
|
41
|
+
count = add requested, 0
|
|
42
|
+
jmp L_COPY_INIT
|
|
43
|
+
|
|
44
|
+
L_USE_ROOM:
|
|
45
|
+
count = add room, 0
|
|
46
|
+
jmp L_COPY_INIT
|
|
47
|
+
|
|
48
|
+
L_COPY_INIT:
|
|
49
|
+
buf = load mock+MockIo_buf as ptr
|
|
50
|
+
offset_slot = stack_alloc 8
|
|
51
|
+
store offset_slot+0, 0 as u64
|
|
52
|
+
jmp L_COPY_HEAD
|
|
53
|
+
|
|
54
|
+
L_COPY_HEAD:
|
|
55
|
+
offset = load offset_slot+0 as u64
|
|
56
|
+
done = eq offset, count
|
|
57
|
+
br done -> L_DONE, L_COPY_BODY
|
|
58
|
+
|
|
59
|
+
L_COPY_BODY:
|
|
60
|
+
src_ip = ptr_add src, offset
|
|
61
|
+
dst_offset = add len, offset
|
|
62
|
+
dst_ip = ptr_add buf, dst_offset
|
|
63
|
+
byte = load src_ip+0 as u8
|
|
64
|
+
store dst_ip+0, byte as u8
|
|
65
|
+
next = add offset, 1
|
|
66
|
+
store offset_slot+0, next as u64
|
|
67
|
+
!src_ip
|
|
68
|
+
!dst_offset
|
|
69
|
+
!dst_ip
|
|
70
|
+
!byte
|
|
71
|
+
!offset
|
|
72
|
+
!done
|
|
73
|
+
!next
|
|
74
|
+
jmp L_COPY_HEAD
|
|
75
|
+
|
|
76
|
+
L_DONE:
|
|
77
|
+
new_len = add len, count
|
|
78
|
+
store mock+MockIo_len, new_len as u64
|
|
79
|
+
!new_len
|
|
80
|
+
!offset
|
|
81
|
+
!done
|
|
82
|
+
!buf
|
|
83
|
+
!cap
|
|
84
|
+
!len
|
|
85
|
+
!room
|
|
86
|
+
!fits
|
|
87
|
+
!requested
|
|
88
|
+
!src
|
|
89
|
+
!mock
|
|
90
|
+
return count
|
|
91
|
+
|
|
92
|
+
@export sa_mock_io_read(&mock: ptr, &dst: ptr, requested: u64) -> u64:
|
|
93
|
+
L_ENTRY:
|
|
94
|
+
len = load mock+MockIo_len as u64
|
|
95
|
+
pos = load mock+MockIo_pos as u64
|
|
96
|
+
remaining = sub len, pos
|
|
97
|
+
fits = ule requested, remaining
|
|
98
|
+
br fits -> L_USE_REQUESTED, L_USE_REMAINING
|
|
99
|
+
|
|
100
|
+
L_USE_REQUESTED:
|
|
101
|
+
count = add requested, 0
|
|
102
|
+
jmp L_COPY_INIT
|
|
103
|
+
|
|
104
|
+
L_USE_REMAINING:
|
|
105
|
+
count = add remaining, 0
|
|
106
|
+
jmp L_COPY_INIT
|
|
107
|
+
|
|
108
|
+
L_COPY_INIT:
|
|
109
|
+
buf = load mock+MockIo_buf as ptr
|
|
110
|
+
offset_slot = stack_alloc 8
|
|
111
|
+
store offset_slot+0, 0 as u64
|
|
112
|
+
jmp L_COPY_HEAD
|
|
113
|
+
|
|
114
|
+
L_COPY_HEAD:
|
|
115
|
+
offset = load offset_slot+0 as u64
|
|
116
|
+
done = eq offset, count
|
|
117
|
+
br done -> L_DONE, L_COPY_BODY
|
|
118
|
+
|
|
119
|
+
L_COPY_BODY:
|
|
120
|
+
src_offset = add pos, offset
|
|
121
|
+
src_ip = ptr_add buf, src_offset
|
|
122
|
+
dst_ip = ptr_add dst, offset
|
|
123
|
+
byte = load src_ip+0 as u8
|
|
124
|
+
store dst_ip+0, byte as u8
|
|
125
|
+
next = add offset, 1
|
|
126
|
+
store offset_slot+0, next as u64
|
|
127
|
+
!src_offset
|
|
128
|
+
!src_ip
|
|
129
|
+
!dst_ip
|
|
130
|
+
!byte
|
|
131
|
+
!offset
|
|
132
|
+
!done
|
|
133
|
+
!next
|
|
134
|
+
jmp L_COPY_HEAD
|
|
135
|
+
|
|
136
|
+
L_DONE:
|
|
137
|
+
new_pos = add pos, count
|
|
138
|
+
store mock+MockIo_pos, new_pos as u64
|
|
139
|
+
!new_pos
|
|
140
|
+
!offset
|
|
141
|
+
!done
|
|
142
|
+
!buf
|
|
143
|
+
!len
|
|
144
|
+
!pos
|
|
145
|
+
!remaining
|
|
146
|
+
!fits
|
|
147
|
+
!requested
|
|
148
|
+
!dst
|
|
149
|
+
!mock
|
|
150
|
+
return count
|
|
151
|
+
|
|
152
|
+
[MACRO] MOCK_IO_INIT %mock, %buf, %cap
|
|
153
|
+
call @sa_mock_io_init(&%mock, &%buf, %cap)
|
|
154
|
+
[END_MACRO]
|
|
155
|
+
|
|
156
|
+
[MACRO] MOCK_IO_REWIND %mock
|
|
157
|
+
call @sa_mock_io_rewind(&%mock)
|
|
158
|
+
[END_MACRO]
|
|
159
|
+
|
|
160
|
+
[MACRO] MOCK_IO_LEN %out_len, %mock
|
|
161
|
+
%out_len = call @sa_mock_io_len(&%mock)
|
|
162
|
+
[END_MACRO]
|
|
163
|
+
|
|
164
|
+
[MACRO] MOCK_IO_POS %out_pos, %mock
|
|
165
|
+
%out_pos = call @sa_mock_io_pos(&%mock)
|
|
166
|
+
[END_MACRO]
|
|
167
|
+
|
|
168
|
+
[MACRO] MOCK_IO_WRITE %out_count, %mock, %src, %len
|
|
169
|
+
%out_count = call @sa_mock_io_write(&%mock, &%src, %len)
|
|
170
|
+
[END_MACRO]
|
|
171
|
+
|
|
172
|
+
[MACRO] MOCK_IO_READ %out_count, %mock, %dst, %len
|
|
173
|
+
%out_count = call @sa_mock_io_read(&%mock, &%dst, %len)
|
|
174
|
+
[END_MACRO]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import "mock_io.sal"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import "regex.sa"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import "../core/slice.sal"
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// SA-facing contracts for the Zig-backed sa_std.text.regex module.
|
|
2
|
+
// Regex and regex match handles are opaque owned ptr values.
|
|
3
|
+
@extern sa_regex_compile(&pattern: ptr, pattern_len: u64, cflags: i32) -> ^ptr
|
|
4
|
+
@extern sa_regex_match(regex: ptr, &text: ptr, text_len: u64) -> ^ptr
|
|
5
|
+
@extern sa_regex_group_ptr(match: ptr, group_idx: u32) -> &ptr
|
|
6
|
+
@extern sa_regex_group_len(match: ptr, group_idx: u32) -> u64
|
|
7
|
+
@extern sa_regex_group_count(regex: ptr) -> u64
|
|
8
|
+
@extern sa_regex_free(^regex: ptr) -> i32!
|
|
9
|
+
@extern sa_regex_match_free(^match: ptr) -> i32!
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#def SA_REGEX_EXTENDED = 1
|
|
2
|
+
#def SA_REGEX_ICASE = 2
|
|
3
|
+
#def SA_REGEX_NEWLINE = 4
|
|
4
|
+
#def SA_REGEX_NOSUB = 8
|
|
5
|
+
#def SA_REGEX_NOTBOL = 1
|
|
6
|
+
#def SA_REGEX_NOTEOL = 2
|
|
7
|
+
#def SA_REGEX_REG_NOERROR = 0
|
|
8
|
+
#def SA_REGEX_REG_OK = 0
|
|
9
|
+
#def SA_REGEX_REG_NOMATCH = 1
|
|
10
|
+
#def SA_REGEX_REG_BADPAT = 2
|
|
11
|
+
#def SA_REGEX_REG_ECOLLATE = 3
|
|
12
|
+
#def SA_REGEX_REG_ECTYPE = 4
|
|
13
|
+
#def SA_REGEX_REG_EESCAPE = 5
|
|
14
|
+
#def SA_REGEX_REG_ESUBREG = 6
|
|
15
|
+
#def SA_REGEX_REG_EBRACK = 7
|
|
16
|
+
#def SA_REGEX_REG_EPAREN = 8
|
|
17
|
+
#def SA_REGEX_REG_EBRACE = 9
|
|
18
|
+
#def SA_REGEX_REG_BADBR = 10
|
|
19
|
+
#def SA_REGEX_REG_ERANGE = 11
|
|
20
|
+
#def SA_REGEX_REG_ESPACE = 12
|
|
21
|
+
#def SA_REGEX_REG_BADRPT = 13
|
|
22
|
+
// SAASM layout constants currently avoid negative literals; keep the signed -1
|
|
23
|
+
// bit pattern so the value still matches the runtime's C ABI error code.
|
|
24
|
+
#def SA_REGEX_REG_ENOSYS = 0xffffffffffffffff
|
|
25
|
+
|
|
26
|
+
#def SaRegexGroup_SIZE = 16
|
|
27
|
+
#def SaRegexGroup_ptr = +0
|
|
28
|
+
#def SaRegexGroup_len = +8
|
|
29
|
+
|
|
30
|
+
#def SaRegexMatch_SIZE = 16
|
|
31
|
+
#def SaRegexMatch_matched = +0
|
|
32
|
+
#def SaRegexMatch_group_count = +4
|
|
33
|
+
#def SaRegexMatch_groups = +8
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import "../thread.sal"
|