@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
package/sa_std/num.sai
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Checked integer arithmetic contract (Rust `overflow-checks = true` semantics).
|
|
2
|
+
//
|
|
3
|
+
// Declared here (not invented in a backend): every `*WithOverflow` MIR rvalue
|
|
4
|
+
// lowers to one of these, and the value they return is exact — overflow traps
|
|
5
|
+
// with `panic(code)` instead of wrapping, which is what rustc's overflow
|
|
6
|
+
// `Assert` enforces. Implemented by the Zig-backed sa_std.num library; the
|
|
7
|
+
// guard shape is mirrored in `num.sal` (NUM_*_CHECKED macros) so generated SA
|
|
8
|
+
// can inline the same logic.
|
|
9
|
+
@extern sa_num_add_checked(a: i64, b: i64) -> i64
|
|
10
|
+
@extern sa_num_sub_checked(a: i64, b: i64) -> i64
|
|
11
|
+
@extern sa_num_mul_checked(a: i64, b: i64) -> i64
|
package/sa_std/num.sal
ADDED
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
#def NUM_U64_BITS = 64
|
|
2
|
+
#def BOOL_DEFAULT = 0
|
|
3
|
+
|
|
4
|
+
#def NUM_U32_BITS = 32
|
|
5
|
+
#def NUM_U16_BITS = 16
|
|
6
|
+
#def NUM_U8_BITS = 8
|
|
7
|
+
#def NUM_I64_BITS = 64
|
|
8
|
+
#def NUM_I32_BITS = 32
|
|
9
|
+
#def NUM_I16_BITS = 16
|
|
10
|
+
#def NUM_I8_BITS = 8
|
|
11
|
+
#def NUM_USIZE_BITS = 64
|
|
12
|
+
#def NUM_ISIZE_BITS = 64
|
|
13
|
+
#def NUM_U64_MAX = -1
|
|
14
|
+
#def NUM_U32_MAX = 4294967295
|
|
15
|
+
#def NUM_U16_MAX = 65535
|
|
16
|
+
#def NUM_U8_MAX = 255
|
|
17
|
+
#def NUM_USIZE_MAX = -1
|
|
18
|
+
#def NUM_I64_MAX = 9223372036854775807
|
|
19
|
+
#def NUM_I64_MIN = -9223372036854775807 - 1
|
|
20
|
+
#def NUM_I32_MAX = 2147483647
|
|
21
|
+
#def NUM_I32_MIN = -2147483648
|
|
22
|
+
#def NUM_I16_MAX = 32767
|
|
23
|
+
#def NUM_I16_MIN = -32768
|
|
24
|
+
#def NUM_I8_MAX = 127
|
|
25
|
+
#def NUM_I8_MIN = -128
|
|
26
|
+
#def NUM_ISIZE_MAX = 9223372036854775807
|
|
27
|
+
#def NUM_ISIZE_MIN = -9223372036854775807 - 1
|
|
28
|
+
|
|
29
|
+
#def NUM_U64_DEFAULT = 0
|
|
30
|
+
#def NUM_U32_DEFAULT = 0
|
|
31
|
+
#def NUM_U16_DEFAULT = 0
|
|
32
|
+
#def NUM_U8_DEFAULT = 0
|
|
33
|
+
#def NUM_USIZE_DEFAULT = 0
|
|
34
|
+
#def NUM_I64_DEFAULT = 0
|
|
35
|
+
#def NUM_I32_DEFAULT = 0
|
|
36
|
+
#def NUM_I16_DEFAULT = 0
|
|
37
|
+
#def NUM_I8_DEFAULT = 0
|
|
38
|
+
#def NUM_ISIZE_DEFAULT = 0
|
|
39
|
+
#def NUM_F32_DEFAULT = 0
|
|
40
|
+
#def NUM_F64_DEFAULT = 0
|
|
41
|
+
|
|
42
|
+
#def NonZeroU64_SIZE = 8
|
|
43
|
+
#def NonZeroU64_value = +0
|
|
44
|
+
|
|
45
|
+
#def NonZeroU32_SIZE = 8
|
|
46
|
+
#def NonZeroU32_value = +0
|
|
47
|
+
|
|
48
|
+
#def NonZeroU16_SIZE = 8
|
|
49
|
+
#def NonZeroU16_value = +0
|
|
50
|
+
|
|
51
|
+
#def NonZeroU8_SIZE = 8
|
|
52
|
+
#def NonZeroU8_value = +0
|
|
53
|
+
|
|
54
|
+
#def NonZeroUsize_SIZE = 8
|
|
55
|
+
#def NonZeroUsize_value = +0
|
|
56
|
+
|
|
57
|
+
#def NonZeroI64_SIZE = 8
|
|
58
|
+
#def NonZeroI64_value = +0
|
|
59
|
+
|
|
60
|
+
#def NonZeroI32_SIZE = 8
|
|
61
|
+
#def NonZeroI32_value = +0
|
|
62
|
+
|
|
63
|
+
#def NonZeroI16_SIZE = 8
|
|
64
|
+
#def NonZeroI16_value = +0
|
|
65
|
+
|
|
66
|
+
#def NonZeroI8_SIZE = 8
|
|
67
|
+
#def NonZeroI8_value = +0
|
|
68
|
+
|
|
69
|
+
#def NonZeroIsize_SIZE = 8
|
|
70
|
+
#def NonZeroIsize_value = +0
|
|
71
|
+
#def NONZERO_U8_MIN = 1
|
|
72
|
+
#def NONZERO_U8_MAX = 255
|
|
73
|
+
#def NONZERO_U8_ONE = 1
|
|
74
|
+
|
|
75
|
+
#def NONZERO_U16_MIN = 1
|
|
76
|
+
#def NONZERO_U16_MAX = 65535
|
|
77
|
+
#def NONZERO_U16_ONE = 1
|
|
78
|
+
|
|
79
|
+
#def NONZERO_U32_MIN = 1
|
|
80
|
+
#def NONZERO_U32_MAX = 4294967295
|
|
81
|
+
#def NONZERO_U32_ONE = 1
|
|
82
|
+
|
|
83
|
+
#def NONZERO_U64_MIN = 1
|
|
84
|
+
#def NONZERO_U64_MAX = -1
|
|
85
|
+
#def NONZERO_U64_ONE = 1
|
|
86
|
+
|
|
87
|
+
#def NONZERO_USIZE_MIN = 1
|
|
88
|
+
#def NONZERO_USIZE_MAX = -1
|
|
89
|
+
#def NONZERO_USIZE_ONE = 1
|
|
90
|
+
|
|
91
|
+
#def NONZERO_I8_MIN = -128
|
|
92
|
+
#def NONZERO_I8_MAX = 127
|
|
93
|
+
|
|
94
|
+
#def NONZERO_I16_MIN = -32768
|
|
95
|
+
#def NONZERO_I16_MAX = 32767
|
|
96
|
+
|
|
97
|
+
#def NONZERO_I32_MIN = -2147483648
|
|
98
|
+
#def NONZERO_I32_MAX = 2147483647
|
|
99
|
+
|
|
100
|
+
#def NONZERO_I64_MIN = -9223372036854775807 - 1
|
|
101
|
+
#def NONZERO_I64_MAX = 9223372036854775807
|
|
102
|
+
|
|
103
|
+
#def NONZERO_ISIZE_MIN = -9223372036854775807 - 1
|
|
104
|
+
#def NONZERO_ISIZE_MAX = 9223372036854775807
|
|
105
|
+
|
|
106
|
+
#def NUM_U8_MIN = 0
|
|
107
|
+
#def NUM_U16_MIN = 0
|
|
108
|
+
#def NUM_U32_MIN = 0
|
|
109
|
+
#def NUM_U64_MIN = 0
|
|
110
|
+
#def NUM_USIZE_MIN = 0
|
|
111
|
+
|
|
112
|
+
#def NUM_U8_BYTES = 1
|
|
113
|
+
#def NUM_U16_BYTES = 2
|
|
114
|
+
#def NUM_U32_BYTES = 4
|
|
115
|
+
#def NUM_U64_BYTES = 8
|
|
116
|
+
#def NUM_USIZE_BYTES = 8
|
|
117
|
+
#def NUM_I8_BYTES = 1
|
|
118
|
+
#def NUM_I16_BYTES = 2
|
|
119
|
+
#def NUM_I32_BYTES = 4
|
|
120
|
+
#def NUM_I64_BYTES = 8
|
|
121
|
+
#def NUM_ISIZE_BYTES = 8
|
|
122
|
+
|
|
123
|
+
#def NUM_F32_BITS = 32
|
|
124
|
+
#def NUM_F32_BYTES = 4
|
|
125
|
+
#def NUM_F32_INFINITY = 0x7F800000
|
|
126
|
+
#def NUM_F32_NEG_INFINITY = 0xFF800000
|
|
127
|
+
#def NUM_F32_NAN = 0x7FC00000
|
|
128
|
+
#def NUM_F32_ZERO = 0x00000000
|
|
129
|
+
#def NUM_F32_MINUS_ZERO = 0x80000000
|
|
130
|
+
#def NUM_F32_MIN_POSITIVE = 0x00800000
|
|
131
|
+
#def NUM_F32_MAX = 0x7F7FFFFF
|
|
132
|
+
#def NUM_F32_MIN = 0xFF7FFFFF
|
|
133
|
+
#def NUM_F32_EPSILON = 0x34000000
|
|
134
|
+
#def NUM_F32_MAX_SUBNORMAL = 0x007FFFFF
|
|
135
|
+
#def NUM_F32_MIN_SUBNORMAL = 0x00000001
|
|
136
|
+
|
|
137
|
+
#def NUM_F64_BITS = 64
|
|
138
|
+
#def NUM_F64_BYTES = 8
|
|
139
|
+
#def NUM_F64_INFINITY = 0x7FF0000000000000
|
|
140
|
+
#def NUM_F64_NEG_INFINITY = 0xFFF0000000000000
|
|
141
|
+
#def NUM_F64_NAN = 0x7FF8000000000000
|
|
142
|
+
#def NUM_F64_ZERO = 0x0000000000000000
|
|
143
|
+
#def NUM_F64_MINUS_ZERO = 0x8000000000000000
|
|
144
|
+
#def NUM_F64_MIN_POSITIVE = 0x0010000000000000
|
|
145
|
+
#def NUM_F64_MAX = 0x7FEFFFFFFFFFFFFF
|
|
146
|
+
#def NUM_F64_MIN = 0xFFEFFFFFFFFFFFFF
|
|
147
|
+
#def NUM_F64_EPSILON = 0x3CB0000000000000
|
|
148
|
+
#def NUM_F64_MAX_SUBNORMAL = 0x000FFFFFFFFFFFFF
|
|
149
|
+
#def NUM_F64_MIN_SUBNORMAL = 0x0000000000000001
|
|
150
|
+
|
|
151
|
+
#def WrappingU64_SIZE = 8
|
|
152
|
+
#def WrappingU64_value = +0
|
|
153
|
+
#def WrappingU32_SIZE = 8
|
|
154
|
+
#def WrappingU32_value = +0
|
|
155
|
+
#def WrappingI64_SIZE = 8
|
|
156
|
+
#def WrappingI64_value = +0
|
|
157
|
+
|
|
158
|
+
#def SaturatingU64_SIZE = 8
|
|
159
|
+
#def SaturatingU64_value = +0
|
|
160
|
+
#def SaturatingI64_SIZE = 8
|
|
161
|
+
#def SaturatingI64_value = +0
|
|
162
|
+
|
|
163
|
+
#def NUM_F32_DIGITS = 6
|
|
164
|
+
#def NUM_F32_RADIX = 2
|
|
165
|
+
#def NUM_F32_MIN_EXP = -125
|
|
166
|
+
#def NUM_F32_MAX_EXP = 128
|
|
167
|
+
#def NUM_F32_MIN_10_EXP = -37
|
|
168
|
+
#def NUM_F32_MAX_10_EXP = 38
|
|
169
|
+
|
|
170
|
+
#def NUM_F64_DIGITS = 15
|
|
171
|
+
#def NUM_F64_RADIX = 2
|
|
172
|
+
#def NUM_F64_MIN_EXP = -1021
|
|
173
|
+
#def NUM_F64_MAX_EXP = 1024
|
|
174
|
+
#def NUM_F64_MIN_10_EXP = -307
|
|
175
|
+
#def NUM_F64_MAX_10_EXP = 308
|
|
176
|
+
|
|
177
|
+
#def NUM_F32_MANTISSA_DIGITS = 24
|
|
178
|
+
#def NUM_F64_MANTISSA_DIGITS = 53
|
|
179
|
+
|
|
180
|
+
#def WRAPPING_U64_MIN = 0
|
|
181
|
+
#def WRAPPING_U64_MAX = -1
|
|
182
|
+
#def WRAPPING_U64_BITS = NUM_U64_BITS
|
|
183
|
+
#def WRAPPING_U32_MIN = 0
|
|
184
|
+
#def WRAPPING_U32_MAX = 4294967295
|
|
185
|
+
#def WRAPPING_U32_BITS = NUM_U32_BITS
|
|
186
|
+
#def WRAPPING_I64_MIN = -9223372036854775807 - 1
|
|
187
|
+
#def WRAPPING_I64_MAX = 9223372036854775807
|
|
188
|
+
#def WRAPPING_I64_BITS = NUM_I64_BITS
|
|
189
|
+
|
|
190
|
+
#def SATURATING_U64_MIN = 0
|
|
191
|
+
#def SATURATING_U64_MAX = -1
|
|
192
|
+
#def SATURATING_U64_BITS = NUM_U64_BITS
|
|
193
|
+
#def SATURATING_I64_MIN = -9223372036854775807 - 1
|
|
194
|
+
#def SATURATING_I64_MAX = 9223372036854775807
|
|
195
|
+
#def SATURATING_I64_BITS = NUM_I64_BITS
|
|
196
|
+
|
|
197
|
+
#def NUM_F32_SIGN_BIT = 0x80000000
|
|
198
|
+
#def NUM_F32_EXP_MASK = 0x7F800000
|
|
199
|
+
#def NUM_F32_MANT_MASK = 0x007FFFFF
|
|
200
|
+
#def NUM_F32_EXP_BIAS = 127
|
|
201
|
+
|
|
202
|
+
#def NUM_F64_SIGN_BIT = 0x8000000000000000
|
|
203
|
+
#def NUM_F64_EXP_MASK = 0x7FF0000000000000
|
|
204
|
+
#def NUM_F64_MANT_MASK = 0x000FFFFFFFFFFFFF
|
|
205
|
+
#def NUM_F64_EXP_BIAS = 1023
|
|
206
|
+
|
|
207
|
+
#def NUM_INT_ERROR_EMPTY = 0
|
|
208
|
+
#def NUM_INT_ERROR_INVALID_DIGIT = 1
|
|
209
|
+
#def NUM_INT_ERROR_POS_OVERFLOW = 2
|
|
210
|
+
#def NUM_INT_ERROR_NEG_OVERFLOW = 3
|
|
211
|
+
#def NUM_INT_ERROR_ZERO = 4
|
|
212
|
+
|
|
213
|
+
#def ParseIntError_SIZE = 24
|
|
214
|
+
#def ParseIntError_code = +0
|
|
215
|
+
#def ParseIntError_msg = +8
|
|
216
|
+
|
|
217
|
+
#def NUM_FLOAT_ERROR_EMPTY = 0
|
|
218
|
+
#def NUM_FLOAT_ERROR_INVALID = 1
|
|
219
|
+
|
|
220
|
+
#def ParseFloatError_SIZE = 8
|
|
221
|
+
#def ParseFloatError_ALIGN = 8
|
|
222
|
+
#def ParseFloatError_kind = +0
|
|
223
|
+
|
|
224
|
+
#def TryFromIntError_SIZE = 8
|
|
225
|
+
#def TryFromIntError_code = +0
|
|
226
|
+
#def TRY_FROM_INT_ERROR_POS_OVERFLOW = 0
|
|
227
|
+
#def TRY_FROM_INT_ERROR_NEG_OVERFLOW = 1
|
|
228
|
+
|
|
229
|
+
#def NONZERO_U8_BITS = 8
|
|
230
|
+
#def NONZERO_U8_BYTES = 1
|
|
231
|
+
#def NONZERO_U16_BITS = 16
|
|
232
|
+
#def NONZERO_U16_BYTES = 2
|
|
233
|
+
#def NONZERO_U32_BITS = 32
|
|
234
|
+
#def NONZERO_U32_BYTES = 4
|
|
235
|
+
#def NONZERO_U64_BITS = 64
|
|
236
|
+
#def NONZERO_U64_BYTES = 8
|
|
237
|
+
#def NONZERO_USIZE_BITS = 64
|
|
238
|
+
#def NONZERO_USIZE_BYTES = 8
|
|
239
|
+
#def NONZERO_I8_BITS = 8
|
|
240
|
+
#def NONZERO_I8_BYTES = 1
|
|
241
|
+
#def NONZERO_I16_BITS = 16
|
|
242
|
+
#def NONZERO_I16_BYTES = 2
|
|
243
|
+
#def NONZERO_I32_BITS = 32
|
|
244
|
+
#def NONZERO_I32_BYTES = 4
|
|
245
|
+
#def NONZERO_I64_BITS = 64
|
|
246
|
+
#def NONZERO_I64_BYTES = 8
|
|
247
|
+
#def NONZERO_ISIZE_BITS = 64
|
|
248
|
+
#def NONZERO_ISIZE_BYTES = 8
|
|
249
|
+
|
|
250
|
+
// Checked signed arithmetic (mirrors sa_std/num.sai). Overflow traps with
|
|
251
|
+
// panic(PANIC_ARITH_OVERFLOW) instead of wrapping, matching rustc's
|
|
252
|
+
// `*WithOverflow` + overflow `Assert` pair. Guards are the standard sign
|
|
253
|
+
// tests: an addition overflows when both operands share a sign that the
|
|
254
|
+
// result does not, a subtraction when the operands' signs differ and the
|
|
255
|
+
// result takes the subtrahend's sign.
|
|
256
|
+
#def PANIC_ARITH_OVERFLOW = 9001
|
|
257
|
+
|
|
258
|
+
[MACRO] NUM_ADD_CHECKED %out, %a, %b
|
|
259
|
+
%out = add %a, %b
|
|
260
|
+
%num_ac_pos_a_%out = gt %a, 0
|
|
261
|
+
%num_ac_pos_b_%out = gt %b, 0
|
|
262
|
+
%num_ac_both_pos_%out = and %num_ac_pos_a_%out, %num_ac_pos_b_%out
|
|
263
|
+
%num_ac_res_neg_%out = lt %out, 0
|
|
264
|
+
%num_ac_ovf_pos_%out = and %num_ac_both_pos_%out, %num_ac_res_neg_%out
|
|
265
|
+
%num_ac_neg_a_%out = lt %a, 0
|
|
266
|
+
%num_ac_neg_b_%out = lt %b, 0
|
|
267
|
+
%num_ac_both_neg_%out = and %num_ac_neg_a_%out, %num_ac_neg_b_%out
|
|
268
|
+
%num_ac_res_nonneg_%out = ge %out, 0
|
|
269
|
+
%num_ac_ovf_neg_%out = and %num_ac_both_neg_%out, %num_ac_res_nonneg_%out
|
|
270
|
+
%num_ac_ovf_%out = or %num_ac_ovf_pos_%out, %num_ac_ovf_neg_%out
|
|
271
|
+
br %num_ac_ovf_%out -> L_NUM_ADD_CHECKED_OVF_%out, L_NUM_ADD_CHECKED_OK_%out
|
|
272
|
+
L_NUM_ADD_CHECKED_OVF_%out:
|
|
273
|
+
panic(PANIC_ARITH_OVERFLOW)
|
|
274
|
+
L_NUM_ADD_CHECKED_OK_%out:
|
|
275
|
+
!%num_ac_ovf_neg_%out
|
|
276
|
+
!%num_ac_res_nonneg_%out
|
|
277
|
+
!%num_ac_both_neg_%out
|
|
278
|
+
!%num_ac_neg_b_%out
|
|
279
|
+
!%num_ac_neg_a_%out
|
|
280
|
+
!%num_ac_ovf_pos_%out
|
|
281
|
+
!%num_ac_res_neg_%out
|
|
282
|
+
!%num_ac_both_pos_%out
|
|
283
|
+
!%num_ac_pos_b_%out
|
|
284
|
+
!%num_ac_pos_a_%out
|
|
285
|
+
[END_MACRO]
|
|
286
|
+
|
|
287
|
+
[MACRO] NUM_SUB_CHECKED %out, %a, %b
|
|
288
|
+
%out = sub %a, %b
|
|
289
|
+
%num_sc_pos_a_%out = gt %a, 0
|
|
290
|
+
%num_sc_neg_b_%out = lt %b, 0
|
|
291
|
+
%num_sc_mixed_%out = and %num_sc_pos_a_%out, %num_sc_neg_b_%out
|
|
292
|
+
%num_sc_res_neg_%out = lt %out, 0
|
|
293
|
+
%num_sc_ovf_pos_%out = and %num_sc_mixed_%out, %num_sc_res_neg_%out
|
|
294
|
+
%num_sc_neg_a_%out = lt %a, 0
|
|
295
|
+
%num_sc_pos_b_%out = gt %b, 0
|
|
296
|
+
%num_sc_mixed2_%out = and %num_sc_neg_a_%out, %num_sc_pos_b_%out
|
|
297
|
+
%num_sc_res_nonneg_%out = ge %out, 0
|
|
298
|
+
%num_sc_ovf_neg_%out = and %num_sc_mixed2_%out, %num_sc_res_nonneg_%out
|
|
299
|
+
%num_sc_ovf_%out = or %num_sc_ovf_pos_%out, %num_sc_ovf_neg_%out
|
|
300
|
+
br %num_sc_ovf_%out -> L_NUM_SUB_CHECKED_OVF_%out, L_NUM_SUB_CHECKED_OK_%out
|
|
301
|
+
L_NUM_SUB_CHECKED_OVF_%out:
|
|
302
|
+
panic(PANIC_ARITH_OVERFLOW)
|
|
303
|
+
L_NUM_SUB_CHECKED_OK_%out:
|
|
304
|
+
!%num_sc_res_nonneg_%out
|
|
305
|
+
!%num_sc_mixed2_%out
|
|
306
|
+
!%num_sc_pos_b_%out
|
|
307
|
+
!%num_sc_neg_a_%out
|
|
308
|
+
!%num_sc_ovf_neg_%out
|
|
309
|
+
!%num_sc_res_neg_%out
|
|
310
|
+
!%num_sc_mixed_%out
|
|
311
|
+
!%num_sc_neg_b_%out
|
|
312
|
+
!%num_sc_pos_a_%out
|
|
313
|
+
[END_MACRO]
|
|
314
|
+
|
|
315
|
+
[MACRO] NUM_MUL_CHECKED %out, %a, %b
|
|
316
|
+
%out = mul %a, %b
|
|
317
|
+
// Divide back: the product is exact iff it divides without remainder and
|
|
318
|
+
// neither factor is -1 with a minimal result.
|
|
319
|
+
%num_mc_amin_%out = eq %a, -1
|
|
320
|
+
%num_mc_bmin_%out = eq %b, -1
|
|
321
|
+
%num_mc_back_%out = sub %out, 0
|
|
322
|
+
br %num_mc_amin_%out -> L_NUM_MUL_CHECKED_MIN_%out, L_NUM_MUL_CHECKED_DIV_%out
|
|
323
|
+
L_NUM_MUL_CHECKED_MIN_%out:
|
|
324
|
+
br %num_mc_bmin_%out -> L_NUM_MUL_CHECKED_OK_%out, L_NUM_MUL_CHECKED_DIV_%out
|
|
325
|
+
L_NUM_MUL_CHECKED_DIV_%out:
|
|
326
|
+
%num_mc_div_%out = div %out, %a
|
|
327
|
+
%num_mc_rem_%out = rem %num_mc_div_%out, %a
|
|
328
|
+
%num_mc_ovf_%out = ne %num_mc_rem_%out, 0
|
|
329
|
+
br %num_mc_ovf_%out -> L_NUM_MUL_CHECKED_OVF_%out, L_NUM_MUL_CHECKED_OK_%out
|
|
330
|
+
L_NUM_MUL_CHECKED_OVF_%out:
|
|
331
|
+
panic(PANIC_ARITH_OVERFLOW)
|
|
332
|
+
L_NUM_MUL_CHECKED_OK_%out:
|
|
333
|
+
!%num_mc_ovf_%out
|
|
334
|
+
!%num_mc_rem_%out
|
|
335
|
+
!%num_mc_div_%out
|
|
336
|
+
br L_NUM_MUL_CHECKED_TAIL_%out
|
|
337
|
+
L_NUM_MUL_CHECKED_TAIL_%out:
|
|
338
|
+
!%num_mc_back_%out
|
|
339
|
+
!%num_mc_bmin_%out
|
|
340
|
+
!%num_mc_amin_%out
|
|
341
|
+
[END_MACRO]
|