@grain/stdlib 0.5.12 → 0.6.0

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.
Files changed (155) hide show
  1. package/CHANGELOG.md +200 -0
  2. package/LICENSE +1 -1
  3. package/README.md +25 -2
  4. package/array.gr +1512 -199
  5. package/array.md +2032 -94
  6. package/bigint.gr +239 -140
  7. package/bigint.md +450 -106
  8. package/buffer.gr +595 -102
  9. package/buffer.md +903 -145
  10. package/bytes.gr +401 -110
  11. package/bytes.md +551 -63
  12. package/char.gr +228 -49
  13. package/char.md +373 -7
  14. package/exception.gr +26 -12
  15. package/exception.md +29 -5
  16. package/float32.gr +130 -109
  17. package/float32.md +185 -57
  18. package/float64.gr +112 -99
  19. package/float64.md +185 -57
  20. package/hash.gr +47 -37
  21. package/hash.md +21 -3
  22. package/int16.gr +430 -0
  23. package/int16.md +618 -0
  24. package/int32.gr +200 -269
  25. package/int32.md +254 -289
  26. package/int64.gr +142 -225
  27. package/int64.md +254 -289
  28. package/int8.gr +511 -0
  29. package/int8.md +786 -0
  30. package/json.gr +2084 -0
  31. package/json.md +608 -0
  32. package/list.gr +120 -68
  33. package/list.md +125 -80
  34. package/map.gr +560 -57
  35. package/map.md +672 -56
  36. package/marshal.gr +239 -227
  37. package/marshal.md +36 -4
  38. package/number.gr +626 -676
  39. package/number.md +738 -153
  40. package/option.gr +33 -35
  41. package/option.md +58 -42
  42. package/package.json +2 -2
  43. package/path.gr +148 -187
  44. package/path.md +47 -96
  45. package/pervasives.gr +75 -416
  46. package/pervasives.md +85 -180
  47. package/priorityqueue.gr +433 -74
  48. package/priorityqueue.md +422 -54
  49. package/queue.gr +362 -80
  50. package/queue.md +433 -38
  51. package/random.gr +67 -75
  52. package/random.md +68 -40
  53. package/range.gr +135 -63
  54. package/range.md +198 -43
  55. package/rational.gr +284 -0
  56. package/rational.md +545 -0
  57. package/regex.gr +933 -1066
  58. package/regex.md +59 -60
  59. package/result.gr +23 -25
  60. package/result.md +54 -39
  61. package/runtime/atof/common.gr +78 -82
  62. package/runtime/atof/common.md +22 -10
  63. package/runtime/atof/decimal.gr +102 -127
  64. package/runtime/atof/decimal.md +28 -7
  65. package/runtime/atof/lemire.gr +56 -71
  66. package/runtime/atof/lemire.md +9 -1
  67. package/runtime/atof/parse.gr +83 -110
  68. package/runtime/atof/parse.md +12 -2
  69. package/runtime/atof/slow.gr +28 -35
  70. package/runtime/atof/slow.md +9 -1
  71. package/runtime/atof/table.gr +19 -18
  72. package/runtime/atof/table.md +10 -2
  73. package/runtime/atoi/parse.gr +153 -136
  74. package/runtime/atoi/parse.md +50 -1
  75. package/runtime/bigint.gr +410 -517
  76. package/runtime/bigint.md +71 -57
  77. package/runtime/compare.gr +176 -85
  78. package/runtime/compare.md +31 -1
  79. package/runtime/dataStructures.gr +144 -32
  80. package/runtime/dataStructures.md +267 -31
  81. package/runtime/debugPrint.gr +34 -15
  82. package/runtime/debugPrint.md +37 -5
  83. package/runtime/equal.gr +53 -52
  84. package/runtime/equal.md +30 -1
  85. package/runtime/exception.gr +38 -47
  86. package/runtime/exception.md +10 -8
  87. package/runtime/gc.gr +23 -152
  88. package/runtime/gc.md +13 -17
  89. package/runtime/malloc.gr +31 -31
  90. package/runtime/malloc.md +11 -3
  91. package/runtime/numberUtils.gr +191 -172
  92. package/runtime/numberUtils.md +17 -9
  93. package/runtime/numbers.gr +1695 -1021
  94. package/runtime/numbers.md +1098 -134
  95. package/runtime/string.gr +540 -242
  96. package/runtime/string.md +76 -6
  97. package/runtime/unsafe/constants.gr +30 -13
  98. package/runtime/unsafe/constants.md +80 -0
  99. package/runtime/unsafe/conv.gr +55 -28
  100. package/runtime/unsafe/conv.md +41 -9
  101. package/runtime/unsafe/memory.gr +10 -30
  102. package/runtime/unsafe/memory.md +15 -19
  103. package/runtime/unsafe/tags.gr +37 -21
  104. package/runtime/unsafe/tags.md +88 -8
  105. package/runtime/unsafe/wasmf32.gr +30 -36
  106. package/runtime/unsafe/wasmf32.md +64 -56
  107. package/runtime/unsafe/wasmf64.gr +30 -36
  108. package/runtime/unsafe/wasmf64.md +64 -56
  109. package/runtime/unsafe/wasmi32.gr +49 -66
  110. package/runtime/unsafe/wasmi32.md +102 -94
  111. package/runtime/unsafe/wasmi64.gr +52 -79
  112. package/runtime/unsafe/wasmi64.md +108 -100
  113. package/runtime/utils/printing.gr +13 -15
  114. package/runtime/utils/printing.md +11 -3
  115. package/runtime/wasi.gr +294 -295
  116. package/runtime/wasi.md +62 -42
  117. package/set.gr +574 -64
  118. package/set.md +634 -54
  119. package/stack.gr +181 -64
  120. package/stack.md +271 -42
  121. package/string.gr +453 -533
  122. package/string.md +241 -151
  123. package/uint16.gr +369 -0
  124. package/uint16.md +585 -0
  125. package/uint32.gr +470 -0
  126. package/uint32.md +737 -0
  127. package/uint64.gr +471 -0
  128. package/uint64.md +737 -0
  129. package/uint8.gr +369 -0
  130. package/uint8.md +585 -0
  131. package/uri.gr +1093 -0
  132. package/uri.md +477 -0
  133. package/{sys → wasi}/file.gr +914 -500
  134. package/{sys → wasi}/file.md +454 -50
  135. package/wasi/process.gr +292 -0
  136. package/{sys → wasi}/process.md +164 -6
  137. package/wasi/random.gr +77 -0
  138. package/wasi/random.md +80 -0
  139. package/{sys → wasi}/time.gr +15 -22
  140. package/{sys → wasi}/time.md +5 -5
  141. package/immutablearray.gr +0 -929
  142. package/immutablearray.md +0 -1038
  143. package/immutablemap.gr +0 -493
  144. package/immutablemap.md +0 -479
  145. package/immutablepriorityqueue.gr +0 -360
  146. package/immutablepriorityqueue.md +0 -291
  147. package/immutableset.gr +0 -498
  148. package/immutableset.md +0 -449
  149. package/runtime/debug.gr +0 -2
  150. package/runtime/debug.md +0 -6
  151. package/runtime/unsafe/errors.gr +0 -36
  152. package/runtime/unsafe/errors.md +0 -204
  153. package/sys/process.gr +0 -254
  154. package/sys/random.gr +0 -79
  155. package/sys/random.md +0 -66
