@grain/stdlib 0.4.1 → 0.4.5
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 +63 -0
- package/LICENSE +21 -0
- package/README.md +34 -0
- package/array.gr +200 -89
- package/array.md +81 -5
- package/buffer.gr +93 -36
- package/bytes.gr +512 -407
- package/bytes.md +621 -0
- package/char.gr +119 -55
- package/char.md +200 -0
- package/hash.gr +42 -15
- package/hash.md +44 -0
- package/list.gr +121 -50
- package/map.gr +106 -110
- package/number.gr +37 -1
- package/number.md +66 -0
- package/option.gr +260 -53
- package/option.md +579 -0
- package/package.json +33 -29
- package/pervasives.gr +32 -20
- package/queue.gr +102 -30
- package/queue.md +191 -0
- package/range.gr +26 -26
- package/range.md +1 -1
- package/regex.gr +3055 -0
- package/regex.md +449 -0
- package/result.gr +216 -70
- package/result.md +446 -0
- package/runtime/dataStructures.gr +28 -29
- package/runtime/debug.gr +0 -1
- package/runtime/equal.gr +37 -16
- package/runtime/exception.gr +28 -15
- package/runtime/gc.gr +33 -20
- package/runtime/malloc.gr +19 -11
- package/runtime/numberUtils.gr +208 -105
- package/runtime/numbers.gr +217 -118
- package/runtime/string.gr +150 -59
- package/runtime/stringUtils.gr +176 -0
- package/runtime/unsafe/conv.gr +51 -8
- package/runtime/unsafe/memory.gr +14 -3
- package/runtime/unsafe/printWasm.gr +4 -4
- package/runtime/unsafe/tags.gr +2 -2
- package/runtime/unsafe/wasmf32.gr +9 -2
- package/runtime/unsafe/wasmf64.gr +9 -2
- package/runtime/unsafe/wasmi32.gr +65 -47
- package/runtime/unsafe/wasmi64.gr +78 -50
- package/runtime/wasi.gr +199 -45
- package/set.gr +281 -119
- package/set.md +502 -0
- package/stack.gr +26 -26
- package/stack.md +143 -0
- package/string.gr +697 -329
- package/string.md +815 -0
- package/sys/file.gr +356 -177
- package/sys/process.gr +10 -6
- package/sys/random.gr +3 -6
- package/sys/time.gr +3 -3
package/runtime/unsafe/conv.gr
CHANGED
|
@@ -6,13 +6,13 @@ import WasmF64 from "runtime/unsafe/wasmf64"
|
|
|
6
6
|
import Tags from "runtime/unsafe/tags"
|
|
7
7
|
|
|
8
8
|
@disableGC
|
|
9
|
-
export let toInt32 =
|
|
9
|
+
export let toInt32 = n => {
|
|
10
10
|
let ptr = Memory.malloc(12n)
|
|
11
11
|
WasmI32.store(ptr, Tags._GRAIN_BOXED_NUM_HEAP_TAG, 0n)
|
|
12
12
|
WasmI32.store(ptr, Tags._GRAIN_INT32_BOXED_NUM_TAG, 4n)
|
|
13
13
|
WasmI32.store(ptr, n, 8n)
|
|
14
14
|
|
|
15
|
-
WasmI32.toGrain(ptr)
|
|
15
|
+
WasmI32.toGrain(ptr): Int32
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
@disableGC
|
|
@@ -22,13 +22,13 @@ export let fromInt32 = (n: Int32) => {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
@disableGC
|
|
25
|
-
export let toInt64 =
|
|
25
|
+
export let toInt64 = n => {
|
|
26
26
|
let ptr = Memory.malloc(16n)
|
|
27
27
|
WasmI32.store(ptr, Tags._GRAIN_BOXED_NUM_HEAP_TAG, 0n)
|
|
28
28
|
WasmI32.store(ptr, Tags._GRAIN_INT64_BOXED_NUM_TAG, 4n)
|
|
29
29
|
WasmI64.store(ptr, n, 8n)
|
|
30
30
|
|
|
31
|
-
WasmI32.toGrain(ptr)
|
|
31
|
+
WasmI32.toGrain(ptr): Int64
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
@disableGC
|
|
@@ -38,13 +38,13 @@ export let fromInt64 = (n: Int64) => {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
@disableGC
|
|
41
|
-
export let toFloat32 =
|
|
41
|
+
export let toFloat32 = n => {
|
|
42
42
|
let ptr = Memory.malloc(12n)
|
|
43
43
|
WasmI32.store(ptr, Tags._GRAIN_BOXED_NUM_HEAP_TAG, 0n)
|
|
44
44
|
WasmI32.store(ptr, Tags._GRAIN_FLOAT32_BOXED_NUM_TAG, 4n)
|
|
45
45
|
WasmF32.store(ptr, n, 8n)
|
|
46
46
|
|
|
47
|
-
WasmI32.toGrain(ptr)
|
|
47
|
+
WasmI32.toGrain(ptr): Float32
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
@disableGC
|
|
@@ -54,13 +54,13 @@ export let fromFloat32 = (n: Float32) => {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
@disableGC
|
|
57
|
-
export let toFloat64 =
|
|
57
|
+
export let toFloat64 = n => {
|
|
58
58
|
let ptr = Memory.malloc(16n)
|
|
59
59
|
WasmI32.store(ptr, Tags._GRAIN_BOXED_NUM_HEAP_TAG, 0n)
|
|
60
60
|
WasmI32.store(ptr, Tags._GRAIN_FLOAT64_BOXED_NUM_TAG, 4n)
|
|
61
61
|
WasmF64.store(ptr, n, 8n)
|
|
62
62
|
|
|
63
|
-
WasmI32.toGrain(ptr)
|
|
63
|
+
WasmI32.toGrain(ptr): Float64
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
@disableGC
|
|
@@ -68,3 +68,46 @@ export let fromFloat64 = (n: Float64) => {
|
|
|
68
68
|
let ptr = WasmI32.fromGrain(n)
|
|
69
69
|
WasmF64.load(ptr, 8n)
|
|
70
70
|
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Converts a WasmI32 value to Number.
|
|
74
|
+
*
|
|
75
|
+
* This function is meant to be called from a `@disableGC` context without
|
|
76
|
+
* need to call incRef on the function.
|
|
77
|
+
*
|
|
78
|
+
* @param n: The WasmI32 to convert
|
|
79
|
+
* @returns The value converted to either a simple or a 32 bit heap allocated number.
|
|
80
|
+
*/
|
|
81
|
+
@disableGC
|
|
82
|
+
export let wasmI32ToNumber = (n: WasmI32) => {
|
|
83
|
+
// Follows a little optimization. Instead of testing if n is range of allowed
|
|
84
|
+
// non heap allocated simple numbers (-1073741824n..1073741823n), actually
|
|
85
|
+
// make a simple number, convert it back to WasmI32, and test if it stayed
|
|
86
|
+
// the same. This may sound counter intuitive, but for numbers that fit into
|
|
87
|
+
// the range it is faster than performing the check with WasmI32.geS and
|
|
88
|
+
// WasmI32.leS by about 20%. An additional ~33% is gained by avoiding a
|
|
89
|
+
// call to tagSimpleNumber and instead doing it inline. For the case of
|
|
90
|
+
// numbers not fitting into the range, the cost of these simple ALU
|
|
91
|
+
// instructions are negligible compared to heap allocations.
|
|
92
|
+
|
|
93
|
+
// First step: naively convert to simple number, just like tagSimpleNumber.
|
|
94
|
+
// This will overflow for values not in the range, but it's fine.
|
|
95
|
+
let simple = WasmI32.xor(WasmI32.shl(n, 1n), 1n)
|
|
96
|
+
|
|
97
|
+
// Untag it, just like numbers.untagSimple.
|
|
98
|
+
let untagged = WasmI32.shrS(simple, 1n)
|
|
99
|
+
|
|
100
|
+
let result = if (WasmI32.eq(untagged, n)) {
|
|
101
|
+
// Just test if the untagged number is the same. If it didn't overflow, then
|
|
102
|
+
// we're good. We just need to cast the raw value into a Number at the type
|
|
103
|
+
// system level.
|
|
104
|
+
WasmI32.toGrain(simple): Number
|
|
105
|
+
} else {
|
|
106
|
+
// If it did overflow, then the value differs and we need to discard it and
|
|
107
|
+
// allocate the number on the heap. A boxed 32 bit number actually is the
|
|
108
|
+
// same thing as an Int32. It only needs to be cast into Number.
|
|
109
|
+
let asInt32 = toInt32(n)
|
|
110
|
+
WasmI32.toGrain(WasmI32.fromGrain(asInt32)): Number
|
|
111
|
+
}
|
|
112
|
+
result
|
|
113
|
+
}
|
package/runtime/unsafe/memory.gr
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
/* grainc-flags --compilation-mode=runtime */
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
malloc,
|
|
5
|
+
free,
|
|
6
|
+
incRef,
|
|
7
|
+
decRef,
|
|
8
|
+
utoa32Buffered,
|
|
9
|
+
decimalCount32,
|
|
10
|
+
} from "runtime/gc"
|
|
4
11
|
import WasmI32, {
|
|
5
12
|
add as (+),
|
|
6
13
|
sub as (-),
|
|
7
14
|
shl as (<<),
|
|
8
15
|
eq as (==),
|
|
9
16
|
ne as (!=),
|
|
10
|
-
ltU as (<)
|
|
17
|
+
ltU as (<),
|
|
11
18
|
} from "runtime/unsafe/wasmi32"
|
|
12
19
|
|
|
13
20
|
export malloc
|
|
@@ -48,4 +55,8 @@ export let fill = (dest, c, n) => {
|
|
|
48
55
|
}
|
|
49
56
|
}
|
|
50
57
|
|
|
51
|
-
export primitive compare: (
|
|
58
|
+
export primitive compare: (
|
|
59
|
+
WasmI32,
|
|
60
|
+
WasmI32,
|
|
61
|
+
WasmI32,
|
|
62
|
+
) -> WasmI32 = "@wasm.memory_compare"
|
|
@@ -5,7 +5,7 @@ import Memory from "runtime/unsafe/memory"
|
|
|
5
5
|
// [FIXME] These all leak ATM (grain-lang/grain#791)
|
|
6
6
|
|
|
7
7
|
@disableGC
|
|
8
|
-
export let printI32 =
|
|
8
|
+
export let printI32 = val => {
|
|
9
9
|
Memory.incRef(WasmI32.fromGrain(print))
|
|
10
10
|
Memory.incRef(WasmI32.fromGrain(toString))
|
|
11
11
|
let conv = Conv.toInt32(val)
|
|
@@ -23,7 +23,7 @@ export let printI32 = (val) => {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
@disableGC
|
|
26
|
-
export let printI64 =
|
|
26
|
+
export let printI64 = val => {
|
|
27
27
|
Memory.incRef(WasmI32.fromGrain(print))
|
|
28
28
|
Memory.incRef(WasmI32.fromGrain(toString))
|
|
29
29
|
let conv = Conv.toInt64(val)
|
|
@@ -41,7 +41,7 @@ export let printI64 = (val) => {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
@disableGC
|
|
44
|
-
export let printF32 =
|
|
44
|
+
export let printF32 = val => {
|
|
45
45
|
Memory.incRef(WasmI32.fromGrain(print))
|
|
46
46
|
Memory.incRef(WasmI32.fromGrain(toString))
|
|
47
47
|
let conv = Conv.toFloat32(val)
|
|
@@ -59,7 +59,7 @@ export let printF32 = (val) => {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
@disableGC
|
|
62
|
-
export let printF64 =
|
|
62
|
+
export let printF64 = val => {
|
|
63
63
|
Memory.incRef(WasmI32.fromGrain(print))
|
|
64
64
|
Memory.incRef(WasmI32.fromGrain(toString))
|
|
65
65
|
let conv = Conv.toFloat64(val)
|
package/runtime/unsafe/tags.gr
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* grainc-flags --compilation-mode=runtime */
|
|
2
2
|
|
|
3
|
-
export let _GRAIN_NUMBER_TAG_TYPE
|
|
4
|
-
export let _GRAIN_CONST_TAG_TYPE
|
|
3
|
+
export let _GRAIN_NUMBER_TAG_TYPE = 0b0001n
|
|
4
|
+
export let _GRAIN_CONST_TAG_TYPE = 0b0110n
|
|
5
5
|
export let _GRAIN_GENERIC_HEAP_TAG_TYPE = 0b0000n
|
|
6
6
|
|
|
7
7
|
export let _GRAIN_NUMBER_TAG_MASK = 0b0001n
|
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
// WebAssembly Memory Instructions
|
|
4
4
|
export primitive load: (WasmI32, WasmI32) -> WasmF32 = "@wasm.load_float32"
|
|
5
|
-
export primitive store: (
|
|
5
|
+
export primitive store: (
|
|
6
|
+
WasmI32,
|
|
7
|
+
WasmF32,
|
|
8
|
+
WasmI32,
|
|
9
|
+
) -> Void = "@wasm.store_float32"
|
|
6
10
|
|
|
7
11
|
// WebAssembly Unary Instructions
|
|
8
12
|
export primitive neg: WasmF32 -> WasmF32 = "@wasm.neg_float32"
|
|
@@ -18,7 +22,10 @@ export primitive add: (WasmF32, WasmF32) -> WasmF32 = "@wasm.add_float32"
|
|
|
18
22
|
export primitive sub: (WasmF32, WasmF32) -> WasmF32 = "@wasm.sub_float32"
|
|
19
23
|
export primitive mul: (WasmF32, WasmF32) -> WasmF32 = "@wasm.mul_float32"
|
|
20
24
|
export primitive div: (WasmF32, WasmF32) -> WasmF32 = "@wasm.div_float32"
|
|
21
|
-
export primitive copySign: (
|
|
25
|
+
export primitive copySign: (
|
|
26
|
+
WasmF32,
|
|
27
|
+
WasmF32,
|
|
28
|
+
) -> WasmF32 = "@wasm.copy_sign_float32"
|
|
22
29
|
export primitive min: (WasmF32, WasmF32) -> WasmF32 = "@wasm.min_float32"
|
|
23
30
|
export primitive max: (WasmF32, WasmF32) -> WasmF32 = "@wasm.max_float32"
|
|
24
31
|
export primitive eq: (WasmF32, WasmF32) -> Bool = "@wasm.eq_float32"
|
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
// WebAssembly Memory Instructions
|
|
4
4
|
export primitive load: (WasmI32, WasmI32) -> WasmF64 = "@wasm.load_float64"
|
|
5
|
-
export primitive store: (
|
|
5
|
+
export primitive store: (
|
|
6
|
+
WasmI32,
|
|
7
|
+
WasmF64,
|
|
8
|
+
WasmI32,
|
|
9
|
+
) -> Void = "@wasm.store_float64"
|
|
6
10
|
|
|
7
11
|
// WebAssembly Unary Instructions
|
|
8
12
|
export primitive neg: WasmF64 -> WasmF64 = "@wasm.neg_float64"
|
|
@@ -18,7 +22,10 @@ export primitive add: (WasmF64, WasmF64) -> WasmF64 = "@wasm.add_float64"
|
|
|
18
22
|
export primitive sub: (WasmF64, WasmF64) -> WasmF64 = "@wasm.sub_float64"
|
|
19
23
|
export primitive mul: (WasmF64, WasmF64) -> WasmF64 = "@wasm.mul_float64"
|
|
20
24
|
export primitive div: (WasmF64, WasmF64) -> WasmF64 = "@wasm.div_float64"
|
|
21
|
-
export primitive copySign: (
|
|
25
|
+
export primitive copySign: (
|
|
26
|
+
WasmF64,
|
|
27
|
+
WasmF64,
|
|
28
|
+
) -> WasmF64 = "@wasm.copy_sign_float64"
|
|
22
29
|
export primitive min: (WasmF64, WasmF64) -> WasmF64 = "@wasm.min_float64"
|
|
23
30
|
export primitive max: (WasmF64, WasmF64) -> WasmF64 = "@wasm.max_float64"
|
|
24
31
|
export primitive eq: (WasmF64, WasmF64) -> Bool = "@wasm.eq_float64"
|
|
@@ -1,58 +1,76 @@
|
|
|
1
1
|
/* grainc-flags --compilation-mode=runtime */
|
|
2
2
|
|
|
3
3
|
// WebAssembly Memory Instructions
|
|
4
|
-
export primitive load
|
|
5
|
-
export primitive load8S
|
|
6
|
-
export primitive load8U
|
|
7
|
-
export primitive load16S
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export primitive
|
|
4
|
+
export primitive load: (WasmI32, WasmI32) -> WasmI32 = "@wasm.load_int32"
|
|
5
|
+
export primitive load8S: (WasmI32, WasmI32) -> WasmI32 = "@wasm.load_8_s_int32"
|
|
6
|
+
export primitive load8U: (WasmI32, WasmI32) -> WasmI32 = "@wasm.load_8_u_int32"
|
|
7
|
+
export primitive load16S: (
|
|
8
|
+
WasmI32,
|
|
9
|
+
WasmI32,
|
|
10
|
+
) -> WasmI32 = "@wasm.load_16_s_int32"
|
|
11
|
+
export primitive load16U: (
|
|
12
|
+
WasmI32,
|
|
13
|
+
WasmI32,
|
|
14
|
+
) -> WasmI32 = "@wasm.load_16_u_int32"
|
|
15
|
+
export primitive store: (
|
|
16
|
+
WasmI32,
|
|
17
|
+
WasmI32,
|
|
18
|
+
WasmI32,
|
|
19
|
+
) -> Void = "@wasm.store_int32"
|
|
20
|
+
export primitive store8: (
|
|
21
|
+
WasmI32,
|
|
22
|
+
WasmI32,
|
|
23
|
+
WasmI32,
|
|
24
|
+
) -> Void = "@wasm.store_8_int32"
|
|
25
|
+
export primitive store16: (
|
|
26
|
+
WasmI32,
|
|
27
|
+
WasmI32,
|
|
28
|
+
WasmI32,
|
|
29
|
+
) -> Void = "@wasm.store_16_int32"
|
|
12
30
|
|
|
13
31
|
// WebAssembly Unary Instructions
|
|
14
|
-
export primitive clz
|
|
15
|
-
export primitive ctz
|
|
16
|
-
export primitive popcnt
|
|
17
|
-
export primitive eqz
|
|
32
|
+
export primitive clz: WasmI32 -> WasmI32 = "@wasm.clz_int32"
|
|
33
|
+
export primitive ctz: WasmI32 -> WasmI32 = "@wasm.ctz_int32"
|
|
34
|
+
export primitive popcnt: WasmI32 -> WasmI32 = "@wasm.popcnt_int32"
|
|
35
|
+
export primitive eqz: WasmI32 -> Bool = "@wasm.eq_z_int32"
|
|
18
36
|
|
|
19
37
|
// WebAssembly Binary Instructions
|
|
20
|
-
export primitive add
|
|
21
|
-
export primitive sub
|
|
22
|
-
export primitive mul
|
|
23
|
-
export primitive divS
|
|
24
|
-
export primitive divU
|
|
25
|
-
export primitive remS
|
|
26
|
-
export primitive remU
|
|
27
|
-
export primitive and
|
|
28
|
-
export primitive or
|
|
29
|
-
export primitive xor
|
|
30
|
-
export primitive shl
|
|
31
|
-
export primitive shrS
|
|
32
|
-
export primitive shrU
|
|
33
|
-
export primitive rotl
|
|
34
|
-
export primitive rotr
|
|
35
|
-
export primitive eq
|
|
36
|
-
export primitive ne
|
|
37
|
-
export primitive ltS
|
|
38
|
-
export primitive ltU
|
|
39
|
-
export primitive leS
|
|
40
|
-
export primitive leU
|
|
41
|
-
export primitive gtS
|
|
42
|
-
export primitive gtU
|
|
43
|
-
export primitive geS
|
|
44
|
-
export primitive geU
|
|
38
|
+
export primitive add: (WasmI32, WasmI32) -> WasmI32 = "@wasm.add_int32"
|
|
39
|
+
export primitive sub: (WasmI32, WasmI32) -> WasmI32 = "@wasm.sub_int32"
|
|
40
|
+
export primitive mul: (WasmI32, WasmI32) -> WasmI32 = "@wasm.mul_int32"
|
|
41
|
+
export primitive divS: (WasmI32, WasmI32) -> WasmI32 = "@wasm.div_s_int32"
|
|
42
|
+
export primitive divU: (WasmI32, WasmI32) -> WasmI32 = "@wasm.div_u_int32"
|
|
43
|
+
export primitive remS: (WasmI32, WasmI32) -> WasmI32 = "@wasm.rem_s_int32"
|
|
44
|
+
export primitive remU: (WasmI32, WasmI32) -> WasmI32 = "@wasm.rem_u_int32"
|
|
45
|
+
export primitive and: (WasmI32, WasmI32) -> WasmI32 = "@wasm.and_int32"
|
|
46
|
+
export primitive or: (WasmI32, WasmI32) -> WasmI32 = "@wasm.or_int32"
|
|
47
|
+
export primitive xor: (WasmI32, WasmI32) -> WasmI32 = "@wasm.xor_int32"
|
|
48
|
+
export primitive shl: (WasmI32, WasmI32) -> WasmI32 = "@wasm.shl_int32"
|
|
49
|
+
export primitive shrS: (WasmI32, WasmI32) -> WasmI32 = "@wasm.shr_s_int32"
|
|
50
|
+
export primitive shrU: (WasmI32, WasmI32) -> WasmI32 = "@wasm.shr_u_int32"
|
|
51
|
+
export primitive rotl: (WasmI32, WasmI32) -> WasmI32 = "@wasm.rot_l_int32"
|
|
52
|
+
export primitive rotr: (WasmI32, WasmI32) -> WasmI32 = "@wasm.rot_r_int32"
|
|
53
|
+
export primitive eq: (WasmI32, WasmI32) -> Bool = "@wasm.eq_int32"
|
|
54
|
+
export primitive ne: (WasmI32, WasmI32) -> Bool = "@wasm.ne_int32"
|
|
55
|
+
export primitive ltS: (WasmI32, WasmI32) -> Bool = "@wasm.lt_s_int32"
|
|
56
|
+
export primitive ltU: (WasmI32, WasmI32) -> Bool = "@wasm.lt_u_int32"
|
|
57
|
+
export primitive leS: (WasmI32, WasmI32) -> Bool = "@wasm.le_s_int32"
|
|
58
|
+
export primitive leU: (WasmI32, WasmI32) -> Bool = "@wasm.le_u_int32"
|
|
59
|
+
export primitive gtS: (WasmI32, WasmI32) -> Bool = "@wasm.gt_s_int32"
|
|
60
|
+
export primitive gtU: (WasmI32, WasmI32) -> Bool = "@wasm.gt_u_int32"
|
|
61
|
+
export primitive geS: (WasmI32, WasmI32) -> Bool = "@wasm.ge_s_int32"
|
|
62
|
+
export primitive geU: (WasmI32, WasmI32) -> Bool = "@wasm.ge_u_int32"
|
|
45
63
|
|
|
46
64
|
// WebAssembly Conversion Instructions
|
|
47
|
-
export primitive wrapI64
|
|
48
|
-
export primitive truncF32S
|
|
49
|
-
export primitive truncF32U
|
|
50
|
-
export primitive truncF64S
|
|
51
|
-
export primitive truncF64U
|
|
52
|
-
export primitive reinterpretF32
|
|
53
|
-
export primitive extendS8
|
|
54
|
-
export primitive extendS16
|
|
65
|
+
export primitive wrapI64: WasmI64 -> WasmI32 = "@wasm.wrap_int64"
|
|
66
|
+
export primitive truncF32S: WasmF32 -> WasmI32 = "@wasm.trunc_s_float32_to_int32"
|
|
67
|
+
export primitive truncF32U: WasmF32 -> WasmI32 = "@wasm.trunc_u_float32_to_int32"
|
|
68
|
+
export primitive truncF64S: WasmF64 -> WasmI32 = "@wasm.trunc_s_float64_to_int32"
|
|
69
|
+
export primitive truncF64U: WasmF64 -> WasmI32 = "@wasm.trunc_u_float64_to_int32"
|
|
70
|
+
export primitive reinterpretF32: WasmF32 -> WasmI32 = "@wasm.reinterpret_float32"
|
|
71
|
+
export primitive extendS8: WasmI32 -> WasmI32 = "@wasm.extend_s8_int32"
|
|
72
|
+
export primitive extendS16: WasmI32 -> WasmI32 = "@wasm.extend_s16_int32"
|
|
55
73
|
|
|
56
74
|
// Grain Conversions
|
|
57
|
-
export primitive fromGrain
|
|
58
|
-
export primitive toGrain
|
|
75
|
+
export primitive fromGrain: a -> WasmI32 = "@wasm.fromGrain"
|
|
76
|
+
export primitive toGrain: WasmI32 -> a = "@wasm.toGrain"
|
|
@@ -1,59 +1,87 @@
|
|
|
1
1
|
/* grainc-flags --compilation-mode=runtime */
|
|
2
2
|
|
|
3
3
|
// WebAssembly Memory Instructions
|
|
4
|
-
export primitive load
|
|
5
|
-
export primitive load8S
|
|
6
|
-
export primitive load8U
|
|
7
|
-
export primitive load16S
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export primitive
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
export primitive load: (WasmI32, WasmI32) -> WasmI64 = "@wasm.load_int64"
|
|
5
|
+
export primitive load8S: (WasmI32, WasmI32) -> WasmI64 = "@wasm.load_8_s_int64"
|
|
6
|
+
export primitive load8U: (WasmI32, WasmI32) -> WasmI64 = "@wasm.load_8_u_int64"
|
|
7
|
+
export primitive load16S: (
|
|
8
|
+
WasmI32,
|
|
9
|
+
WasmI32,
|
|
10
|
+
) -> WasmI64 = "@wasm.load_16_s_int64"
|
|
11
|
+
export primitive load16U: (
|
|
12
|
+
WasmI32,
|
|
13
|
+
WasmI32,
|
|
14
|
+
) -> WasmI64 = "@wasm.load_16_u_int64"
|
|
15
|
+
export primitive load32S: (
|
|
16
|
+
WasmI32,
|
|
17
|
+
WasmI32,
|
|
18
|
+
) -> WasmI64 = "@wasm.load_32_s_int64"
|
|
19
|
+
export primitive load32U: (
|
|
20
|
+
WasmI32,
|
|
21
|
+
WasmI32,
|
|
22
|
+
) -> WasmI64 = "@wasm.load_32_u_int64"
|
|
23
|
+
export primitive store: (
|
|
24
|
+
WasmI32,
|
|
25
|
+
WasmI64,
|
|
26
|
+
WasmI32,
|
|
27
|
+
) -> Void = "@wasm.store_int64"
|
|
28
|
+
export primitive store8: (
|
|
29
|
+
WasmI32,
|
|
30
|
+
WasmI64,
|
|
31
|
+
WasmI32,
|
|
32
|
+
) -> Void = "@wasm.store_8_int64"
|
|
33
|
+
export primitive store16: (
|
|
34
|
+
WasmI32,
|
|
35
|
+
WasmI64,
|
|
36
|
+
WasmI32,
|
|
37
|
+
) -> Void = "@wasm.store_16_int64"
|
|
38
|
+
export primitive store32: (
|
|
39
|
+
WasmI32,
|
|
40
|
+
WasmI64,
|
|
41
|
+
WasmI32,
|
|
42
|
+
) -> Void = "@wasm.store_32_int64"
|
|
15
43
|
|
|
16
44
|
// WebAssembly Unary Instructions
|
|
17
|
-
export primitive clz
|
|
18
|
-
export primitive ctz
|
|
19
|
-
export primitive popcnt
|
|
20
|
-
export primitive eqz
|
|
45
|
+
export primitive clz: WasmI64 -> WasmI64 = "@wasm.clz_int64"
|
|
46
|
+
export primitive ctz: WasmI64 -> WasmI64 = "@wasm.ctz_int64"
|
|
47
|
+
export primitive popcnt: WasmI64 -> WasmI64 = "@wasm.popcnt_int64"
|
|
48
|
+
export primitive eqz: WasmI64 -> Bool = "@wasm.eq_z_int64"
|
|
21
49
|
|
|
22
50
|
// WebAssembly Binary Instructions
|
|
23
|
-
export primitive add
|
|
24
|
-
export primitive sub
|
|
25
|
-
export primitive mul
|
|
26
|
-
export primitive divS
|
|
27
|
-
export primitive divU
|
|
28
|
-
export primitive remS
|
|
29
|
-
export primitive remU
|
|
30
|
-
export primitive and
|
|
31
|
-
export primitive or
|
|
32
|
-
export primitive xor
|
|
33
|
-
export primitive shl
|
|
34
|
-
export primitive shrU
|
|
35
|
-
export primitive shrS
|
|
36
|
-
export primitive rotl
|
|
37
|
-
export primitive rotr
|
|
38
|
-
export primitive eq
|
|
39
|
-
export primitive ne
|
|
40
|
-
export primitive ltS
|
|
41
|
-
export primitive ltU
|
|
42
|
-
export primitive leS
|
|
43
|
-
export primitive leU
|
|
44
|
-
export primitive gtS
|
|
45
|
-
export primitive gtU
|
|
46
|
-
export primitive geS
|
|
47
|
-
export primitive geU
|
|
51
|
+
export primitive add: (WasmI64, WasmI64) -> WasmI64 = "@wasm.add_int64"
|
|
52
|
+
export primitive sub: (WasmI64, WasmI64) -> WasmI64 = "@wasm.sub_int64"
|
|
53
|
+
export primitive mul: (WasmI64, WasmI64) -> WasmI64 = "@wasm.mul_int64"
|
|
54
|
+
export primitive divS: (WasmI64, WasmI64) -> WasmI64 = "@wasm.div_s_int64"
|
|
55
|
+
export primitive divU: (WasmI64, WasmI64) -> WasmI64 = "@wasm.div_u_int64"
|
|
56
|
+
export primitive remS: (WasmI64, WasmI64) -> WasmI64 = "@wasm.rem_s_int64"
|
|
57
|
+
export primitive remU: (WasmI64, WasmI64) -> WasmI64 = "@wasm.rem_u_int64"
|
|
58
|
+
export primitive and: (WasmI64, WasmI64) -> WasmI64 = "@wasm.and_int64"
|
|
59
|
+
export primitive or: (WasmI64, WasmI64) -> WasmI64 = "@wasm.or_int64"
|
|
60
|
+
export primitive xor: (WasmI64, WasmI64) -> WasmI64 = "@wasm.xor_int64"
|
|
61
|
+
export primitive shl: (WasmI64, WasmI64) -> WasmI64 = "@wasm.shl_int64"
|
|
62
|
+
export primitive shrU: (WasmI64, WasmI64) -> WasmI64 = "@wasm.shr_u_int64"
|
|
63
|
+
export primitive shrS: (WasmI64, WasmI64) -> WasmI64 = "@wasm.shr_s_int64"
|
|
64
|
+
export primitive rotl: (WasmI64, WasmI64) -> WasmI64 = "@wasm.rot_l_int64"
|
|
65
|
+
export primitive rotr: (WasmI64, WasmI64) -> WasmI64 = "@wasm.rot_r_int64"
|
|
66
|
+
export primitive eq: (WasmI64, WasmI64) -> Bool = "@wasm.eq_int64"
|
|
67
|
+
export primitive ne: (WasmI64, WasmI64) -> Bool = "@wasm.ne_int64"
|
|
68
|
+
export primitive ltS: (WasmI64, WasmI64) -> Bool = "@wasm.lt_s_int64"
|
|
69
|
+
export primitive ltU: (WasmI64, WasmI64) -> Bool = "@wasm.lt_u_int64"
|
|
70
|
+
export primitive leS: (WasmI64, WasmI64) -> Bool = "@wasm.le_s_int64"
|
|
71
|
+
export primitive leU: (WasmI64, WasmI64) -> Bool = "@wasm.le_u_int64"
|
|
72
|
+
export primitive gtS: (WasmI64, WasmI64) -> Bool = "@wasm.gt_s_int64"
|
|
73
|
+
export primitive gtU: (WasmI64, WasmI64) -> Bool = "@wasm.gt_u_int64"
|
|
74
|
+
export primitive geS: (WasmI64, WasmI64) -> Bool = "@wasm.ge_s_int64"
|
|
75
|
+
export primitive geU: (WasmI64, WasmI64) -> Bool = "@wasm.ge_u_int64"
|
|
48
76
|
|
|
49
77
|
// WebAssembly Conversion instructions
|
|
50
|
-
export primitive extendI32S
|
|
51
|
-
export primitive extendI32U
|
|
52
|
-
export primitive truncF32S
|
|
53
|
-
export primitive truncF32U
|
|
54
|
-
export primitive truncF64S
|
|
55
|
-
export primitive truncF64U
|
|
56
|
-
export primitive reinterpretF64
|
|
57
|
-
export primitive extendS8
|
|
58
|
-
export primitive extendS16
|
|
59
|
-
export primitive extendS32
|
|
78
|
+
export primitive extendI32S: WasmI32 -> WasmI64 = "@wasm.extend_s_int32"
|
|
79
|
+
export primitive extendI32U: WasmI32 -> WasmI64 = "@wasm.extend_u_int32"
|
|
80
|
+
export primitive truncF32S: WasmF32 -> WasmI64 = "@wasm.trunc_s_float32_to_int64"
|
|
81
|
+
export primitive truncF32U: WasmF32 -> WasmI64 = "@wasm.trunc_u_float32_to_int64"
|
|
82
|
+
export primitive truncF64S: WasmF64 -> WasmI64 = "@wasm.trunc_s_float64_to_int64"
|
|
83
|
+
export primitive truncF64U: WasmF64 -> WasmI64 = "@wasm.trunc_u_float64_to_int64"
|
|
84
|
+
export primitive reinterpretF64: WasmF64 -> WasmI64 = "@wasm.reinterpret_float64"
|
|
85
|
+
export primitive extendS8: WasmI64 -> WasmI64 = "@wasm.extend_s8_int64"
|
|
86
|
+
export primitive extendS16: WasmI64 -> WasmI64 = "@wasm.extend_s16_int64"
|
|
87
|
+
export primitive extendS32: WasmI64 -> WasmI64 = "@wasm.extend_s32_int64"
|