@grain/stdlib 0.6.6 → 0.7.1

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 (137) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/LICENSE +1 -1
  3. package/README.md +2 -2
  4. package/array.gr +55 -7
  5. package/array.md +606 -560
  6. package/bigint.md +228 -228
  7. package/buffer.gr +85 -53
  8. package/buffer.md +442 -319
  9. package/bytes.gr +112 -35
  10. package/bytes.md +299 -219
  11. package/char.gr +201 -99
  12. package/char.md +447 -120
  13. package/exception.gr +11 -11
  14. package/exception.md +29 -4
  15. package/float32.gr +327 -3
  16. package/float32.md +698 -111
  17. package/float64.gr +320 -3
  18. package/float64.md +698 -111
  19. package/fs.gr +1082 -0
  20. package/fs.md +630 -0
  21. package/hash.gr +142 -88
  22. package/hash.md +105 -17
  23. package/int16.md +178 -178
  24. package/int32.gr +26 -5
  25. package/int32.md +266 -231
  26. package/int64.gr +27 -2
  27. package/int64.md +266 -231
  28. package/int8.md +178 -178
  29. package/json.gr +366 -51
  30. package/json.md +431 -15
  31. package/list.gr +328 -31
  32. package/list.md +759 -336
  33. package/map.gr +20 -12
  34. package/map.md +266 -260
  35. package/marshal.gr +41 -40
  36. package/marshal.md +14 -14
  37. package/number.gr +278 -35
  38. package/number.md +688 -269
  39. package/option.md +162 -162
  40. package/package.json +5 -3
  41. package/path.gr +48 -0
  42. package/path.md +180 -89
  43. package/pervasives.gr +2 -2
  44. package/pervasives.md +275 -275
  45. package/priorityqueue.gr +7 -7
  46. package/priorityqueue.md +131 -131
  47. package/queue.gr +183 -29
  48. package/queue.md +404 -148
  49. package/random.md +43 -43
  50. package/range.gr +4 -4
  51. package/range.md +42 -42
  52. package/rational.md +123 -123
  53. package/regex.gr +52 -51
  54. package/regex.md +102 -102
  55. package/result.md +118 -118
  56. package/runtime/atof/common.md +39 -39
  57. package/runtime/atof/decimal.gr +6 -6
  58. package/runtime/atof/decimal.md +14 -14
  59. package/runtime/atof/lemire.gr +5 -5
  60. package/runtime/atof/lemire.md +1 -1
  61. package/runtime/atof/parse.gr +16 -16
  62. package/runtime/atof/parse.md +2 -2
  63. package/runtime/atof/slow.md +1 -1
  64. package/runtime/atof/table.md +2 -2
  65. package/runtime/atoi/parse.gr +3 -3
  66. package/runtime/atoi/parse.md +1 -1
  67. package/runtime/bigint.gr +15 -47
  68. package/runtime/bigint.md +54 -60
  69. package/runtime/compare.gr +2 -2
  70. package/runtime/compare.md +8 -8
  71. package/runtime/dataStructures.md +211 -211
  72. package/runtime/debugPrint.gr +4 -1
  73. package/runtime/debugPrint.md +9 -9
  74. package/runtime/equal.gr +99 -77
  75. package/runtime/equal.md +8 -8
  76. package/runtime/exception.gr +62 -82
  77. package/runtime/exception.md +62 -11
  78. package/runtime/gc.gr +39 -45
  79. package/runtime/gc.md +4 -4
  80. package/runtime/malloc.gr +7 -7
  81. package/runtime/malloc.md +13 -13
  82. package/runtime/math/kernel/cos.gr +70 -0
  83. package/runtime/math/kernel/cos.md +14 -0
  84. package/runtime/math/kernel/sin.gr +65 -0
  85. package/runtime/math/kernel/sin.md +14 -0
  86. package/runtime/math/kernel/tan.gr +136 -0
  87. package/runtime/math/kernel/tan.md +14 -0
  88. package/runtime/math/rempio2.gr +244 -0
  89. package/runtime/math/rempio2.md +14 -0
  90. package/runtime/math/trig.gr +130 -0
  91. package/runtime/math/trig.md +28 -0
  92. package/runtime/math/umuldi.gr +26 -0
  93. package/runtime/math/umuldi.md +14 -0
  94. package/runtime/numberUtils.gr +29 -29
  95. package/runtime/numberUtils.md +12 -12
  96. package/runtime/numbers.gr +373 -381
  97. package/runtime/numbers.md +348 -342
  98. package/runtime/string.gr +37 -105
  99. package/runtime/string.md +20 -26
  100. package/runtime/unsafe/constants.md +24 -24
  101. package/runtime/unsafe/conv.md +19 -19
  102. package/runtime/unsafe/memory.gr +24 -20
  103. package/runtime/unsafe/memory.md +27 -7
  104. package/runtime/unsafe/offsets.gr +36 -0
  105. package/runtime/unsafe/offsets.md +88 -0
  106. package/runtime/unsafe/panic.gr +28 -0
  107. package/runtime/unsafe/panic.md +14 -0
  108. package/runtime/unsafe/tags.md +32 -32
  109. package/runtime/unsafe/wasmf32.md +28 -28
  110. package/runtime/unsafe/wasmf64.md +28 -28
  111. package/runtime/unsafe/wasmi32.md +47 -47
  112. package/runtime/unsafe/wasmi64.md +50 -50
  113. package/runtime/utf8.gr +189 -0
  114. package/runtime/utf8.md +117 -0
  115. package/runtime/wasi.gr +4 -2
  116. package/runtime/wasi.md +147 -147
  117. package/set.gr +18 -11
  118. package/set.md +253 -247
  119. package/stack.gr +171 -2
  120. package/stack.md +371 -89
  121. package/string.gr +352 -557
  122. package/string.md +298 -255
  123. package/uint16.md +170 -170
  124. package/uint32.gr +25 -4
  125. package/uint32.md +249 -214
  126. package/uint64.gr +25 -5
  127. package/uint64.md +249 -214
  128. package/uint8.md +170 -170
  129. package/uri.gr +57 -53
  130. package/uri.md +88 -89
  131. package/wasi/file.gr +67 -59
  132. package/wasi/file.md +308 -308
  133. package/wasi/process.md +26 -26
  134. package/wasi/random.md +12 -12
  135. package/wasi/time.md +16 -16
  136. package/runtime/utils/printing.gr +0 -60
  137. package/runtime/utils/printing.md +0 -26