@@ -1,29 +1,34 @@
1
- /* grainc-flags --no-pervasives */
1
+ @noPervasives
2
+ module Compare
2
3
 
3
- import WasmI32, {
4
- eq as (==),
5
- ne as (!=),
6
- and as (&),
7
- xor as (^),
8
- or as (|),
9
- add as (+),
10
- sub as (-),
11
- mul as (*),
12
- ltS as (<),
13
- gtS as (>),
4
+ from "runtime/unsafe/wasmi32" include WasmI32
5
+ use WasmI32.{
6
+ (==),
7
+ (!=),
8
+ (&),
9
+ (^),
10
+ (|),
11
+ (+),
12
+ (-),
13
+ (*),
14
+ (<),
15
+ (>),
14
16
  remS as (%),
15
- shl as (<<),
16
- shrU as (>>>),
17
- } from "runtime/unsafe/wasmi32"
18
- import WasmI64 from "runtime/unsafe/wasmi64"
19
- import Memory from "runtime/unsafe/memory"
20
- import Tags from "runtime/unsafe/tags"
21
- import { tagSimpleNumber } from "runtime/dataStructures"
22
- import { isNumber, cmp as numberCompare } from "runtime/numbers"
17
+ (<<),
18
+ (>>>),
19
+ }
20
+ from "runtime/unsafe/wasmi64" include WasmI64
21
+ from "runtime/unsafe/wasmf32" include WasmF32
22
+ from "runtime/unsafe/memory" include Memory
23
+ from "runtime/unsafe/tags" include Tags
24
+ from "runtime/dataStructures" include DataStructures
25
+ use DataStructures.{ tagSimpleNumber }
26
+ from "runtime/numbers" include Numbers
27
+ use Numbers.{ isNumber, cmp as numberCompare }
23
28
 
