@grain/stdlib 0.4.4 → 0.5.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 (97) hide show
  1. package/CHANGELOG.md +87 -0
  2. package/LICENSE +1 -1
  3. package/array.gr +92 -73
  4. package/array.md +18 -18
  5. package/bigint.gr +497 -0
  6. package/bigint.md +811 -0
  7. package/buffer.gr +56 -217
  8. package/buffer.md +24 -17
  9. package/bytes.gr +103 -205
  10. package/bytes.md +19 -0
  11. package/char.gr +152 -166
  12. package/char.md +200 -0
  13. package/exception.md +6 -0
  14. package/float32.gr +159 -82
  15. package/float32.md +315 -0
  16. package/float64.gr +163 -82
  17. package/float64.md +315 -0
  18. package/hash.gr +53 -49
  19. package/int32.gr +479 -230
  20. package/int32.md +937 -0
  21. package/int64.gr +479 -230
  22. package/int64.md +937 -0
  23. package/list.gr +530 -116
  24. package/list.md +1141 -0
  25. package/map.gr +302 -121
  26. package/map.md +525 -0
  27. package/number.gr +51 -57
  28. package/number.md +37 -3
  29. package/option.gr +25 -25
  30. package/option.md +1 -1
  31. package/package.json +3 -3
  32. package/pervasives.gr +504 -52
  33. package/pervasives.md +1116 -0
  34. package/queue.gr +8 -1
  35. package/queue.md +10 -0
  36. package/random.gr +196 -0
  37. package/random.md +179 -0
  38. package/range.gr +26 -26
  39. package/regex.gr +1833 -842
  40. package/regex.md +11 -11
  41. package/result.md +1 -1
  42. package/runtime/bigint.gr +2045 -0
  43. package/runtime/bigint.md +326 -0
  44. package/runtime/dataStructures.gr +99 -279
  45. package/runtime/dataStructures.md +391 -0
  46. package/runtime/debug.gr +0 -1
  47. package/runtime/debug.md +6 -0
  48. package/runtime/equal.gr +40 -37
  49. package/runtime/equal.md +6 -0
  50. package/runtime/exception.gr +28 -15
  51. package/runtime/exception.md +30 -0
  52. package/runtime/gc.gr +50 -20
  53. package/runtime/gc.md +36 -0
  54. package/runtime/malloc.gr +32 -22
  55. package/runtime/malloc.md +55 -0
  56. package/runtime/numberUtils.gr +297 -142
  57. package/runtime/numberUtils.md +54 -0
  58. package/runtime/numbers.gr +1204 -453
  59. package/runtime/numbers.md +300 -0
  60. package/runtime/string.gr +193 -228
  61. package/runtime/string.md +24 -0
  62. package/runtime/stringUtils.gr +62 -38
  63. package/runtime/stringUtils.md +6 -0
  64. package/runtime/unsafe/constants.gr +17 -0
  65. package/runtime/unsafe/constants.md +72 -0
  66. package/runtime/unsafe/conv.gr +10 -10
  67. package/runtime/unsafe/conv.md +71 -0
  68. package/runtime/unsafe/errors.md +204 -0
  69. package/runtime/unsafe/memory.gr +14 -3
  70. package/runtime/unsafe/memory.md +54 -0
  71. package/runtime/unsafe/printWasm.gr +4 -4
  72. package/runtime/unsafe/printWasm.md +24 -0
  73. package/runtime/unsafe/tags.gr +11 -10
  74. package/runtime/unsafe/tags.md +120 -0
  75. package/runtime/unsafe/wasmf32.gr +9 -2
  76. package/runtime/unsafe/wasmf32.md +168 -0
  77. package/runtime/unsafe/wasmf64.gr +9 -2
  78. package/runtime/unsafe/wasmf64.md +168 -0
  79. package/runtime/unsafe/wasmi32.gr +65 -47
  80. package/runtime/unsafe/wasmi32.md +282 -0
  81. package/runtime/unsafe/wasmi64.gr +78 -50
  82. package/runtime/unsafe/wasmi64.md +300 -0
  83. package/runtime/utils/printing.gr +62 -0
  84. package/runtime/utils/printing.md +18 -0
  85. package/runtime/wasi.gr +200 -46
  86. package/runtime/wasi.md +839 -0
  87. package/set.gr +125 -121
  88. package/set.md +24 -21
  89. package/stack.gr +29 -29
  90. package/stack.md +4 -6
  91. package/string.gr +434 -415
  92. package/string.md +3 -3
  93. package/sys/file.gr +477 -482
  94. package/sys/process.gr +33 -47
  95. package/sys/random.gr +48 -20
  96. package/sys/random.md +38 -0
  97. package/sys/time.gr +12 -28