@@ -22,234 +22,234 @@ Functions and constants included in the Common module.
22
22
  ### Common.**_MINIMUM_EXPONENT**
23
23
 
24
24
  ```grain
25
- _MINIMUM_EXPONENT : WasmI32
25
+ _MINIMUM_EXPONENT: WasmI32
26
26
  ```
27
27
 
28
28
  ### Common.**_MIN_EXPONENT_ROUND_TO_EVEN**
29
29
 
30
30
  ```grain
31
- _MIN_EXPONENT_ROUND_TO_EVEN : WasmI64
31
+ _MIN_EXPONENT_ROUND_TO_EVEN: WasmI64
32
32
  ```
33
33
 
34
34
  ### Common.**_MAX_EXPONENT_ROUND_TO_EVEN**
35
35
 
36
36
  ```grain
37
- _MAX_EXPONENT_ROUND_TO_EVEN : WasmI64
37
+ _MAX_EXPONENT_ROUND_TO_EVEN: WasmI64
38
38
  ```
39
39
 
40
40
  ### Common.**_MIN_EXPONENT_FAST_PATH**
41
41
 
42
42
  ```grain
43
- _MIN_EXPONENT_FAST_PATH : WasmI32
43
+ _MIN_EXPONENT_FAST_PATH: WasmI32
44
44
  ```
45
45
 
46
46
  ### Common.**_MAX_EXPONENT_FAST_PATH**
47
47
 
48
48
  ```grain
49
- _MAX_EXPONENT_FAST_PATH : WasmI32
49
+ _MAX_EXPONENT_FAST_PATH: WasmI32
50
50
  ```
51
51
 
52
52
  ### Common.**_MAX_EXPONENT_DISGUISED_FAST_PATH**
53
53
 
54
54
  ```grain
55
- _MAX_EXPONENT_DISGUISED_FAST_PATH : WasmI32
55
+ _MAX_EXPONENT_DISGUISED_FAST_PATH: WasmI32
56
56
  ```
57
57
 
58
58
  ### Common.**_MAX_MANTISSA_FAST_PATH**
59
59
 
60
60
  ```grain
61
- _MAX_MANTISSA_FAST_PATH : WasmI64
61
+ _MAX_MANTISSA_FAST_PATH: WasmI64
62
62
  ```
63
63
 
64
64
  ### Common.**_MANTISSA_EXPLICIT_BITS_64**
65
65
 
66
66
  ```grain
67
- _MANTISSA_EXPLICIT_BITS_64 : WasmI64
67
+ _MANTISSA_EXPLICIT_BITS_64: WasmI64
68
68
  ```
69
69
 
70
70
  ### Common.**_MANTISSA_EXPLICIT_BITS_32**
71
71
 