24
- primitive (!): Bool -> Bool = "@not"
25
- primitive (||): (Bool, Bool) -> Bool = "@or"
26
- primitive (&&): (Bool, Bool) -> Bool = "@and"
29
+ primitive (!) = "@not"
30
+ primitive (||) = "@or"
31
+ primitive (&&) = "@and"
27
32
 
28
33
  @unsafe
29
34
  let zero = WasmI32.fromGrain(0)
@@ -36,34 +41,28 @@ let rec heapCompareHelp = (heapTag, xptr, yptr) => {
36
41
  let xvariant = WasmI32.load(xptr, 12n)
37
42
  let yvariant = WasmI32.load(yptr, 12n)
38
43
  if (xvariant != yvariant) {
39
- tagSimpleNumber(xvariant - yvariant)
40
- } else {
41
- let xarity = WasmI32.load(xptr, 16n)
42
- let yarity = WasmI32.load(yptr, 16n)
43
-
44
- let mut result = 0
44
+ return tagSimpleNumber(xvariant - yvariant)
45
+ }
46
+ let xarity = WasmI32.load(xptr, 16n)
47
+ let yarity = WasmI32.load(yptr, 16n)
45
48
 
46
- let bytes = xarity * 4n
47
- for (let mut i = 0n; i < bytes; i += 4n) {
48
- let sub = compareHelp(
49
- WasmI32.load(xptr + i, 20n),
50
- WasmI32.load(yptr + i, 20n)
51
- )
52
- if (WasmI32.fromGrain(sub) != zero) {
53
- result = sub
54
- break
55
- }
49
+ let bytes = xarity * 4n
50
+ for (let mut i = 0n; i < bytes; i += 4n) {
51
+ let sub = compareHelp(
52
+ WasmI32.load(xptr + i, 20n),
53
+ WasmI32.load(yptr + i, 20n)
54
+ )
55
+ if (WasmI32.fromGrain(sub) != zero) {
56
+ return sub
56
57
  }
57
-
58
- result
59
58
  }
59
+
60
+ return 0
60
61
  },
61
62
  t when t == Tags._GRAIN_RECORD_HEAP_TAG => {
62
63
  let xlength = WasmI32.load(xptr, 12n)
63
64
  let ylength = WasmI32.load(yptr, 12n)
64
65
 
65
- let mut result = 0
66
-
67
66
  let bytes = xlength * 4n
68
67
  for (let mut i = 0n; i < bytes; i += 4n) {
69
68
  let sub = compareHelp(
@@ -71,12 +70,11 @@ let rec heapCompareHelp = (heapTag, xptr, yptr) => {
71
70
  WasmI32.load(yptr + i, 16n)
72
71
  )
73
72
  if (WasmI32.fromGrain(sub) != zero) {
74
- result = sub
75
- break
73
+ return sub
76
74
  }
77
75
  }
78
76
 
79
- result
77
+ return 0
80
78
  },
81
79
  t when t == Tags._GRAIN_ARRAY_HEAP_TAG => {
82
80
  let xlength = WasmI32.load(xptr, 4n)
@@ -84,49 +82,42 @@ let rec heapCompareHelp = (heapTag, xptr, yptr) => {
84
82
 
85
83
  // Check if the same length
86
84
  if (xlength != ylength) {
87
- tagSimpleNumber(xlength - ylength)
88
- } else {
89
- let mut result = 0
90
- let bytes = xlength * 4n
91
- for (let mut i = 0n; i < bytes; i += 4n) {
92
- let sub = compareHelp(
93
- WasmI32.load(xptr + i, 8n),
94
- WasmI32.load(yptr + i, 8n)
95
- )
96
- if (WasmI32.fromGrain(sub) != zero) {
97
- result = sub
98
- break
99
- }
85
+ return tagSimpleNumber(xlength - ylength)
86
+ }
87
+ let bytes = xlength * 4n
88
+ for (let mut i = 0n; i < bytes; i += 4n) {
89
+ let sub = compareHelp(
90
+ WasmI32.load(xptr + i, 8n),
91
+ WasmI32.load(yptr + i, 8n)
92
+ )
93
+ if (WasmI32.fromGrain(sub) != zero) {
94
+ return sub
100
95
  }
101
-
102
- result
103
96
  }
97
+
98
+ return 0
104
99
  },
105
- t when (
106
- t == Tags._GRAIN_STRING_HEAP_TAG || t == Tags._GRAIN_BYTES_HEAP_TAG
107
- ) => {
100
+ t when t == Tags._GRAIN_STRING_HEAP_TAG || t == Tags._GRAIN_BYTES_HEAP_TAG => {
108
101
  let xlength = WasmI32.load(xptr, 4n)
109
102
  let ylength = WasmI32.load(yptr, 4n)
110
103
 
111
104
  if (xlength == ylength) {
112
- tagSimpleNumber(Memory.compare(xptr + 8n, yptr + 8n, xlength))
105
+ return tagSimpleNumber(Memory.compare(xptr + 8n, yptr + 8n, xlength))
106
+ }
107
+ if (xlength < ylength) {
108
+ let sub = Memory.compare(xptr + 8n, yptr + 8n, xlength)
109
+ // The shorter one comes first
110
+ return if (sub == 0n) -1 else tagSimpleNumber(sub)
113
111
  } else {
114
- if (xlength < ylength) {
115
- let sub = Memory.compare(xptr + 8n, yptr + 8n, xlength)
116
- // The shorter one comes first
117
- if (sub == 0n) -1 else tagSimpleNumber(sub)
118
- } else {
119
- let sub = Memory.compare(xptr + 8n, yptr + 8n, ylength)
120
- // The shorter one comes first
121
- if (sub == 0n) 1 else tagSimpleNumber(sub)
122
- }
112
+ let sub = Memory.compare(xptr + 8n, yptr + 8n, ylength)
113
+ // The shorter one comes first
114
+ return if (sub == 0n) 1 else tagSimpleNumber(sub)
123
115
  }
124
116
  },
125
117
  t when t == Tags._GRAIN_TUPLE_HEAP_TAG => {
126
118
  let xsize = WasmI32.load(xptr, 4n)
127
119
  let ysize = WasmI32.load(yptr, 4n)
128
120
 
129
- let mut result = 0
130
121
  let bytes = xsize * 4n
131
122
  for (let mut i = 0n; i < bytes; i += 4n) {
132
123
  let sub = compareHelp(
@@ -134,34 +125,123 @@ let rec heapCompareHelp = (heapTag, xptr, yptr) => {
134
125
  WasmI32.load(yptr + i, 8n)
135
126
  )
136
127
  if (WasmI32.fromGrain(sub) != zero) {
137
- result = sub
138
- break
128
+ return sub
139
129
  }
140
130
  }
141
131
 
142
- result
132
+ return 0
133
+ },
134
+ t when t == Tags._GRAIN_INT32_HEAP_TAG => {
135
+ let xval = WasmI32.load(xptr, 4n)
136
+ let yval = WasmI32.load(yptr, 4n)
137
+ return if (xval < yval) {
138
+ -1
139
+ } else if (xval > yval) {
140
+ 1
141
+ } else {
142
+ 0
143
+ }
144
+ },
145
+ // Float32 is handled by compareHelp directly
146
+ t when t == Tags._GRAIN_UINT32_HEAP_TAG => {
147
+ let xval = WasmI32.load(xptr, 4n)
148
+ let yval = WasmI32.load(yptr, 4n)
149
+ return if (WasmI32.ltU(xval, yval)) {
150
+ -1
151
+ } else if (WasmI32.gtU(xval, yval)) {
152
+ 1
153
+ } else {
154
+ 0
155
+ }
156
+ },
157
+ t when t == Tags._GRAIN_UINT64_HEAP_TAG => {
158
+ let xval = WasmI64.load(xptr, 8n)
159
+ let yval = WasmI64.load(yptr, 8n)
160
+ return if (WasmI64.ltU(xval, yval)) {
161
+ -1
162
+ } else if (WasmI64.gtU(xval, yval)) {
163
+ 1
164
+ } else {
165
+ 0
166
+ }
143
167
  },
144
168
  _ => {
145
169
  // No other implementation
146
- tagSimpleNumber(xptr - yptr)
170
+ return tagSimpleNumber(xptr - yptr)
147
171
  },
148
172
  }
149
- },
150
- compareHelp = (x, y) => {
173
+ }
174
+ and compareHelp = (x, y) => {
151
175
  let xtag = x & Tags._GRAIN_GENERIC_TAG_MASK
152
176
  let ytag = y & Tags._GRAIN_GENERIC_TAG_MASK
153
177
  if ((xtag & ytag) != Tags._GRAIN_GENERIC_HEAP_TAG_TYPE) {
154
178
  // Short circuit for non-pointer values
155
179
  if ((xtag & Tags._GRAIN_NUMBER_TAG_MASK) == Tags._GRAIN_NUMBER_TAG_TYPE) {
156
180
  // Signed comparisons are necessary for numbers
157
- if (x < y) -1 else if (x > y) 1 else 0
181
+ if (x < y) {
182
+ -1
183
+ } else if (x > y) {
184
+ 1
185
+ } else {
186
+ 0
187
+ }
188
+ } else if (xtag == Tags._GRAIN_SHORTVAL_TAG_TYPE) {
189
+ let shortValTag = x & Tags._GRAIN_GENERIC_SHORTVAL_TAG_MASK
190
+ if (
191
+ shortValTag == Tags._GRAIN_INT8_TAG_MASK ||
192
+ shortValTag == Tags._GRAIN_INT16_TAG_MASK
193
+ ) {
194
+ if (x < y) {
195
+ -1
196
+ } else if (x > y) {
197
+ 1
198
+ } else {
199
+ 0
200
+ }
201
+ } else {
202
+ if (WasmI32.ltU(x, y)) {
203
+ -1
204
+ } else if (WasmI32.gtU(x, y)) {
205
+ 1
206
+ } else {
207
+ 0
208
+ }
209
+ }
158
210
  } else {
159
211
  // Unsigned comparisons are necessary for other stack-allocated values
160
- if (WasmI32.ltU(x, y)) -1 else if (WasmI32.gtU(x, y)) 1 else 0
212
+ if (WasmI32.ltU(x, y)) {
213
+ -1
214
+ } else if (WasmI32.gtU(x, y)) {
215
+ 1
216
+ } else {
217
+ 0
218
+ }
161
219
  }
162
220
  } else if (isNumber(x)) {
163
221
  // Numbers have special comparison rules, e.g. NaN == NaN
164
222
  tagSimpleNumber(numberCompare(x, y))
223
+ } else if (WasmI32.load(x, 0n) == Tags._GRAIN_FLOAT32_HEAP_TAG) {
224
+ // Short circuit for Float32 to correctly handle NaN comparisons
225
+ let xval = WasmF32.load(x, 4n)
226
+ let yval = WasmF32.load(y, 4n)
227
+ use WasmF32.{ (!=) }
228
+ let xIsNaN = xval != xval
229
+ let yIsNaN = yval != yval
230
+ if (xIsNaN) {
231
+ if (yIsNaN) 0 else -1
232
+ } else if (yIsNaN) {
233
+ // x is confirmed to be not NaN at this point
234
+ 1
235
+ } else {
236
+ use WasmF32.{ (<), (>) }
237
+ if (xval < yval) {
238
+ -1
239
+ } else if (xval > yval) {
240
+ 1
241
+ } else {
242
+ 0
243
+ }
244
+ }
165
245
  } else {
166
246
  // Handle all other heap allocated things
167
247
  // Can short circuit if pointers are the same
@@ -173,7 +253,18 @@ compareHelp = (x, y) => {
173
253
  }
174
254
  }
175
255
 
256
+ /**
257
+ * Compares the first argument to the second argument and produces an integer result.
258
+ * Provides a consistent ordering over all types and is suitable for sorting and other kinds of ordering.
259
+ * `compare` treats `NaN` differently than the other comparison operators in that it considers `NaN` equal to itself and smaller than any other number.
260
+ *
261
+ * @param num1: The first operand
262
+ * @param num2: The second operand
263
+ * @returns A negative integer if the first operand is less than the second operand, `0` if they are equal, or a positive integer otherwise
264
+ *
265
+ * @since v0.5.3
266
+ */
176
267
  @unsafe
177
- export let compare = (x: a, y: a) => {
178
- compareHelp(WasmI32.fromGrain(x), WasmI32.fromGrain(y))
268
+ provide let compare = (num1: a, num2: a) => {
269
+ compareHelp(WasmI32.fromGrain(num1), WasmI32.fromGrain(num2))
179
270
  }
@@ -1,6 +1,36 @@
1
+ ---
2
+ title: Compare
3
+ ---
4
+
5
+ ## Values
6
+
7
+ Functions and constants included in the Compare module.
8
+
1
9
  ### Compare.**compare**
2
10
 
11
+ <details disabled>
12
+ <summary tabindex="-1">Added in <code>0.5.3</code></summary>
13
+ No other changes yet.
14
+ </details>
15
+
3
16
  ```grain
4
- compare : (a, a) -> Number
17
+ compare : (num1: a, num2: a) => Number
5
18
  ```
6
19
 
20
+ Compares the first argument to the second argument and produces an integer result.
21
+ Provides a consistent ordering over all types and is suitable for sorting and other kinds of ordering.
22
+ `compare` treats `NaN` differently than the other comparison operators in that it considers `NaN` equal to itself and smaller than any other number.
23
+
24
+ Parameters:
25
+
26
+ |param|type|description|
27
+ |-----|----|-----------|
28
+ |`num1`|`a`|The first operand|
29
+ |`num2`|`a`|The second operand|
30
+
31
+ Returns:
32
+
33
+ |type|description|
34
+ |----|-----------|
35
+ |`Number`|A negative integer if the first operand is less than the second operand, `0` if they are equal, or a positive integer otherwise|
36
+
@@ -1,22 +1,23 @@
1
- /* grainc-flags --no-pervasives */
1
+ @noPervasives
2
+ module DataStructures
2
3
 
3
4
  /**
4
5
  * Allocates a new Grain array.
5
6
  *
6
- * @param numElts: The number of elements to be contained in this array
7
+ * @param size: The number of elements to be contained in this array
7
8
  * @returns The pointer to the array
8
9
  */
9
10
  @unsafe
10
- export primitive allocateArray: WasmI32 -> WasmI32 = "@allocate.array"
11
+ provide primitive allocateArray = "@allocate.array"
11
12
 
12
13
  /**
13
14
  * Allocates a new Grain tuple.
14
15
  *
15
- * @param numElts: The number of elements to be contained in this tuple
16
+ * @param size: The number of elements to be contained in this tuple
16
17
  * @returns The pointer to the tuple
17
18
  */
18
19
  @unsafe
19
- export primitive allocateTuple: WasmI32 -> WasmI32 = "@allocate.tuple"
20
+ provide primitive allocateTuple = "@allocate.tuple"
20
21
 
21
22
  /**
22
23
  * Allocates a new Grain bytes.
@@ -25,7 +26,7 @@ export primitive allocateTuple: WasmI32 -> WasmI32 = "@allocate.tuple"
25
26
  * @returns The pointer to the bytes
26
27
  */
27
28
  @unsafe
28
- export primitive allocateBytes: WasmI32 -> WasmI32 = "@allocate.bytes"
29
+ provide primitive allocateBytes = "@allocate.bytes"
29
30
 
30
31
  /**
31
32
  * Allocates a new Grain string.
@@ -34,7 +35,7 @@ export primitive allocateBytes: WasmI32 -> WasmI32 = "@allocate.bytes"
34
35
  * @returns The pointer to the string
35
36
  */
36
37
  @unsafe
37
- export primitive allocateString: WasmI32 -> WasmI32 = "@allocate.string"
38
+ provide primitive allocateString = "@allocate.string"
38
39
 
39
40
  // INT32/INT64
40
41
 
@@ -44,15 +45,33 @@ export primitive allocateString: WasmI32 -> WasmI32 = "@allocate.string"
44
45
  * @returns The pointer to the empty Int32
45
46
  */
46
47
  @unsafe
47
- export primitive allocateInt32: () -> WasmI32 = "@allocate.int32"
48
+ provide primitive allocateInt32 = "@allocate.int32"
48
49
 
49
50
  /**
50
51
  * Allocates a new Int32 with a prepopulated value
51
- * @param value: The value to store
52
+ *
53
+ * @param int: The value to store
52
54
  * @returns The pointer to the Int32
53
55
  */
54
56
  @unsafe
55
- export primitive newInt32: WasmI32 -> WasmI32 = "@new.int32"
57
+ provide primitive newInt32 = "@new.int32"
58
+
59
+ /**
60
+ * Allocates a new Uint32.
61
+ *
62
+ * @returns The pointer to the empty Uint32
63
+ */
64
+ @unsafe
65
+ provide primitive allocateUint32 = "@allocate.uint32"
66
+
67
+ /**
68
+ * Allocates a new Uint32 with a prepopulated value
69
+ *
70
+ * @param int: The value to store
71
+ * @returns The pointer to the Uint32
72
+ */
73
+ @unsafe
74
+ provide primitive newUint32 = "@new.uint32"
56
75
 
57
76
  /**
58
77
  * Allocates a new Int64.
@@ -60,15 +79,33 @@ export primitive newInt32: WasmI32 -> WasmI32 = "@new.int32"
60
79
  * @returns The pointer to the empty Int64
61
80
  */
62
81
  @unsafe
63
- export primitive allocateInt64: () -> WasmI32 = "@allocate.int64"
82
+ provide primitive allocateInt64 = "@allocate.int64"
64
83
 
65
84
  /**
66
85
  * Allocates a new Int64 with a prepopulated value
67
- * @param value: The value to store
86
+ *
87
+ * @param int: The value to store
68
88
  * @returns The pointer to the Int64
69
89
  */
70
90
  @unsafe
71
- export primitive newInt64: WasmI64 -> WasmI32 = "@new.int64"
91
+ provide primitive newInt64 = "@new.int64"
92
+
93
+ /**
94
+ * Allocates a new Uint64.
95
+ *
96
+ * @returns The pointer to the empty Uint64
97
+ */
98
+ @unsafe
99
+ provide primitive allocateUint64 = "@allocate.uint64"
100
+
101
+ /**
102
+ * Allocates a new Uint64 with a prepopulated value
103
+ *
104
+ * @param int: The value to store
105
+ * @returns The pointer to the Uint64
106
+ */
107
+ @unsafe
108
+ provide primitive newUint64 = "@new.uint64"
72
109
 
73
110
  // FLOATS
74
111
 
@@ -78,15 +115,16 @@ export primitive newInt64: WasmI64 -> WasmI32 = "@new.int64"
78
115
  * @returns The pointer to the empty Float32
79
116
  */
80
117
  @unsafe
81
- export primitive allocateFloat32: () -> WasmI32 = "@allocate.float32"
118
+ provide primitive allocateFloat32 = "@allocate.float32"
82
119
 
83
120
  /**
84
121
  * Allocates a new Float32 with a prepopulated value
85
- * @param value: The value to store
122
+ *
123
+ * @param float: The value to store
86
124
  * @returns the pointer to the Float32
87
125
  */
88
126
  @unsafe
89
- export primitive newFloat32: WasmF32 -> WasmI32 = "@new.float32"
127
+ provide primitive newFloat32 = "@new.float32"
90
128
 
91
129
  /**
92
130
  * Allocates a new Float64.
@@ -94,15 +132,16 @@ export primitive newFloat32: WasmF32 -> WasmI32 = "@new.float32"
94
132
  * @returns The pointer to the empty Float64
95
133
  */
96
134
  @unsafe
97
- export primitive allocateFloat64: () -> WasmI32 = "@allocate.float64"
135
+ provide primitive allocateFloat64 = "@allocate.float64"
98
136
 
99
137
  /**
100
138
  * Allocates a new Float64 with a prepopulated value
101
- * @param value: The value to store
139
+ *
140
+ * @param float: The value to store
102
141
  * @returns The pointer to the Float64
103
142
  */
104
143
  @unsafe
105
- export primitive newFloat64: WasmF64 -> WasmI32 = "@new.float64"
144
+ provide primitive newFloat64 = "@new.float64"
106
145
 
107
146
  // RATIONALS
108
147
 
@@ -112,16 +151,17 @@ export primitive newFloat64: WasmF64 -> WasmI32 = "@new.float64"
112
151
  * @returns The pointer to the empty Rational
113
152
  */
114
153
  @unsafe
115
- export primitive allocateRational: () -> WasmI32 = "@allocate.rational"
154
+ provide primitive allocateRational = "@allocate.rational"
116
155
 
117
156
  /**
118
157
  * Allocates a new Rational with a prepopulated value
119
- * @param value: The numerator value to store
120
- * @param value: The denominator value to store
158
+ *
159
+ * @param numerator: The numerator value to store
160
+ * @param denominator: The denominator value to store
121
161
  * @returns The pointer to the Rational
122
162
  */
123
163
  @unsafe
124
- export primitive newRational: (WasmI32, WasmI32) -> WasmI32 = "@new.rational"
164
+ provide primitive newRational = "@new.rational"
125
165
 
126
166
  /**
127
167
  * Load the (tagged) variant of an ADT.
@@ -130,7 +170,7 @@ export primitive newRational: (WasmI32, WasmI32) -> WasmI32 = "@new.rational"
130
170
  * @returns The (tagged) ADT variant id
131
171
  */
132
172
  @unsafe
133
- export primitive loadAdtVariant: WasmI32 -> WasmI32 = "@adt.load_variant"
173
+ provide primitive loadAdtVariant = "@adt.load_variant"
134
174
 
135
175
  /**
136
176
  * Load an untagged string's size.
@@ -139,7 +179,7 @@ export primitive loadAdtVariant: WasmI32 -> WasmI32 = "@adt.load_variant"
139
179
  * @returns The string size (in bytes)
140
180
  */
141
181
  @unsafe
142
- export primitive stringSize: WasmI32 -> WasmI32 = "@string.size"
182
+ provide primitive stringSize = "@string.size"
143
183
 
144
184
  /**
145
185
  * Load an untagged Bytes' size.
@@ -148,7 +188,7 @@ export primitive stringSize: WasmI32 -> WasmI32 = "@string.size"
148
188
  * @returns The Bytes size (in bytes)
149
189
  */
150
190
  @unsafe
151
- export primitive bytesSize: WasmI32 -> WasmI32 = "@bytes.size"
191
+ provide primitive bytesSize = "@bytes.size"
152
192
 
153
193
  /**
154
194
  * Tag a simple number.
@@ -157,7 +197,7 @@ export primitive bytesSize: WasmI32 -> WasmI32 = "@bytes.size"
157
197
  * @returns The tagged number
158
198
  */
159
199
  @unsafe
160
- export primitive tagSimpleNumber: WasmI32 -> Number = "@tag.simple_number"
200
+ provide primitive tagSimpleNumber = "@tag.simple_number"
161
201
 
162
202
  /**
163
203
  * Untag a simple number.
@@ -166,22 +206,94 @@ export primitive tagSimpleNumber: WasmI32 -> Number = "@tag.simple_number"
166
206
  * @returns The untagged number
167
207
  */
168
208
  @unsafe
169
- export primitive untagSimpleNumber: Number -> WasmI32 = "@untag.simple_number"
209
+ provide primitive untagSimpleNumber = "@untag.simple_number"
170
210
 
171
211
  /**
172
212
  * Tag a char.
173
213
  *
174
- * @param num: The usv to tag
214
+ * @param char: The usv to tag
175
215
  * @returns The tagged char
176
216
  */
177
217
  @unsafe
178
- export primitive tagChar: WasmI32 -> Char = "@tag.char"
218
+ provide primitive tagChar = "@tag.char"
179
219
 
180
220
  /**
181
221
  * Untag a char.
182
222
  *
183
- * @param num: The char to untag
223
+ * @param char: The char to untag
184
224
  * @returns The untagged usv
185
225
  */
186
226
  @unsafe
187
- export primitive untagChar: Char -> WasmI32 = "@untag.char"
227
+ provide primitive untagChar = "@untag.char"
228
+
229
+ /**
230
+ * Tag an int8.
231
+ *
232
+ * @param int: The int8 to tag
233
+ * @returns The tagged int8
234
+ */
235
+ @unsafe
236
+ provide primitive tagInt8 = "@tag.int8"
237
+
238
+ /**
239
+ * Untag an int8.
240
+ *
241
+ * @param int: The int8 to untag
242
+ * @returns The untagged int8
243
+ */
244
+ @unsafe
245
+ provide primitive untagInt8 = "@untag.int8"
246
+
247
+ /**
248
+ * Tag an int16.
249
+ *
250
+ * @param int: The int16 to tag
251
+ * @returns The tagged int16
252
+ */
253
+ @unsafe
254
+ provide primitive tagInt16 = "@tag.int16"
255
+
256
+ /**
257
+ * Untag an int16.
258
+ *
259
+ * @param int: The int16 to untag
260
+ * @returns The untagged int16
261
+ */
262
+ @unsafe
263
+ provide primitive untagInt16 = "@untag.int16"
264
+
265
+ /**
266
+ * Tag a uint8.
267
+ *
268
+ * @param int: The uint8 to tag
269
+ * @returns The tagged uint8
270
+ */
271
+ @unsafe
272
+ provide primitive tagUint8 = "@tag.uint8"
273
+
274
+ /**
275
+ * Untag a uint8.
276
+ *
277
+ * @param int: The uint8 to untag
278
+ * @returns The untagged uint8
279
+ */
280
+ @unsafe
281
+ provide primitive untagUint8 = "@untag.uint8"
282
+
283
+ /**
284
+ * Tag a uint16.
285
+ *
286
+ * @param int: The uint16 to tag
287
+ * @returns The tagged uint16
288
+ */
289
+ @unsafe
290
+ provide primitive tagUint16 = "@tag.uint16"
291
+
292
+ /**
293
+ * Untag a uint16.
294
+ *
295
+ * @param int: The uint16 to untag
296
+ * @returns The untagged uint16
297
+ */
298
+ @unsafe
299
+ provide primitive untagUint16 = "@untag.uint16"