@@ -0,0 +1,24 @@
1
+ ### String.**StringList**
2
+
3
+ ```grain
4
+ type StringList
5
+ ```
6
+
7
+ ### String.**concat**
8
+
9
+ ```grain
10
+ concat : (String, String) -> String
11
+ ```
12
+
13
+ ### String.**toString**
14
+
15
+ ```grain
16
+ toString : a -> String
17
+ ```
18
+
19
+ ### String.**print**
20
+
21
+ ```grain
22
+ print : a -> Void
23
+ ```
24
+
@@ -14,9 +14,10 @@ import WasmI32, {
14
14
  import WasmI64 from "runtime/unsafe/wasmi64"
15
15
  import Memory from "runtime/unsafe/memory"
16
16
  import Tags from "runtime/unsafe/tags"
17
+ import BI from "runtime/bigint"
17
18
  import { reducedInteger } from "runtime/numbers"
18
19
 
19
- @disableGC
20
+ @unsafe
20
21
  export let rec parseInt = (string: String, radix: Number) => {
21
22
  let _CHAR_0 = 0x30n
22
23
  let _CHAR_B = 0x42n
@@ -45,11 +46,13 @@ export let rec parseInt = (string: String, radix: Number) => {
45
46
  let strEnd = offset + strLen
46
47
 
47
48
  let radix = WasmI32.fromGrain(radix)
48
- let result = if (WasmI32.eqz(radix & Tags._GRAIN_NUMBER_TAG_MASK) || radix < WasmI32.fromGrain(2) || radix > WasmI32.fromGrain(36)) {
49
- Memory.incRef(WasmI32.fromGrain(Err))
49
+ if (
50
+ WasmI32.eqz(radix & Tags._GRAIN_NUMBER_TAG_MASK) ||
51
+ radix < WasmI32.fromGrain(2) ||
52
+ radix > WasmI32.fromGrain(36)
53
+ ) {
50
54
  Err("Radix must be an integer between 2 and 36")
51
55
  } else if (WasmI32.eqz(strLen)) {
52
- Memory.incRef(WasmI32.fromGrain(Err))
53
56
  Err("Invalid input")
54
57
  } else {
55
58
  let mut char = WasmI32.load8U(offset, 0n)
@@ -86,10 +89,13 @@ export let rec parseInt = (string: String, radix: Number) => {
86
89
  }
87
90
  }
88
91
 
92
+ // We try to avoid allocating a BigInt if it's not needed
89
93
  let mut value = 0N
94
+ let mut radixBigInt = 0n
95
+ let mut valueBigInt = 0n
96
+ let mut isBigInt = 0n
90
97
 
91
- // we use 0 to represent no error, 1 to represent an invalid
92
- // input, and 2 to represent an overflow
98
+ // we use 0 to represent no error and 1 to represent an invalid input
93
99
  let mut error = 1n
94
100
 
95
101
  for (let mut i = offset; i < strEnd; i += 1n) {
@@ -126,47 +132,65 @@ export let rec parseInt = (string: String, radix: Number) => {
126
132
 
127
133
  let digit = WasmI64.extendI32U(digit)
128
134
 
129
- value = WasmI64.mul(value, radix)
130
-
131
- // Check for overflow
132
- // 64-bit int min + 1
133
- if (WasmI64.ltS(value, WasmI64.add(limit, digit))) {
134
- error = 2n
135
- // overflow
136
- break
135
+ if (WasmI32.eqz(isBigInt)) {
136
+ let prevValue = value
137
+ value = WasmI64.mul(value, radix)
138
+ // Check for overflow
139
+ // 64-bit int min + 1
140
+ if (WasmI64.ltS(value, WasmI64.add(limit, digit))) {
141
+ // we overflowed. allocate BigInt and use instead
142
+ isBigInt = 1n
143
+ valueBigInt = BI.makeWrappedUint64(WasmI64.mul(prevValue, -1N))
144
+ radixBigInt = BI.makeWrappedUint64(radix)
145
+ let newvalue = BI.mul(valueBigInt, radixBigInt)
146
+ Memory.decRef(valueBigInt)
147
+ valueBigInt = newvalue
148
+ let newvalue = BI.addInt(valueBigInt, digit)
149
+ Memory.decRef(valueBigInt)
150
+ valueBigInt = newvalue
151
+ } else {
152
+ // To quote the OpenJDK,
153
+ // "Accumulating negatively avoids surprises near MAX_VALUE"
154
+ // The minimum value of a 64-bit integer (-9223372036854775808) can't be
155
+ // represented as a positive number because it would be larger than the
156
+ // maximum 64-bit integer (9223372036854775807), so we'd be unable to
157
+ // parse negatives as positives and multiply by the sign at the end.
158
+ // Instead, we represent all positive numbers as negative numbers since
159
+ // we have one unit more headroom.
160
+ value = WasmI64.sub(value, digit)
161
+ }
162
+ } else {
163
+ let newvalue = BI.mul(valueBigInt, radixBigInt)
164
+ Memory.decRef(valueBigInt)
165
+ valueBigInt = newvalue
166
+ let newvalue = BI.addInt(valueBigInt, digit)
167
+ Memory.decRef(valueBigInt)
168
+ valueBigInt = newvalue
137
169
  }
138
-
139
- // To quote the OpenJDK,
140
- // "Accumulating negatively avoids surprises near MAX_VALUE"
141
- // The minimum value of a 64-bit integer (-9223372036854775808) can't be
142
- // represented as a positive number because it would be larger than the
143
- // maximum 64-bit integer (9223372036854775807), so we'd be unable to
144
- // parse negatives as positives and multiply by the sign at the end.
145
- // Instead, we represent all positive numbers as negative numbers since
146
- // we have one unit more headroom.
147
- value = WasmI64.sub(value, digit)
148
170
  }
149
171
 
150
172
  match (error) {
151
173
  1n => {
152
- Memory.incRef(WasmI32.fromGrain(Err))
153
174
  Err("Invalid digit in input")
154
175
  },
155
- 2n => {
156
- Memory.incRef(WasmI32.fromGrain(Err))
157
- Err("Input out of range of representable integers")
158
- },
159
176
  _ => {
160
- let value = if (negative) value else WasmI64.mul(value, -1N)
161
- let number = WasmI32.toGrain(reducedInteger(value)): (Number)
162
- Memory.incRef(WasmI32.fromGrain(Ok))
163
- Ok(number)
177
+ if (WasmI32.eqz(isBigInt)) {
178
+ let value = if (negative) value else WasmI64.mul(value, -1N)
179
+ let number = WasmI32.toGrain(
180
+ Memory.incRef(reducedInteger(value))
181
+ ): Number
182
+ Ok(number)
183
+ } else {
184
+ // BigInt number is accumulated in positive form
185
+ if (negative) {
186
+ let newvalue = BI.negate(valueBigInt)
187
+ Memory.decRef(valueBigInt)
188
+ Ok(WasmI32.toGrain(newvalue))
189
+ } else {
190
+ Ok(WasmI32.toGrain(valueBigInt))
191
+ }
192
+ }
164
193
  },
165
194
  }
166
195
  }
167
-
168
- Memory.decRef(WasmI32.fromGrain(parseInt))
169
- Memory.decRef(radix)
170
-
171
- result
172
196
  }
@@ -0,0 +1,6 @@
1
+ ### StringUtils.**parseInt**
2
+
3
+ ```grain
4
+ parseInt : (String, Number) -> Result<Number, String>
5
+ ```
6
+
@@ -0,0 +1,17 @@
1
+ /* grainc-flags --compilation-mode=runtime */
2
+
3
+ // Signed/Unsigned Min/Max Constants
4
+ export let _SMIN_I32 = 0xFFFFFFFFn
5
+ export let _SMAX_I32 = 0x7FFFFFFFn
6
+ export let _UMIN_I32 = 0x0n
7
+ export let _UMAX_I32 = 0xFFFFFFFFn
8
+
9
+ export let _SMIN_I64 = 0xFFFFFFFFFFFFFFFFN
10
+ export let _SMAX_I64 = 0x7FFFFFFFFFFFFFFFN
11
+ export let _UMIN_I64 = 0x0N
12
+ export let _UMAX_I64 = 0xFFFFFFFFFFFFFFFFN
13
+
14
+ export let _SMIN32_I64 = -0x7FFFFFFFN
15
+ export let _SMAX32_I64 = 0x7FFFFFFFN
16
+ export let _UMIN32_I64 = 0x0N
17
+ export let _UMAX32_I64 = 0xFFFFFFFFN
@@ -0,0 +1,72 @@
1
+ ### Constants.**_SMIN_I32**
2
+
3
+ ```grain
4
+ _SMIN_I32 : WasmI32
5
+ ```
6
+
7
+ ### Constants.**_SMAX_I32**
8
+
9
+ ```grain
10
+ _SMAX_I32 : WasmI32
11
+ ```
12
+
13
+ ### Constants.**_UMIN_I32**
14
+
15
+ ```grain
16
+ _UMIN_I32 : WasmI32
17
+ ```
18
+
19
+ ### Constants.**_UMAX_I32**
20
+
21
+ ```grain
22
+ _UMAX_I32 : WasmI32
23
+ ```
24
+
25
+ ### Constants.**_SMIN_I64**
26
+
27
+ ```grain
28
+ _SMIN_I64 : WasmI64
29
+ ```
30
+
31
+ ### Constants.**_SMAX_I64**
32
+
33
+ ```grain
34
+ _SMAX_I64 : WasmI64
35
+ ```
36
+
37
+ ### Constants.**_UMIN_I64**
38
+
39
+ ```grain
40
+ _UMIN_I64 : WasmI64
41
+ ```
42
+
43
+ ### Constants.**_UMAX_I64**
44
+
45
+ ```grain
46
+ _UMAX_I64 : WasmI64
47
+ ```
48
+
49
+ ### Constants.**_SMIN32_I64**
50
+
51
+ ```grain
52
+ _SMIN32_I64 : WasmI64
53
+ ```
54
+
55
+ ### Constants.**_SMAX32_I64**
56
+
57
+ ```grain
58
+ _SMAX32_I64 : WasmI64
59
+ ```
60
+
61
+ ### Constants.**_UMIN32_I64**
62
+
63
+ ```grain
64
+ _UMIN32_I64 : WasmI64
65
+ ```
66
+
67
+ ### Constants.**_UMAX32_I64**
68
+
69
+ ```grain
70
+ _UMAX32_I64 : WasmI64
71
+ ```
72
+
@@ -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 = (n) => {
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) : Int32
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 = (n) => {
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) : Int64
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 = (n) => {
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) : Float32
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 = (n) => {
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) : Float64
63
+ WasmI32.toGrain(ptr): Float64
64
64
  }
65
65
 
66
66
  @disableGC
@@ -101,13 +101,13 @@ export let wasmI32ToNumber = (n: WasmI32) => {
101
101
  // Just test if the untagged number is the same. If it didn't overflow, then
102
102
  // we're good. We just need to cast the raw value into a Number at the type
103
103
  // system level.
104
- WasmI32.toGrain(simple): (Number)
104
+ WasmI32.toGrain(simple): Number
105
105
  } else {
106
106
  // If it did overflow, then the value differs and we need to discard it and
107
107
  // allocate the number on the heap. A boxed 32 bit number actually is the
108
108
  // same thing as an Int32. It only needs to be cast into Number.
109
109
  let asInt32 = toInt32(n)
110
- WasmI32.toGrain(WasmI32.fromGrain(asInt32)): (Number)
110
+ WasmI32.toGrain(WasmI32.fromGrain(asInt32)): Number
111
111
  }
112
112
  result
113
113
  }
@@ -0,0 +1,71 @@
1
+ ### Conv.**toInt32**
2
+
3
+ ```grain
4
+ toInt32 : WasmI32 -> Int32
5
+ ```
6
+
7
+ ### Conv.**fromInt32**
8
+
9
+ ```grain
10
+ fromInt32 : Int32 -> WasmI32
11
+ ```
12
+
13
+ ### Conv.**toInt64**
14
+
15
+ ```grain
16
+ toInt64 : WasmI64 -> Int64
17
+ ```
18
+
19
+ ### Conv.**fromInt64**
20
+
21
+ ```grain
22
+ fromInt64 : Int64 -> WasmI64
23
+ ```
24
+
25
+ ### Conv.**toFloat32**
26
+
27
+ ```grain
28
+ toFloat32 : WasmF32 -> Float32
29
+ ```
30
+
31
+ ### Conv.**fromFloat32**
32
+
33
+ ```grain
34
+ fromFloat32 : Float32 -> WasmF32
35
+ ```
36
+
37
+ ### Conv.**toFloat64**
38
+
39
+ ```grain
40
+ toFloat64 : WasmF64 -> Float64
41
+ ```
42
+
43
+ ### Conv.**fromFloat64**
44
+
45
+ ```grain
46
+ fromFloat64 : Float64 -> WasmF64
47
+ ```
48
+
49
+ ### Conv.**wasmI32ToNumber**
50
+
51
+ ```grain
52
+ wasmI32ToNumber : WasmI32 -> Number
53
+ ```
54
+
55
+ Converts a WasmI32 value to Number.
56
+
57
+ This function is meant to be called from a `@disableGC` context without
58
+ need to call incRef on the function.
59
+
60
+ Parameters:
61
+
62
+ |param|type|description|
63
+ |-----|----|-----------|
64
+ |`n`|`WasmI32`|The WasmI32 to convert|
65
+
66
+ Returns:
67
+
68
+ |type|description|
69
+ |----|-----------|
70
+ |`Number`|The value converted to either a simple or a 32 bit heap allocated number.|
71
+
@@ -0,0 +1,204 @@
1
+ ### Errors.**_GRAIN_ERR_NOT_NUMBER_COMP**
2
+
3
+ ```grain
4
+ _GRAIN_ERR_NOT_NUMBER_COMP : WasmI32
5
+ ```
6
+
7
+ ### Errors.**_GRAIN_ERR_NOT_NUMBER_ARITH**
8
+
9
+ ```grain
10
+ _GRAIN_ERR_NOT_NUMBER_ARITH : WasmI32
11
+ ```
12
+
13
+ ### Errors.**_GRAIN_ERR_NOT_BOOLEAN_LOGIC**
14
+
15
+ ```grain
16
+ _GRAIN_ERR_NOT_BOOLEAN_LOGIC : WasmI32
17
+ ```
18
+
19
+ ### Errors.**_GRAIN_ERR_NOT_BOOLEAN_IF**
20
+
21
+ ```grain
22
+ _GRAIN_ERR_NOT_BOOLEAN_IF : WasmI32
23
+ ```
24
+
25
+ ### Errors.**_GRAIN_ERR_OVERFLOW**
26
+
27
+ ```grain
28
+ _GRAIN_ERR_OVERFLOW : WasmI32
29
+ ```
30
+
31
+ ### Errors.**_GRAIN_ERR_GET_NOT_TUP**
32
+
33
+ ```grain
34
+ _GRAIN_ERR_GET_NOT_TUP : WasmI32
35
+ ```
36
+
37
+ ### Errors.**_GRAIN_ERR_GET_ITEM_IDX_NOT_NUMBER**
38
+
39
+ ```grain
40
+ _GRAIN_ERR_GET_ITEM_IDX_NOT_NUMBER : WasmI32
41
+ ```
42
+
43
+ ### Errors.**_GRAIN_ERR_GET_ITEM_IDX_TOO_SMALL**
44
+
45
+ ```grain
46
+ _GRAIN_ERR_GET_ITEM_IDX_TOO_SMALL : WasmI32
47
+ ```
48
+
49
+ ### Errors.**_GRAIN_ERR_GET_ITEM_IDX_TOO_LARGE**
50
+
51
+ ```grain
52
+ _GRAIN_ERR_GET_ITEM_IDX_TOO_LARGE : WasmI32
53
+ ```
54
+
55
+ ### Errors.**_GRAIN_ERR_CALLED_NON_FUNCTION**
56
+
57
+ ```grain
58
+ _GRAIN_ERR_CALLED_NON_FUNCTION : WasmI32
59
+ ```
60
+
61
+ ### Errors.**_GRAIN_ERR_ARITY_MISMATCH**
62
+
63
+ ```grain
64
+ _GRAIN_ERR_ARITY_MISMATCH : WasmI32
65
+ ```
66
+
67
+ ### Errors.**_GRAIN_ERR_OUT_OF_MEMORY**
68
+
69
+ ```grain
70
+ _GRAIN_ERR_OUT_OF_MEMORY : WasmI32
71
+ ```
72
+
73
+ ### Errors.**_GRAIN_ERR_SET_NOT_TUP**
74
+
75
+ ```grain
76
+ _GRAIN_ERR_SET_NOT_TUP : WasmI32
77
+ ```
78
+
79
+ ### Errors.**_GRAIN_ERR_SET_ITEM_IDX_NOT_NUMBER**
80
+
81
+ ```grain
82
+ _GRAIN_ERR_SET_ITEM_IDX_NOT_NUMBER : WasmI32
83
+ ```
84
+
85
+ ### Errors.**_GRAIN_ERR_SET_ITEM_IDX_TOO_SMALL**
86
+
87
+ ```grain
88
+ _GRAIN_ERR_SET_ITEM_IDX_TOO_SMALL : WasmI32
89
+ ```
90
+
91
+ ### Errors.**_GRAIN_ERR_SET_ITEM_IDX_TOO_LARGE**
92
+
93
+ ```grain
94
+ _GRAIN_ERR_SET_ITEM_IDX_TOO_LARGE : WasmI32
95
+ ```
96
+
97
+ ### Errors.**_GRAIN_ERR_DIVISION_BY_ZERO**
98
+
99
+ ```grain
100
+ _GRAIN_ERR_DIVISION_BY_ZERO : WasmI32
101
+ ```
102
+
103
+ ### Errors.**_GRAIN_ERR_MODULO_BY_ZERO**
104
+
105
+ ```grain
106
+ _GRAIN_ERR_MODULO_BY_ZERO : WasmI32
107
+ ```
108
+
109
+ ### Errors.**_GRAIN_ERR_ARRAY_INDEX_OUT_OF_BOUNDS**
110
+
111
+ ```grain
112
+ _GRAIN_ERR_ARRAY_INDEX_OUT_OF_BOUNDS : WasmI32
113
+ ```
114
+
115
+ ### Errors.**_GRAIN_ERR_INVALID_ARGUMENT**
116
+
117
+ ```grain
118
+ _GRAIN_ERR_INVALID_ARGUMENT : WasmI32
119
+ ```
120
+
121
+ ### Errors.**_GRAIN_ERR_ASSERTION_ERROR**
122
+
123
+ ```grain
124
+ _GRAIN_ERR_ASSERTION_ERROR : WasmI32
125
+ ```
126
+
127
+ ### Errors.**_GRAIN_ERR_FAILURE**
128
+
129
+ ```grain
130
+ _GRAIN_ERR_FAILURE : WasmI32
131
+ ```
132
+
133
+ ### Errors.**_GRAIN_ERR_SYSTEM**
134
+
135
+ ```grain
136
+ _GRAIN_ERR_SYSTEM : WasmI32
137
+ ```
138
+
139
+ ### Errors.**_GRAIN_ERR_NOT_INTLIKE**
140
+
141
+ ```grain
142
+ _GRAIN_ERR_NOT_INTLIKE : WasmI32
143
+ ```
144
+
145
+ ### Errors.**_GRAIN_ERR_NOT_RATIONAL**
146
+
147
+ ```grain
148
+ _GRAIN_ERR_NOT_RATIONAL : WasmI32
149
+ ```
150
+
151
+ ### Errors.**_GRAIN_ERR_MALFORMED_UTF8**
152
+
153
+ ```grain
154
+ _GRAIN_ERR_MALFORMED_UTF8 : WasmI32
155
+ ```
156
+
157
+ ### Errors.**_GRAIN_ERR_NOT_ADT_VAL_GENERIC**
158
+
159
+ ```grain
160
+ _GRAIN_ERR_NOT_ADT_VAL_GENERIC : WasmI32
161
+ ```
162
+
163
+ ### Errors.**_GRAIN_ERR_NOT_STRING_GENERIC**
164
+
165
+ ```grain
166
+ _GRAIN_ERR_NOT_STRING_GENERIC : WasmI32
167
+ ```
168
+
169
+ ### Errors.**_GRAIN_ERR_NOT_BOOLEAN_GENERIC**
170
+
171
+ ```grain
172
+ _GRAIN_ERR_NOT_BOOLEAN_GENERIC : WasmI32
173
+ ```
174
+
175
+ ### Errors.**_GRAIN_ERR_NOT_TUPLE_GENERIC**
176
+
177
+ ```grain
178
+ _GRAIN_ERR_NOT_TUPLE_GENERIC : WasmI32
179
+ ```
180
+
181
+ ### Errors.**_GRAIN_ERR_NOT_LAMBDA_GENERIC**
182
+
183
+ ```grain
184
+ _GRAIN_ERR_NOT_LAMBDA_GENERIC : WasmI32
185
+ ```
186
+
187
+ ### Errors.**_GRAIN_ERR_BAD_INPUT**
188
+
189
+ ```grain
190
+ _GRAIN_ERR_BAD_INPUT : WasmI32
191
+ ```
192
+
193
+ ### Errors.**_GRAIN_ERR_NOT_NONNEG**
194
+
195
+ ```grain
196
+ _GRAIN_ERR_NOT_NONNEG : WasmI32
197
+ ```
198
+
199
+ ### Errors.**_GRAIN_ERR_NOT_NUMBER_GENERIC**
200
+
201
+ ```grain
202
+ _GRAIN_ERR_NOT_NUMBER_GENERIC : WasmI32
203
+ ```
204
+
@@ -1,13 +1,20 @@
1
1
  /* grainc-flags --compilation-mode=runtime */
2
2
 
3
- import { malloc, free, incRef, decRef, utoa32Buffered, decimalCount32 } from "runtime/gc"
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: (WasmI32, WasmI32, WasmI32) -> WasmI32 = "@wasm.memory_compare"
58
+ export primitive compare: (
59
+ WasmI32,
60
+ WasmI32,
61
+ WasmI32,
62
+ ) -> WasmI32 = "@wasm.memory_compare"
@@ -0,0 +1,54 @@
1
+ ### Memory.**malloc**
2
+
3
+ ```grain
4
+ malloc : WasmI32 -> WasmI32
5
+ ```
6
+
7
+ ### Memory.**free**
8
+
9
+ ```grain
10
+ free : WasmI32 -> Void
11
+ ```
12
+
13
+ ### Memory.**incRef**
14
+
15
+ ```grain
16
+ incRef : WasmI32 -> WasmI32
17
+ ```
18
+
19
+ ### Memory.**decRef**
20
+
21
+ ```grain
22
+ decRef : WasmI32 -> WasmI32
23
+ ```
24
+
25
+ ### Memory.**utoa32Buffered**
26
+
27
+ ```grain
28
+ utoa32Buffered : Box<(WasmI32, WasmI32, WasmI32) -> Void>
29
+ ```
30
+
31
+ ### Memory.**decimalCount32**
32
+
33
+ ```grain
34
+ decimalCount32 : Box<WasmI32 -> WasmI32>
35
+ ```
36
+
37
+ ### Memory.**copy**
38
+
39
+ ```grain
40
+ copy : (WasmI32, WasmI32, WasmI32) -> Void
41
+ ```
42
+
43
+ ### Memory.**fill**
44
+
45
+ ```grain
46
+ fill : (WasmI32, WasmI32, WasmI32) -> Void
47
+ ```
48
+
49
+ ### Memory.**compare**
50
+
51
+ ```grain
52
+ compare : (WasmI32, WasmI32, WasmI32) -> WasmI32
53
+ ```
54
+