72
72
  ```grain
73
- _MANTISSA_EXPLICIT_BITS_32 : WasmI32
73
+ _MANTISSA_EXPLICIT_BITS_32: WasmI32
74
74
  ```
75
75
 
76
76
  ### Common.**_INFINITE_POWER**
77
77
 
78
78
  ```grain
79
- _INFINITE_POWER : WasmI32
79
+ _INFINITE_POWER: WasmI32
80
80
  ```
81
81
 
82
82
  ### Common.**_SMALLEST_POWER_OF_TEN**
83
83
 
84
84
  ```grain
85
- _SMALLEST_POWER_OF_TEN : WasmI64
85
+ _SMALLEST_POWER_OF_TEN: WasmI64
86
86
  ```
87
87
 
88
88
  ### Common.**_LARGEST_POWER_OF_TEN**
89
89
 
90
90
  ```grain
91
- _LARGEST_POWER_OF_TEN : WasmI64
91
+ _LARGEST_POWER_OF_TEN: WasmI64
92
92
  ```
93
93
 
94
94
  ### Common.**_SMALLEST_POWER_OF_FIVE**
95
95
 
96
96
  ```grain
97
- _SMALLEST_POWER_OF_FIVE : WasmI64
97
+ _SMALLEST_POWER_OF_FIVE: WasmI64
98
98
  ```
99
99
 
100
100
  ### Common.**_LARGEST_POWER_OF_FIVE**
101
101
 
102
102
  ```grain
103
- _LARGEST_POWER_OF_FIVE : WasmI64
103
+ _LARGEST_POWER_OF_FIVE: WasmI64
104
104
  ```
105
105
 
106
106
  ### Common.**_CHAR_CODE_UNDERSCORE**
107
107
 
108
108
  ```grain
109
- _CHAR_CODE_UNDERSCORE : WasmI32
109
+ _CHAR_CODE_UNDERSCORE: WasmI32
110
110
  ```
111
111
 
112
112
  ### Common.**_CHAR_CODE_PLUS**
113
113
 
114
114
  ```grain
115
- _CHAR_CODE_PLUS : WasmI32
115
+ _CHAR_CODE_PLUS: WasmI32
116
116
  ```
117
117
 
118
118
  ### Common.**_CHAR_CODE_MINUS**
119
119
 
120
120
  ```grain
121
- _CHAR_CODE_MINUS : WasmI32
121
+ _CHAR_CODE_MINUS: WasmI32
122
122
  ```
123
123
 
124
124
  ### Common.**_CHAR_CODE_0**
125
125
 
126
126
  ```grain
127
- _CHAR_CODE_0 : WasmI32
127
+ _CHAR_CODE_0: WasmI32
128
128
  ```
129
129
 
130
130
  ### Common.**_CHAR_CODE_e**
131
131
 
132
132
  ```grain
133
- _CHAR_CODE_e : WasmI32
133
+ _CHAR_CODE_e: WasmI32
134
134
  ```
135
135
 
136
136
  ### Common.**_CHAR_CODE_E**
137
137
 
138
138
  ```grain
139
- _CHAR_CODE_E : WasmI32
139
+ _CHAR_CODE_E: WasmI32
140
140
  ```
141
141
 
142
142
  ### Common.**_CHAR_CODE_DOT**
143
143
 
144
144
  ```grain
145
- _CHAR_CODE_DOT : WasmI32
145
+ _CHAR_CODE_DOT: WasmI32
146
146
  ```
147
147
 
148
148
  ### Common.**_CHAR_CODE_A**
149
149
 
150
150
  ```grain
151
- _CHAR_CODE_A : WasmI32
151
+ _CHAR_CODE_A: WasmI32
152
152
  ```
153
153
 
154
154
  ### Common.**_CHAR_CODE_Z**
155
155
 
156
156
  ```grain
157
- _CHAR_CODE_Z : WasmI32
157
+ _CHAR_CODE_Z: WasmI32
158
158
  ```
159
159
 
160
160
  ### Common.**_CHAR_CODE_a**
161
161
 
162
162
  ```grain
163
- _CHAR_CODE_a : WasmI32
163
+ _CHAR_CODE_a: WasmI32
164
164
  ```
165
165
 
166
166
  ### Common.**_CHAR_CODE_f**
167
167
 
168
168
  ```grain
169
- _CHAR_CODE_f : WasmI32
169
+ _CHAR_CODE_f: WasmI32
170
170
  ```
171
171
 
172
172
  ### Common.**_CHAR_CODE_i**
173
173
 
174
174
  ```grain
175
- _CHAR_CODE_i : WasmI32
175
+ _CHAR_CODE_i: WasmI32
176
176
  ```
