@grain/stdlib 0.5.13 → 0.6.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.
- package/CHANGELOG.md +201 -0
- package/LICENSE +1 -1
- package/README.md +25 -2
- package/array.gr +1512 -199
- package/array.md +2032 -94
- package/bigint.gr +239 -140
- package/bigint.md +450 -106
- package/buffer.gr +595 -102
- package/buffer.md +903 -145
- package/bytes.gr +401 -110
- package/bytes.md +551 -63
- package/char.gr +228 -49
- package/char.md +373 -7
- package/exception.gr +26 -12
- package/exception.md +29 -5
- package/float32.gr +130 -109
- package/float32.md +185 -57
- package/float64.gr +112 -99
- package/float64.md +185 -57
- package/hash.gr +62 -40
- package/hash.md +27 -3
- package/int16.gr +430 -0
- package/int16.md +618 -0
- package/int32.gr +200 -269
- package/int32.md +254 -289
- package/int64.gr +142 -225
- package/int64.md +254 -289
- package/int8.gr +511 -0
- package/int8.md +786 -0
- package/json.gr +2071 -0
- package/json.md +646 -0
- package/list.gr +120 -68
- package/list.md +125 -80
- package/map.gr +560 -57
- package/map.md +672 -56
- package/marshal.gr +239 -227
- package/marshal.md +36 -4
- package/number.gr +626 -676
- package/number.md +738 -153
- package/option.gr +33 -35
- package/option.md +58 -42
- package/package.json +2 -2
- package/path.gr +148 -187
- package/path.md +47 -96
- package/pervasives.gr +75 -416
- package/pervasives.md +85 -180
- package/priorityqueue.gr +433 -74
- package/priorityqueue.md +422 -54
- package/queue.gr +362 -80
- package/queue.md +433 -38
- package/random.gr +67 -75
- package/random.md +68 -40
- package/range.gr +135 -63
- package/range.md +198 -43
- package/rational.gr +284 -0
- package/rational.md +545 -0
- package/regex.gr +933 -1066
- package/regex.md +59 -60
- package/result.gr +23 -25
- package/result.md +54 -39
- package/runtime/atof/common.gr +78 -82
- package/runtime/atof/common.md +22 -10
- package/runtime/atof/decimal.gr +102 -127
- package/runtime/atof/decimal.md +28 -7
- package/runtime/atof/lemire.gr +56 -71
- package/runtime/atof/lemire.md +9 -1
- package/runtime/atof/parse.gr +83 -110
- package/runtime/atof/parse.md +12 -2
- package/runtime/atof/slow.gr +28 -35
- package/runtime/atof/slow.md +9 -1
- package/runtime/atof/table.gr +19 -18
- package/runtime/atof/table.md +10 -2
- package/runtime/atoi/parse.gr +153 -136
- package/runtime/atoi/parse.md +50 -1
- package/runtime/bigint.gr +410 -517
- package/runtime/bigint.md +71 -57
- package/runtime/compare.gr +176 -85
- package/runtime/compare.md +31 -1
- package/runtime/dataStructures.gr +144 -32
- package/runtime/dataStructures.md +267 -31
- package/runtime/debugPrint.gr +34 -15
- package/runtime/debugPrint.md +37 -5
- package/runtime/equal.gr +53 -52
- package/runtime/equal.md +30 -1
- package/runtime/exception.gr +38 -47
- package/runtime/exception.md +10 -8
- package/runtime/gc.gr +23 -152
- package/runtime/gc.md +13 -17
- package/runtime/malloc.gr +31 -31
- package/runtime/malloc.md +11 -3
- package/runtime/numberUtils.gr +193 -174
- package/runtime/numberUtils.md +29 -9
- package/runtime/numbers.gr +1695 -1021
- package/runtime/numbers.md +1098 -134
- package/runtime/string.gr +543 -245
- package/runtime/string.md +76 -6
- package/runtime/unsafe/constants.gr +30 -13
- package/runtime/unsafe/constants.md +80 -0
- package/runtime/unsafe/conv.gr +55 -28
- package/runtime/unsafe/conv.md +41 -9
- package/runtime/unsafe/memory.gr +10 -30
- package/runtime/unsafe/memory.md +15 -19
- package/runtime/unsafe/tags.gr +37 -21
- package/runtime/unsafe/tags.md +88 -8
- package/runtime/unsafe/wasmf32.gr +30 -36
- package/runtime/unsafe/wasmf32.md +64 -56
- package/runtime/unsafe/wasmf64.gr +30 -36
- package/runtime/unsafe/wasmf64.md +64 -56
- package/runtime/unsafe/wasmi32.gr +49 -66
- package/runtime/unsafe/wasmi32.md +102 -94
- package/runtime/unsafe/wasmi64.gr +52 -79
- package/runtime/unsafe/wasmi64.md +108 -100
- package/runtime/utils/printing.gr +13 -15
- package/runtime/utils/printing.md +11 -3
- package/runtime/wasi.gr +294 -295
- package/runtime/wasi.md +62 -42
- package/set.gr +574 -64
- package/set.md +634 -54
- package/stack.gr +181 -64
- package/stack.md +271 -42
- package/string.gr +453 -533
- package/string.md +241 -151
- package/uint16.gr +369 -0
- package/uint16.md +585 -0
- package/uint32.gr +470 -0
- package/uint32.md +737 -0
- package/uint64.gr +471 -0
- package/uint64.md +737 -0
- package/uint8.gr +369 -0
- package/uint8.md +585 -0
- package/uri.gr +1093 -0
- package/uri.md +477 -0
- package/{sys → wasi}/file.gr +914 -500
- package/{sys → wasi}/file.md +454 -50
- package/wasi/process.gr +292 -0
- package/{sys → wasi}/process.md +164 -6
- package/wasi/random.gr +77 -0
- package/wasi/random.md +80 -0
- package/{sys → wasi}/time.gr +15 -22
- package/{sys → wasi}/time.md +5 -5
- package/immutablearray.gr +0 -929
- package/immutablearray.md +0 -1038
- package/immutablemap.gr +0 -493
- package/immutablemap.md +0 -479
- package/immutablepriorityqueue.gr +0 -360
- package/immutablepriorityqueue.md +0 -291
- package/immutableset.gr +0 -498
- package/immutableset.md +0 -449
- package/runtime/debug.gr +0 -2
- package/runtime/debug.md +0 -6
- package/runtime/unsafe/errors.gr +0 -36
- package/runtime/unsafe/errors.md +0 -204
- package/sys/process.gr +0 -254
- package/sys/random.gr +0 -79
- package/sys/random.md +0 -66
package/runtime/compare.gr
CHANGED
|
@@ -1,29 +1,34 @@
|
|
|
1
|
-
|
|
1
|
+
@noPervasives
|
|
2
|
+
module Compare
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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 (!)
|
|
25
|
-
primitive (||)
|
|
26
|
-
primitive (&&)
|
|
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
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
75
|
-
break
|
|
73
|
+
return sub
|
|
76
74
|
}
|
|
77
75
|
}
|
|
78
76
|
|
|
79
|
-
|
|
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
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
|
|
138
|
-
break
|
|
128
|
+
return sub
|
|
139
129
|
}
|
|
140
130
|
}
|
|
141
131
|
|
|
142
|
-
|
|
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)
|
|
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))
|
|
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
|
-
|
|
178
|
-
compareHelp(WasmI32.fromGrain(
|
|
268
|
+
provide let compare = (num1: a, num2: a) => {
|
|
269
|
+
compareHelp(WasmI32.fromGrain(num1), WasmI32.fromGrain(num2))
|
|
179
270
|
}
|
package/runtime/compare.md
CHANGED
|
@@ -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)
|
|
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
|
-
|
|
1
|
+
@noPervasives
|
|
2
|
+
module DataStructures
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Allocates a new Grain array.
|
|
5
6
|
*
|
|
6
|
-
* @param
|
|
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
|
-
|
|
11
|
+
provide primitive allocateArray = "@allocate.array"
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Allocates a new Grain tuple.
|
|
14
15
|
*
|
|
15
|
-
* @param
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
48
|
+
provide primitive allocateInt32 = "@allocate.int32"
|
|
48
49
|
|
|
49
50
|
/**
|
|
50
51
|
* Allocates a new Int32 with a prepopulated value
|
|
51
|
-
*
|
|
52
|
+
*
|
|
53
|
+
* @param int: The value to store
|
|
52
54
|
* @returns The pointer to the Int32
|
|
53
55
|
*/
|
|
54
56
|
@unsafe
|
|
55
|
-
|
|
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
|
-
|
|
82
|
+
provide primitive allocateInt64 = "@allocate.int64"
|
|
64
83
|
|
|
65
84
|
/**
|
|
66
85
|
* Allocates a new Int64 with a prepopulated value
|
|
67
|
-
*
|
|
86
|
+
*
|
|
87
|
+
* @param int: The value to store
|
|
68
88
|
* @returns The pointer to the Int64
|
|
69
89
|
*/
|
|
70
90
|
@unsafe
|
|
71
|
-
|
|
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
|
-
|
|
118
|
+
provide primitive allocateFloat32 = "@allocate.float32"
|
|
82
119
|
|
|
83
120
|
/**
|
|
84
121
|
* Allocates a new Float32 with a prepopulated value
|
|
85
|
-
*
|
|
122
|
+
*
|
|
123
|
+
* @param float: The value to store
|
|
86
124
|
* @returns the pointer to the Float32
|
|
87
125
|
*/
|
|
88
126
|
@unsafe
|
|
89
|
-
|
|
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
|
-
|
|
135
|
+
provide primitive allocateFloat64 = "@allocate.float64"
|
|
98
136
|
|
|
99
137
|
/**
|
|
100
138
|
* Allocates a new Float64 with a prepopulated value
|
|
101
|
-
*
|
|
139
|
+
*
|
|
140
|
+
* @param float: The value to store
|
|
102
141
|
* @returns The pointer to the Float64
|
|
103
142
|
*/
|
|
104
143
|
@unsafe
|
|
105
|
-
|
|
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
|
-
|
|
154
|
+
provide primitive allocateRational = "@allocate.rational"
|
|
116
155
|
|
|
117
156
|
/**
|
|
118
157
|
* Allocates a new Rational with a prepopulated value
|
|
119
|
-
*
|
|
120
|
-
* @param
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
209
|
+
provide primitive untagSimpleNumber = "@untag.simple_number"
|
|
170
210
|
|
|
171
211
|
/**
|
|
172
212
|
* Tag a char.
|
|
173
213
|
*
|
|
174
|
-
* @param
|
|
214
|
+
* @param char: The usv to tag
|
|
175
215
|
* @returns The tagged char
|
|
176
216
|
*/
|
|
177
217
|
@unsafe
|
|
178
|
-
|
|
218
|
+
provide primitive tagChar = "@tag.char"
|
|
179
219
|
|
|
180
220
|
/**
|
|
181
221
|
* Untag a char.
|
|
182
222
|
*
|
|
183
|
-
* @param
|
|
223
|
+
* @param char: The char to untag
|
|
184
224
|
* @returns The untagged usv
|
|
185
225
|
*/
|
|
186
226
|
@unsafe
|
|
187
|
-
|
|
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"
|