177
177
 
178
178
  ### Common.**_CHAR_CODE_n**
179
179
 
180
180
  ```grain
181
- _CHAR_CODE_n : WasmI32
181
+ _CHAR_CODE_n: WasmI32
182
182
  ```
183
183
 
184
184
  ### Common.**_CHAR_CODE_t**
185
185
 
186
186
  ```grain
187
- _CHAR_CODE_t : WasmI32
187
+ _CHAR_CODE_t: WasmI32
188
188
  ```
189
189
 
190
190
  ### Common.**_CHAR_CODE_y**
191
191
 
192
192
  ```grain
193
- _CHAR_CODE_y : WasmI32
193
+ _CHAR_CODE_y: WasmI32
194
194
  ```
195
195
 
196
196
  ### Common.**fpZero**
197
197
 
198
198
  ```grain
199
- fpZero : () => BiasedFp
199
+ fpZero: () => BiasedFp
200
200
  ```
201
201
 
202
202
  ### Common.**fpInf**
203
203
 
204
204
  ```grain
205
- fpInf : () => BiasedFp
205
+ fpInf: () => BiasedFp
206
206
  ```
207
207
 
208
208
  ### Common.**fpErr**
209
209
 
210
210
  ```grain
211
- fpErr : () => BiasedFp
211
+ fpErr: () => BiasedFp
212
212
  ```
213
213
 
214
214
  ### Common.**fpNan**
215
215
 
216
216
  ```grain
217
- fpNan : () => BiasedFp
217
+ fpNan: () => BiasedFp
218
218
  ```
219
219
 
220
220
  ### Common.**getPowers10**
221
221
 
222
222
  ```grain
223
- getPowers10 : (i: WasmI32) => WasmI32
223
+ getPowers10: (i: WasmI32) => WasmI32
224
224
  ```
225
225
 
226
226
  ### Common.**getPowers10FastPath**
227
227
 
228
228
  ```grain
229
- getPowers10FastPath : (i: WasmI32) => WasmF64
229
+ getPowers10FastPath: (i: WasmI32) => WasmF64
230
230
  ```
231
231
 
232
232
  ### Common.**is8Digits**
233
233
 
234
234
  ```grain
235
- is8Digits : (value: WasmI64) => Bool
235
+ is8Digits: (value: WasmI64) => Bool
236
236
  ```
237
237
 
238
238
  ### Common.**power**
239
239
 
240
240
  ```grain
241
- power : (q: WasmI32) => WasmI32
241
+ power: (q: WasmI32) => WasmI32
242
242
  ```
243
243
 
244
244
  ### Common.**fullMultiplication**
245
245
 
246
246
  ```grain
247
- fullMultiplication : (a: WasmI64, b: WasmI64) => (Int64, Int64)
247
+ fullMultiplication: (a: WasmI64, b: WasmI64) => (Int64, Int64)
248
248
  ```
249
249
 
250
250
  ### Common.**biasedFpToNumber**
251
251
 
252
252
  ```grain
253
- biasedFpToNumber : (fp: BiasedFp, negative: Bool) => Number
253
+ biasedFpToNumber: (fp: BiasedFp, negative: Bool) => Number
254
254
  ```
255
255
 
@@ -140,8 +140,8 @@ let trim = d => {
140
140
  let digits = WasmI32.fromGrain(d.digits)
141
141
  let mut numDigits = WasmI32.load(WasmI32.fromGrain(d.numDigits), 4n)
142
142
  while (
143
- numDigits != 0n &&
144
- WasmI32.eqz(WasmI32.load8U(digits + (numDigits - 1n), 8n))
143
+ numDigits != 0n
144
+ && WasmI32.eqz(WasmI32.load8U(digits + (numDigits - 1n), 8n))
145
145
  ) {
146
146
  numDigits -= 1n
147
147
  }
@@ -173,8 +173,8 @@ provide let round = d => {
173
173
  let dpDigit = WasmI32.load8U(digits + dp, 8n)
174
174
  roundUp = dpDigit >= 5n
175
175
  if (dpDigit == 5n && dp + 1n == numDigits) {
176
- roundUp = d.truncated ||
177
- dp != 0n && (1n & WasmI32.load8U(digits + dp - 1n, 8n)) != 0n
176
+ roundUp = d.truncated
177
+ || dp != 0n && (1n & WasmI32.load8U(digits + dp - 1n, 8n)) != 0n
178
178
  }
179
179
  }
180
180
  if (roundUp) {
@@ -381,8 +381,8 @@ provide let leftShift = (d, shift) => {
381
381
  writeIndex -= 1n
382
382
  n = addWasmI64(
383
383
  n,
384
- WasmI64.extendI32U(WasmI32.load8U(digits + readIndex, 8n)) <<
385
- WasmI64.extendI32U(shift)
384
+ WasmI64.extendI32U(WasmI32.load8U(digits + readIndex, 8n))
385
+ << WasmI64.extendI32U(shift)
386
386
  )
387
387
  let quotient = n / 10N
388
388
  let remainder = subWasmI64(n, 10N * quotient)
@@ -19,12 +19,12 @@ record Decimal {
19
19
 
20
20
  Fields:
21
21
 
22
- |name|type|description|
23
- |----|----|-----------|
24
- |`numDigits`|`Int32`|The number of significant digits in the decimal.|
25
- |`decimalPoint`|`Int32`|The offset of the decimal point in the significant digits.|
26
- |`truncated`|`Bool`|If the number of significant digits stored in the decimal is truncated.|
27
- |`digits`|`Bytes`|Buffer of the raw digits, in the range [0, 9].|
22
+ | name | type | description |
23
+ | -------------- | ------- | ----------------------------------------------------------------------- |
24
+ | `numDigits` | `Int32` | The number of significant digits in the decimal. |
25
+ | `decimalPoint` | `Int32` | The offset of the decimal point in the significant digits. |
26
+ | `truncated` | `Bool` | If the number of significant digits stored in the decimal is truncated. |
27
+ | `digits` | `Bytes` | Buffer of the raw digits, in the range [0, 9]. |
28
28
 
29
29
  ## Values
30
30
 
@@ -33,48 +33,48 @@ Functions and constants included in the Decimal module.
33
33
  ### Decimal.**_DECIMAL_POINT_RANGE**
34
34
 
35
35
  ```grain
36
- _DECIMAL_POINT_RANGE : WasmI32
36
+ _DECIMAL_POINT_RANGE: WasmI32
37
37
  ```
38
38
 
39
39
  ### Decimal.**tryAddDigit**
40
40
 
41
41
  ```grain
42
- tryAddDigit : (d: Decimal, digit: WasmI32) => Void
42
+ tryAddDigit: (d: Decimal, digit: WasmI32) => Void
43
43
  ```
44
44
 
45
45
  ### Decimal.**round**
46
46
 
47
47
  ```grain
48
- round : (d: Decimal) => WasmI64
48
+ round: (d: Decimal) => WasmI64
49
49
  ```
50
50
 
51
51
  ### Decimal.**get_TABLE**
52
52
 
53
53
  ```grain
54
- get_TABLE : () => WasmI32
54
+ get_TABLE: () => WasmI32
55
55
  ```
56
56
 
57
57
  ### Decimal.**get_TABLE_POW5**
58
58
 
59
59
  ```grain
60
- get_TABLE_POW5 : () => WasmI32
60
+ get_TABLE_POW5: () => WasmI32
61
61
  ```
62
62
 
63
63
  ### Decimal.**leftShift**
64
64
 
65
65
  ```grain
66
- leftShift : (d: Decimal, shift: WasmI32) => Void
66
+ leftShift: (d: Decimal, shift: WasmI32) => Void
67
67
  ```
68
68
 
69
69
  ### Decimal.**rightShift**
70
70
 
71
71
  ```grain
72
- rightShift : (d: Decimal, shift: WasmI32) => Void
72
+ rightShift: (d: Decimal, shift: WasmI32) => Void
73
73
  ```
74
74
 
75
75
  ### Decimal.**parseDecimal**
76
76
 
77
77
  ```grain
78
- parseDecimal : (s: String) => Decimal
78
+ parseDecimal: (s: String) => Decimal
79
79
  ```
80
80
 
@@ -203,11 +203,11 @@ provide let computeFloat = (exponent: WasmI64, mantissa: WasmI64) => {
203
203
  //
204
204
  // Or, we may fall between two floats: we are exactly halfway.
205
205
  if (
206
- WasmI64.leU(lo, 1N) &&
207
- q >= _MIN_EXPONENT_ROUND_TO_EVEN &&
208
- q <= _MAX_EXPONENT_ROUND_TO_EVEN &&
209
- (mantissa & 3N) == 1N &&
210
- mantissa << WasmI64.extendI32S({
206
+ WasmI64.leU(lo, 1N)
207
+ && q >= _MIN_EXPONENT_ROUND_TO_EVEN
208
+ && q <= _MAX_EXPONENT_ROUND_TO_EVEN
209
+ && (mantissa & 3N) == 1N
210
+ && mantissa << WasmI64.extendI32S({
211
211
  use WasmI32.{ (+), (-) }
212
212
  upperbit + 64n - _MANTISSA_EXPLICIT_BITS_32 - 3n
213
213
  }) == hi
@@ -9,6 +9,6 @@ Functions and constants included in the Lemire module.
9
9
  ### Lemire.**computeFloat**
10
10
 
11
11
  ```grain
12
- computeFloat : (exponent: WasmI64, mantissa: WasmI64) => Common.BiasedFp
12
+ computeFloat: (exponent: WasmI64, mantissa: WasmI64) => Common.BiasedFp
13
13
  ```
14
14
 
@@ -419,16 +419,16 @@ let parseInfNan = s => {
419
419
  }
420
420
 
421
421
  if (
422
- len - i == 3n &&
423
- c1 == _CHAR_CODE_n &&
424
- c2 == _CHAR_CODE_a &&
425
- c3 == _CHAR_CODE_n
422
+ len - i == 3n
423
+ && c1 == _CHAR_CODE_n
424
+ && c2 == _CHAR_CODE_a
425
+ && c3 == _CHAR_CODE_n
426
426
  ) {
427
427
  Ok((fpNan(), negative))
428
428
  } else if (
429
- c1 == _CHAR_CODE_i &&
430
- c2 == _CHAR_CODE_n &&
431
- c3 == _CHAR_CODE_f
429
+ c1 == _CHAR_CODE_i
430
+ && c2 == _CHAR_CODE_n
431
+ && c3 == _CHAR_CODE_f
432
432
  ) {
433
433
  if (len - i == 3n) {
434
434
  Ok((fpInf(), negative))
@@ -455,11 +455,11 @@ let parseInfNan = s => {
455
455
  }
456
456
 
457
457
  if (
458
- c4 == _CHAR_CODE_i &&
459
- c5 == _CHAR_CODE_n &&
460
- c6 == _CHAR_CODE_i &&
461
- c7 == _CHAR_CODE_t &&
462
- c8 == _CHAR_CODE_y
458
+ c4 == _CHAR_CODE_i
459
+ && c5 == _CHAR_CODE_n
460
+ && c6 == _CHAR_CODE_i
461
+ && c7 == _CHAR_CODE_t
462
+ && c8 == _CHAR_CODE_y
463
463
  ) {
464
464
  Ok((fpInf(), negative))
465
465
  } else {
@@ -486,10 +486,10 @@ provide let isFastPath = (
486
486
  use WasmI32.{ (<=) }
487
487
  use WasmI64.{ (<<) }
488
488
 
489
- _MIN_EXPONENT_FAST_PATH <= exponent &&
490
- exponent <= _MAX_EXPONENT_DISGUISED_FAST_PATH &&
491
- WasmI64.leU(mantissa, _MAX_MANTISSA_FAST_PATH) &&
492
- !manyDigits
489
+ _MIN_EXPONENT_FAST_PATH <= exponent
490
+ && exponent <= _MAX_EXPONENT_DISGUISED_FAST_PATH
491
+ && WasmI64.leU(mantissa, _MAX_MANTISSA_FAST_PATH)
492
+ && !manyDigits
493
493
  }
494
494
 
495
495
  @unsafe
@@ -9,7 +9,7 @@ Functions and constants included in the Parse module.
9
9
  ### Parse.**isFastPath**
10
10
 
11
11
  ```grain
12
- isFastPath :
12
+ isFastPath:
13
13
  (exponent: WasmI32, mantissa: WasmI64, negative: Bool, manyDigits: Bool) =>
14
14
  Bool
15
15
  ```
@@ -17,6 +17,6 @@ isFastPath :
17
17
  ### Parse.**parseFloat**
18
18
 
19
19
  ```grain
20
- parseFloat : (string: String) => Result<Number, String>
20
+ parseFloat: (string: String) => Result<Number, String>
21
21
  ```
22
22
 
@@ -9,6 +9,6 @@ Functions and constants included in the Slow module.
9
9
  ### Slow.**parseLongMantissa**
10
10
 
11
11
  ```grain
12
- parseLongMantissa : (s: String) => Common.BiasedFp
12
+ parseLongMantissa: (s: String) => Common.BiasedFp
13
13
  ```
14
14
 
@@ -9,12 +9,12 @@ Functions and constants included in the Table module.
9
9
  ### Table.**get_F64_POWERS10_FAST_PATH**
10
10
 
11
11
  ```grain
12
- get_F64_POWERS10_FAST_PATH : () => WasmI32
12
+ get_F64_POWERS10_FAST_PATH: () => WasmI32
13
13
  ```
14
14
 
15
15
  ### Table.**get_POWERS5**
16
16
 
17
17
  ```grain
18
- get_POWERS5 : () => WasmI32
18
+ get_POWERS5: () => WasmI32
19
19
  ```
20
20
 
@@ -74,9 +74,9 @@ provide let parseInt = (string: String, radix: Number) => {
74
74
 
75
75
  let radix = WasmI32.fromGrain(radix)
76
76
  if (
77
- WasmI32.eqz(radix & Tags._GRAIN_NUMBER_TAG_MASK) ||
78
- radix < WasmI32.fromGrain(2) ||
79
- radix > WasmI32.fromGrain(36)
77
+ WasmI32.eqz(radix & Tags._GRAIN_NUMBER_TAG_MASK)
78
+ || radix < WasmI32.fromGrain(2)
79
+ || radix > WasmI32.fromGrain(36)
80
80
  ) {
81
81
  return Err(ParseIntInvalidRadix)
82
82
  }
@@ -50,6 +50,6 @@ Functions and constants included in the Parse module.
50
50
  ### Parse.**parseInt**
51
51
 
52
52
  ```grain
53
- parseInt : (string: String, radix: Number) => Result<Number, ParseIntError>
53
+ parseInt: (string: String, radix: Number) => Result<Number, ParseIntError>
54
54
  ```
55
55
 
package/runtime/bigint.gr CHANGED
@@ -25,7 +25,6 @@ from "runtime/unsafe/wasmf32" include WasmF32
25
25
  from "runtime/unsafe/wasmf64" include WasmF64
26
26
  from "runtime/exception" include Exception
27
27
  from "runtime/dataStructures" include DataStructures as DS
28
- from "runtime/utils/printing" include Printing as RPrint
29
28
 
30
29
  // things we need which are missing due to --no-pervasives:
31
30
  primitive (!) = "@not"
@@ -131,34 +130,6 @@ let init = (limbs: WasmI32) => {
131
130
  ptr
132
131
  }
133
132
 
134
- // For debugging
135
- @unsafe
136
- provide let debugDumpNumber = (num: WasmI32) => {
137
- use WasmI32.{ (*), (+), (-), (&), (>>>), (<) }
138
- //let num = WasmI32.fromGrain(num)
139
- RPrint.printString("-=-=-=-== debug dump ==-=-=-=-")
140
- RPrint.printString("Ref Count:")
141
- RPrint.printNumber(WasmI64.extendI32U(WasmI32.load(num - 8n, 0n)))
142
- RPrint.printString("Heap Tag:")
143
- RPrint.printNumber(WasmI64.extendI32U(WasmI32.load(num, 0n)))
144
- RPrint.printString("Boxed Num Tag:")
145
- RPrint.printNumber(WasmI64.extendI32U(WasmI32.load(num, 4n)))
146
- RPrint.printString("Num Limbs:")
147
- let limbs = WasmI32.load(num, 8n)
148
- RPrint.printNumber(WasmI64.extendI32U(limbs))
149
- RPrint.printString("Flags:")
150
- RPrint.printNumber(WasmI64.extendI32U(0xffffn & WasmI32.load(num, 12n)))
151
- RPrint.printString("<reserved>:")
152
- RPrint.printNumber(
153
- WasmI64.extendI32U((0xffff0000n & WasmI32.load(num, 12n)) >>> 16n)
154
- )
155
- RPrint.printString("Limbs:")
156
- for (let mut i = 0n; i < limbs; i += 1n) {
157
- // if a nonzero limb is found, then we're at the min
158
- RPrint.printNumber(WasmI64.load(num, (i + 2n) * 8n))
159
- }
160
- }
161
-
162
133
  @unsafe
163
134
  provide let getSize = ptr => {
164
135
  WasmI32.load(ptr, 8n)
@@ -222,8 +193,8 @@ let getHalfSize = ptr => {
222
193
  use WasmI32.{ (-), (<<), gtU as (>) }
223
194
  use WasmI64.{ (>>>) }
224
195
  if (
225
- size > 0n &&
226
- WasmI32.eqz(WasmI32.wrapI64(getLimb(ptr, size - 1n) >>> 32N))
196
+ size > 0n
197
+ && WasmI32.eqz(WasmI32.wrapI64(getLimb(ptr, size - 1n) >>> 32N))
227
198
  ) {
228
199
  // last half-limb is trailing zeros
229
200
  (size << 1n) - 1n
@@ -521,11 +492,8 @@ provide let toFloat64 = (num: WasmI32) => {
521
492
  let mut result = 0.0W
522
493
  use WasmI32.{ (+) }
523
494
  for (let mut i = 0n; WasmI32.ltU(i, numLimbs); i += 1n) {
524
- if (!WasmI32.eqz(i)) {
525
- result *= factor
526
- }
527
495
  use WasmF64.{ (+) }
528
- result += WasmF64.convertI64U(getLimb(num, i))
496
+ result += WasmF64.convertI64U(getLimb(num, i)) * factor
529
497
  }
530
498
  result
531
499
  }
@@ -798,8 +766,8 @@ provide let bigIntToString = (num: WasmI32, base: WasmI32) => {
798
766
  let bits = WasmI64.extendI32U(WasmI32.ctz(base))
799
767
  let mask = (1N << bits) - 1N
800
768
  let numLimbs = getSize(num)
801
- let totalBits = 64N * WasmI64.extendI32U(numLimbs) -
802
- WasmI64.clz(getLimb(num, subWasmI32(numLimbs, 1n)))
769
+ let totalBits = 64N * WasmI64.extendI32U(numLimbs)
770
+ - WasmI64.clz(getLimb(num, subWasmI32(numLimbs, 1n)))
803
771
  let mut acc = 0N
804
772
  let mut accBits = 0N
805
773
  for (let mut i = 0n; i < numLimbs; i += 1n) {
@@ -1230,8 +1198,8 @@ let unsignedMul = (num1: WasmI32, num2: WasmI32) => {
1230
1198
  let curHalfLimb = getHalfLimb(dest, j + i)
1231
1199
  let halfLimb1 = getHalfLimb(num1, i)
1232
1200
  use WasmI64.{ (+) }
1233
- tmp += WasmI64.extendI32U(curHalfLimb) +
1234
- WasmI64.extendI32U(halfLimb1) * WasmI64.extendI32U(halfLimb2)
1201
+ tmp += WasmI64.extendI32U(curHalfLimb)
1202
+ + WasmI64.extendI32U(halfLimb1) * WasmI64.extendI32U(halfLimb2)
1235
1203
  use WasmI32.{ (+) }
1236
1204
  setHalfLimb(dest, j + i, WasmI32.wrapI64(tmp))
1237
1205
  tmp = tmp >>> 32N
@@ -1285,8 +1253,8 @@ provide let shl = (num: WasmI32, places: WasmI32) => {
1285
1253
  let mut carry = 0N
1286
1254
  let a = places / 32n
1287
1255
  let b = places % 32n
1288
- let mask = ((1N << WasmI64.extendI32U(b)) - 1N) <<
1289
- (64N - WasmI64.extendI32U(b))
1256
+ let mask = ((1N << WasmI64.extendI32U(b)) - 1N)
1257
+ << (64N - WasmI64.extendI32U(b))
1290
1258
  let result = init(numLimbs + a)
1291
1259
  setFlag(result, _IS_NEGATIVE, getFlag(num, _IS_NEGATIVE))
1292
1260
  use WasmI32.{ (<<) }
@@ -1855,8 +1823,8 @@ let division = (
1855
1823
  r = WasmI32.load(result, 4n)
1856
1824
  Memory.free(result)
1857
1825
  if (
1858
- flagIsSet(num1, _IS_NEGATIVE) && !flagIsSet(num2, _IS_NEGATIVE) ||
1859
- !flagIsSet(num1, _IS_NEGATIVE) && flagIsSet(num2, _IS_NEGATIVE)
1826
+ flagIsSet(num1, _IS_NEGATIVE) && !flagIsSet(num2, _IS_NEGATIVE)
1827
+ || !flagIsSet(num1, _IS_NEGATIVE) && flagIsSet(num2, _IS_NEGATIVE)
1860
1828
  ) {
1861
1829
  // fix sign for negative div by positive & vice versa
1862
1830
  q = negateInPlace(q)
@@ -1873,10 +1841,10 @@ let division = (
1873
1841
  // convert truncated division to floor division
1874
1842
  // https://en.wikipedia.org/wiki/Modulo_operation
1875
1843
  if (
1876
- divMod &&
1877
- (
1878
- flagIsSet(r, _IS_NEGATIVE) && !flagIsSet(num2, _IS_NEGATIVE) ||
1879
- !flagIsSet(r, _IS_NEGATIVE) && flagIsSet(num2, _IS_NEGATIVE)
1844
+ divMod
1845
+ && (
1846
+ flagIsSet(r, _IS_NEGATIVE) && !flagIsSet(num2, _IS_NEGATIVE)
1847
+ || !flagIsSet(r, _IS_NEGATIVE) && flagIsSet(num2, _IS_NEGATIVE)
1880
1848
  )
1881
1849
  ) {
1882
1850
  let newr = add(r, num2)