toilscript 0.1.2 → 0.1.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/README.md +1 -1
- package/dist/cli.js +3737 -5
- package/dist/cli.js.map +2 -2
- package/dist/importmap.json +2 -2
- package/dist/web.js +3 -3
- package/package.json +1 -1
- package/std/assembly/bignum/LICENSE +201 -0
- package/std/assembly/bignum/NOTICE +13 -0
- package/std/assembly/bignum/fixed/fp128.ts +58 -0
- package/std/assembly/bignum/fixed/fp256.ts +9 -0
- package/std/assembly/bignum/fixed/index.ts +38 -0
- package/std/assembly/bignum/fixed/safe/fp128.ts +3 -0
- package/std/assembly/bignum/fixed/safe/fp256.ts +3 -0
- package/std/assembly/bignum/fixed/types.ts +103 -0
- package/std/assembly/bignum/globals.ts +546 -0
- package/std/assembly/bignum/index.ts +1 -0
- package/std/assembly/bignum/integer/i128.ts +413 -0
- package/std/assembly/bignum/integer/i256.ts +50 -0
- package/std/assembly/bignum/integer/index.ts +3 -0
- package/std/assembly/bignum/integer/u128.ts +963 -0
- package/std/assembly/bignum/integer/u256.ts +1007 -0
- package/std/assembly/bignum/utils.ts +260 -0
- package/std/assembly/bignum.ts +18 -0
- package/std/assembly/index.d.ts +257 -0
- package/std/assembly/toilscript.ts +1 -1
- package/std/assembly.json +1 -0
- package/std/ts-plugin.cjs +44 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { CharCode } from "util/string";
|
|
2
|
+
import { u128 } from "./integer/u128";
|
|
3
|
+
import { u256 } from "./integer/u256";
|
|
4
|
+
|
|
5
|
+
// @ts-ignore: decorator
|
|
6
|
+
@lazy const MaxBaseForExponent128 = memory.data<u64>([
|
|
7
|
+
u64.MAX_VALUE, // 0
|
|
8
|
+
u64.MAX_VALUE, // 1
|
|
9
|
+
u64.MAX_VALUE, // 2
|
|
10
|
+
0x000006597FA94F5B, // 3
|
|
11
|
+
0x00000000FFFFFFFF, // 4
|
|
12
|
+
0x0000000003080C00, // 5
|
|
13
|
+
0x0000000000285145, // 6
|
|
14
|
+
0x000000000004E045, // 7
|
|
15
|
+
0x000000000000FFFF, // 8
|
|
16
|
+
0x0000000000004AA8, // 9
|
|
17
|
+
0x0000000000001BDB, // 10
|
|
18
|
+
0x0000000000000C6F, // 11
|
|
19
|
+
0x0000000000000659, // 12
|
|
20
|
+
0x0000000000000398, // 13
|
|
21
|
+
0x0000000000000235, // 14
|
|
22
|
+
0x0000000000000172, // 15
|
|
23
|
+
0x00000000000000FF, // 16
|
|
24
|
+
0x00000000000000B8, // 17
|
|
25
|
+
0x000000000000008A, // 18
|
|
26
|
+
0x000000000000006A, // 19
|
|
27
|
+
0x0000000000000054, // 20
|
|
28
|
+
0x0000000000000044, // 21
|
|
29
|
+
0x0000000000000038, // 22
|
|
30
|
+
0x000000000000002F, // 23
|
|
31
|
+
0x0000000000000028, // 24
|
|
32
|
+
0x0000000000000022, // 25
|
|
33
|
+
0x000000000000001E, // 26
|
|
34
|
+
0x000000000000001A, // 27
|
|
35
|
+
0x0000000000000017, // 28
|
|
36
|
+
0x0000000000000015, // 29
|
|
37
|
+
0x0000000000000013, // 30
|
|
38
|
+
0x0000000000000011, // 31
|
|
39
|
+
0x000000000000000F, // 32
|
|
40
|
+
0x000000000000000E, // 33
|
|
41
|
+
0x000000000000000D, // 34
|
|
42
|
+
0x000000000000000C, // 35
|
|
43
|
+
0x000000000000000B, // 36
|
|
44
|
+
0x000000000000000B, // 37
|
|
45
|
+
0x000000000000000A, // 38
|
|
46
|
+
]);
|
|
47
|
+
|
|
48
|
+
// Use LUT wrapped by function for lazy compilation
|
|
49
|
+
// @ts-ignore: decorator
|
|
50
|
+
@lazy const RadixCharsTable = memory.data<u8>([
|
|
51
|
+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 36, 36, 36, 36, 36, 36,
|
|
52
|
+
36, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
|
|
53
|
+
25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 36, 36, 36, 36,
|
|
54
|
+
36, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
|
|
55
|
+
25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35
|
|
56
|
+
]);
|
|
57
|
+
|
|
58
|
+
// @ts-ignore: decorator
|
|
59
|
+
@inline export function isPowerOverflow128(base: u128, exponent: i32): bool {
|
|
60
|
+
// never overflow
|
|
61
|
+
if (exponent <= 1 || base <= u128.One) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
// always overflow
|
|
65
|
+
if (base.hi != 0 || exponent >= 128) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
var low = base.lo;
|
|
69
|
+
if (low <= 10) {
|
|
70
|
+
switch (<i32>low) {
|
|
71
|
+
case 2:
|
|
72
|
+
return exponent > 127;
|
|
73
|
+
case 3:
|
|
74
|
+
return exponent > 80;
|
|
75
|
+
case 4:
|
|
76
|
+
return exponent > 63;
|
|
77
|
+
case 5:
|
|
78
|
+
return exponent > 55;
|
|
79
|
+
case 6:
|
|
80
|
+
return exponent > 49;
|
|
81
|
+
case 7:
|
|
82
|
+
return exponent > 45;
|
|
83
|
+
case 8:
|
|
84
|
+
return exponent > 42;
|
|
85
|
+
case 9:
|
|
86
|
+
return exponent > 40;
|
|
87
|
+
case 10:
|
|
88
|
+
return exponent > 38;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (exponent >= 38) return true;
|
|
92
|
+
return low > load<u64>(MaxBaseForExponent128 + (exponent << 3));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// helper function for utoa
|
|
96
|
+
function processU64(digits: Uint8Array, value: u64): void {
|
|
97
|
+
var length = digits.length - 1;
|
|
98
|
+
for (let i = 63; i != -1; --i) {
|
|
99
|
+
for (let j = 0; j <= length; ++j) {
|
|
100
|
+
unchecked(digits[j] += (u8(digits[j] >= 5) * 3));
|
|
101
|
+
}
|
|
102
|
+
for (let j = length; j != -1; --j) {
|
|
103
|
+
let d = unchecked(digits[j]) << 1;
|
|
104
|
+
if (j < length) unchecked(digits[j + 1] |= u8(d > 15));
|
|
105
|
+
unchecked(digits[j] = d & 15);
|
|
106
|
+
}
|
|
107
|
+
unchecked(digits[0] += u8((value & (1 << i)) != 0));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function u128toDecimalString(value: u128): string {
|
|
112
|
+
var length = 40;
|
|
113
|
+
var digits = new Uint8Array(length);
|
|
114
|
+
var result = "", start = false;
|
|
115
|
+
|
|
116
|
+
processU64(digits, value.hi);
|
|
117
|
+
processU64(digits, value.lo);
|
|
118
|
+
|
|
119
|
+
for (let i = length - 1; i != -1; --i) {
|
|
120
|
+
let d = unchecked(digits[i]);
|
|
121
|
+
if (!start && d != 0) start = true;
|
|
122
|
+
if (start) {
|
|
123
|
+
assert(<u32>d <= 9);
|
|
124
|
+
result += String.fromCharCode(0x30 + d);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return result;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function u256toDecimalString(value: u256): string {
|
|
131
|
+
var length = 78;
|
|
132
|
+
var digits = new Uint8Array(length);
|
|
133
|
+
var result = "", start = false;
|
|
134
|
+
|
|
135
|
+
processU64(digits, value.hi2);
|
|
136
|
+
processU64(digits, value.hi1);
|
|
137
|
+
processU64(digits, value.lo2);
|
|
138
|
+
processU64(digits, value.lo1);
|
|
139
|
+
|
|
140
|
+
for (let i = length - 1; i != -1; --i) {
|
|
141
|
+
let d = unchecked(digits[i]);
|
|
142
|
+
if (!start && d != 0) start = true;
|
|
143
|
+
if (start) {
|
|
144
|
+
assert(<u32>d <= 9);
|
|
145
|
+
result += String.fromCharCode(0x30 + d);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return result;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export function atou128(str: string, radix: i32 = 10): u128 {
|
|
152
|
+
if (radix < 2 || radix > 36) {
|
|
153
|
+
throw new Error("Invalid radix");
|
|
154
|
+
}
|
|
155
|
+
var len = str.length;
|
|
156
|
+
if (!len) return u128.Zero;
|
|
157
|
+
|
|
158
|
+
var first = str.charCodeAt(0);
|
|
159
|
+
if (len == 1 && first == CharCode._0) {
|
|
160
|
+
return u128.Zero;
|
|
161
|
+
}
|
|
162
|
+
var isNeg = first == CharCode.MINUS;
|
|
163
|
+
// @ts-ignore
|
|
164
|
+
var index = i32(isNeg | (first == CharCode.PLUS));
|
|
165
|
+
|
|
166
|
+
if (str.charCodeAt(index) == CharCode._0) {
|
|
167
|
+
let second = str.charCodeAt(++index);
|
|
168
|
+
if ((second | 32) == CharCode.x) {
|
|
169
|
+
radix = 16;
|
|
170
|
+
++index;
|
|
171
|
+
} else if ((second | 32) == CharCode.o) {
|
|
172
|
+
radix = 8;
|
|
173
|
+
++index;
|
|
174
|
+
} else if ((second | 32) == CharCode.b) {
|
|
175
|
+
radix = 2;
|
|
176
|
+
++index;
|
|
177
|
+
} else if (second == CharCode._0) {
|
|
178
|
+
// skip leading zeros
|
|
179
|
+
while (index < len && str.charCodeAt(index) == CharCode._0) ++index;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
var result = u128.Zero;
|
|
183
|
+
var table = RadixCharsTable;
|
|
184
|
+
|
|
185
|
+
if (index >= len) return result;
|
|
186
|
+
|
|
187
|
+
if (ASC_SHRINK_LEVEL >= 1) {
|
|
188
|
+
let radix128 = u128.fromU64(radix);
|
|
189
|
+
do {
|
|
190
|
+
let n: u32 = str.charCodeAt(index) - CharCode._0;
|
|
191
|
+
if (n > <u32>(CharCode.z - CharCode._0)) break;
|
|
192
|
+
|
|
193
|
+
let num = load<u8>(table + n);
|
|
194
|
+
if (num >= <u8>radix) break;
|
|
195
|
+
|
|
196
|
+
// @ts-ignore
|
|
197
|
+
result *= radix128;
|
|
198
|
+
// @ts-ignore
|
|
199
|
+
result += u128.fromU64(num);
|
|
200
|
+
} while (++index < len);
|
|
201
|
+
} else {
|
|
202
|
+
switch (radix) {
|
|
203
|
+
case 2: {
|
|
204
|
+
do {
|
|
205
|
+
let num: u32 = str.charCodeAt(index) - CharCode._0;
|
|
206
|
+
if (num >= 2) break;
|
|
207
|
+
// @ts-ignore
|
|
208
|
+
result <<= 1;
|
|
209
|
+
// @ts-ignore
|
|
210
|
+
result |= u128.fromU64(num);
|
|
211
|
+
} while (++index < len);
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
case 10: {
|
|
215
|
+
do {
|
|
216
|
+
let num: u32 = str.charCodeAt(index) - CharCode._0;
|
|
217
|
+
if (num >= 10) break;
|
|
218
|
+
// @ts-ignore
|
|
219
|
+
result = (result << 3) + (result << 1);
|
|
220
|
+
// @ts-ignore
|
|
221
|
+
result += u128.fromU64(num);
|
|
222
|
+
} while (++index < len);
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
case 16: {
|
|
226
|
+
do {
|
|
227
|
+
let n: u32 = str.charCodeAt(index) - CharCode._0;
|
|
228
|
+
if (n > <u32>(CharCode.z - CharCode._0)) break;
|
|
229
|
+
|
|
230
|
+
let num = load<u8>(table + n);
|
|
231
|
+
if (num >= 16) break;
|
|
232
|
+
|
|
233
|
+
// @ts-ignore
|
|
234
|
+
result <<= 4;
|
|
235
|
+
// @ts-ignore
|
|
236
|
+
result |= u128.fromU64(num);
|
|
237
|
+
} while (++index < len);
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
default: {
|
|
241
|
+
let radix128 = u128.fromU64(radix);
|
|
242
|
+
do {
|
|
243
|
+
let n: u32 = str.charCodeAt(index) - CharCode._0;
|
|
244
|
+
if (n > <u32>(CharCode.z - CharCode._0)) break;
|
|
245
|
+
|
|
246
|
+
let num = load<u8>(table + n);
|
|
247
|
+
if (num >= <u8>radix) break;
|
|
248
|
+
|
|
249
|
+
// @ts-ignore
|
|
250
|
+
result *= radix128;
|
|
251
|
+
// @ts-ignore
|
|
252
|
+
result += u128.fromU64(num);
|
|
253
|
+
} while (++index < len);
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
// @ts-ignore
|
|
259
|
+
return isNeg ? -result : result;
|
|
260
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Big integer types (u128 / i128 / u256), vendored verbatim from
|
|
2
|
+
// @btc-vision/as-bignum v1.0.0 (Apache-2.0) under ./bignum. See ./bignum/LICENSE.
|
|
3
|
+
//
|
|
4
|
+
// This file is a top-level standard-library entry, so toilscript globalizes its
|
|
5
|
+
// named re-exports the same way it does Array/Map/String. That makes u128, i128
|
|
6
|
+
// and u256 usable with no import, as native types:
|
|
7
|
+
//
|
|
8
|
+
// let a = u128.fromU64(40) + u128.fromU64(2);
|
|
9
|
+
// let b = u256.fromU128(a);
|
|
10
|
+
//
|
|
11
|
+
// The vendored sources are unmodified; only this thin globalizer is toilscript's.
|
|
12
|
+
// i256 is the signed-256 backing type of the family (u128/i128 convert to it),
|
|
13
|
+
// so it is globalized too for a self-consistent surface.
|
|
14
|
+
|
|
15
|
+
export { u128 } from "./bignum/integer/u128";
|
|
16
|
+
export { i128 } from "./bignum/integer/i128";
|
|
17
|
+
export { u256 } from "./bignum/integer/u256";
|
|
18
|
+
export { i256 } from "./bignum/integer/i256";
|
package/std/assembly/index.d.ts
CHANGED
|
@@ -2890,3 +2890,260 @@ declare namespace external {
|
|
|
2890
2890
|
|
|
2891
2891
|
/** Annotates a global for lazy compilation. */
|
|
2892
2892
|
declare function lazy(...args: any[]): any;
|
|
2893
|
+
|
|
2894
|
+
// Big integers — native globals implemented in std/assembly/bignum (vendored
|
|
2895
|
+
// from @btc-vision/as-bignum). The arithmetic/bitwise/comparison operators
|
|
2896
|
+
// (+ - * / % & | ^ << >> == != < > <= >=) are operator overloads resolved by
|
|
2897
|
+
// the compiler; the equivalent static methods are listed for tooling.
|
|
2898
|
+
|
|
2899
|
+
/** A 128-bit unsigned integer. */
|
|
2900
|
+
declare class u128 {
|
|
2901
|
+
lo: u64;
|
|
2902
|
+
hi: u64;
|
|
2903
|
+
constructor(lo?: u64, hi?: u64);
|
|
2904
|
+
|
|
2905
|
+
static readonly Zero: u128;
|
|
2906
|
+
static readonly One: u128;
|
|
2907
|
+
static readonly Min: u128;
|
|
2908
|
+
static readonly Max: u128;
|
|
2909
|
+
|
|
2910
|
+
static fromString(value: string, radix?: i32): u128;
|
|
2911
|
+
static fromI256(value: i256): u128;
|
|
2912
|
+
static fromU256(value: u256): u128;
|
|
2913
|
+
static fromI128(value: i128): u128;
|
|
2914
|
+
static fromU128(value: u128): u128;
|
|
2915
|
+
static fromI64(value: i64): u128;
|
|
2916
|
+
static fromU64(value: u64): u128;
|
|
2917
|
+
static fromF64(value: f64): u128;
|
|
2918
|
+
static fromF32(value: f32): u128;
|
|
2919
|
+
static fromI32(value: i32): u128;
|
|
2920
|
+
static fromU32(value: u32): u128;
|
|
2921
|
+
static fromBool(value: bool): u128;
|
|
2922
|
+
static fromBits(lo1: u32, lo2: u32, hi1: u32, hi2: u32): u128;
|
|
2923
|
+
static fromBytes<T>(array: T, bigEndian?: bool): u128;
|
|
2924
|
+
static fromBytesLE(array: u8[]): u128;
|
|
2925
|
+
static fromBytesBE(array: u8[]): u128;
|
|
2926
|
+
static fromUint8ArrayLE(array: Uint8Array): u128;
|
|
2927
|
+
static fromUint8ArrayBE(array: Uint8Array): u128;
|
|
2928
|
+
static from<T>(value: T): u128;
|
|
2929
|
+
|
|
2930
|
+
static isEmpty(value: u128): bool;
|
|
2931
|
+
static or(a: u128, b: u128): u128;
|
|
2932
|
+
static xor(a: u128, b: u128): u128;
|
|
2933
|
+
static and(a: u128, b: u128): u128;
|
|
2934
|
+
static shl(value: u128, shift: i32): u128;
|
|
2935
|
+
static shr(value: u128, shift: i32): u128;
|
|
2936
|
+
static shr_u(value: u128, shift: i32): u128;
|
|
2937
|
+
static rotl(value: u128, shift: i32): u128;
|
|
2938
|
+
static rotr(value: u128, shift: i32): u128;
|
|
2939
|
+
static add(a: u128, b: u128): u128;
|
|
2940
|
+
static sub(a: u128, b: u128): u128;
|
|
2941
|
+
static mul(a: u128, b: u128): u128;
|
|
2942
|
+
static div(a: u128, b: u128): u128;
|
|
2943
|
+
static rem(a: u128, b: u128): u128;
|
|
2944
|
+
static div10(value: u128): u128;
|
|
2945
|
+
static rem10(value: u128): u128;
|
|
2946
|
+
static pow(base: u128, exponent: i32): u128;
|
|
2947
|
+
static sqrt(value: u128): u128;
|
|
2948
|
+
static sqr(value: u128): u128;
|
|
2949
|
+
static muldiv(a: u128, b: u128, c: u128): u128;
|
|
2950
|
+
static eq(a: u128, b: u128): bool;
|
|
2951
|
+
static ne(a: u128, b: u128): bool;
|
|
2952
|
+
static lt(a: u128, b: u128): bool;
|
|
2953
|
+
static gt(a: u128, b: u128): bool;
|
|
2954
|
+
static le(a: u128, b: u128): bool;
|
|
2955
|
+
static ge(a: u128, b: u128): bool;
|
|
2956
|
+
static ord(a: u128, b: u128): i32;
|
|
2957
|
+
static popcnt(value: u128): i32;
|
|
2958
|
+
static clz(value: u128): i32;
|
|
2959
|
+
static ctz(value: u128): i32;
|
|
2960
|
+
|
|
2961
|
+
set(value: u128): this;
|
|
2962
|
+
setI64(value: i64): this;
|
|
2963
|
+
setU64(value: u64): this;
|
|
2964
|
+
setI32(value: i32): this;
|
|
2965
|
+
setU32(value: u32): this;
|
|
2966
|
+
isZero(): bool;
|
|
2967
|
+
not(): u128;
|
|
2968
|
+
neg(): u128;
|
|
2969
|
+
pos(): u128;
|
|
2970
|
+
sqr(): this;
|
|
2971
|
+
preInc(): this;
|
|
2972
|
+
preDec(): this;
|
|
2973
|
+
postInc(): u128;
|
|
2974
|
+
postDec(): u128;
|
|
2975
|
+
clone(): u128;
|
|
2976
|
+
as<T>(): T;
|
|
2977
|
+
toI64(): i64;
|
|
2978
|
+
toU64(): u64;
|
|
2979
|
+
toI32(): i32;
|
|
2980
|
+
toU32(): u32;
|
|
2981
|
+
toBool(): bool;
|
|
2982
|
+
toF64(): f64;
|
|
2983
|
+
toF32(): f32;
|
|
2984
|
+
toI128(): i128;
|
|
2985
|
+
toU128(): this;
|
|
2986
|
+
toI256(): i256;
|
|
2987
|
+
toU256(): u256;
|
|
2988
|
+
toBytes(bigEndian?: bool): u8[];
|
|
2989
|
+
toStaticBytes(bigEndian?: bool): StaticArray<u8>;
|
|
2990
|
+
toUint8Array(bigEndian?: bool): Uint8Array;
|
|
2991
|
+
toString(radix?: i32): string;
|
|
2992
|
+
}
|
|
2993
|
+
|
|
2994
|
+
/** A 128-bit signed integer. */
|
|
2995
|
+
declare class i128 {
|
|
2996
|
+
lo: u64;
|
|
2997
|
+
hi: i64;
|
|
2998
|
+
constructor(lo?: u64, hi?: i64);
|
|
2999
|
+
|
|
3000
|
+
static readonly Zero: i128;
|
|
3001
|
+
static readonly One: i128;
|
|
3002
|
+
static readonly Min: i128;
|
|
3003
|
+
static readonly Max: i128;
|
|
3004
|
+
|
|
3005
|
+
static fromString(value: string, radix?: i32): i128;
|
|
3006
|
+
static fromI256(value: i256): i128;
|
|
3007
|
+
static fromU256(value: u256): i128;
|
|
3008
|
+
static fromI128(value: i128): i128;
|
|
3009
|
+
static fromU128(value: u128): i128;
|
|
3010
|
+
static fromI64(value: i64): i128;
|
|
3011
|
+
static fromU64(value: u64): i128;
|
|
3012
|
+
static fromF64(value: f64): i128;
|
|
3013
|
+
static fromF32(value: f32): i128;
|
|
3014
|
+
static fromI32(value: i32): i128;
|
|
3015
|
+
static fromU32(value: u32): i128;
|
|
3016
|
+
static fromBits(lo1: i32, lo2: i32, hi1: i32, hi2: i32): i128;
|
|
3017
|
+
static fromBytes<T>(array: T, bigEndian?: bool): i128;
|
|
3018
|
+
static fromBytesLE(array: u8[]): i128;
|
|
3019
|
+
static fromBytesBE(array: u8[]): i128;
|
|
3020
|
+
static fromUint8ArrayLE(array: Uint8Array): i128;
|
|
3021
|
+
static fromUint8ArrayBE(array: Uint8Array): i128;
|
|
3022
|
+
static from<T>(value: T): i128;
|
|
3023
|
+
|
|
3024
|
+
static isEmpty(value: i128): bool;
|
|
3025
|
+
static or(a: i128, b: i128): i128;
|
|
3026
|
+
static xor(a: i128, b: i128): i128;
|
|
3027
|
+
static and(a: i128, b: i128): i128;
|
|
3028
|
+
static shl(value: i128, shift: i32): i128;
|
|
3029
|
+
static shr_u(value: i128, shift: i32): i128;
|
|
3030
|
+
static add(a: i128, b: i128): i128;
|
|
3031
|
+
static sub(a: i128, b: i128): i128;
|
|
3032
|
+
static eq(a: i128, b: i128): bool;
|
|
3033
|
+
static ne(a: i128, b: i128): bool;
|
|
3034
|
+
static lt(a: i128, b: i128): bool;
|
|
3035
|
+
static gt(a: i128, b: i128): bool;
|
|
3036
|
+
static le(a: i128, b: i128): bool;
|
|
3037
|
+
static ge(a: i128, b: i128): bool;
|
|
3038
|
+
static ord(a: i128, b: i128): i32;
|
|
3039
|
+
static popcnt(value: i128): i32;
|
|
3040
|
+
static clz(value: i128): i32;
|
|
3041
|
+
static ctz(value: i128): i32;
|
|
3042
|
+
static abs(value: i128): i128;
|
|
3043
|
+
|
|
3044
|
+
isNeg(): bool;
|
|
3045
|
+
isPos(): bool;
|
|
3046
|
+
isZero(): bool;
|
|
3047
|
+
not(): i128;
|
|
3048
|
+
neg(): i128;
|
|
3049
|
+
pos(): i128;
|
|
3050
|
+
toBytes(bigEndian?: bool): u8[];
|
|
3051
|
+
toStaticBytes(bigEndian?: bool): StaticArray<u8>;
|
|
3052
|
+
toUint8Array(bigEndian?: bool): Uint8Array;
|
|
3053
|
+
}
|
|
3054
|
+
|
|
3055
|
+
/** A 256-bit unsigned integer. */
|
|
3056
|
+
declare class u256 {
|
|
3057
|
+
lo1: u64;
|
|
3058
|
+
lo2: u64;
|
|
3059
|
+
hi1: u64;
|
|
3060
|
+
hi2: u64;
|
|
3061
|
+
constructor(lo1?: u64, lo2?: u64, hi1?: u64, hi2?: u64);
|
|
3062
|
+
|
|
3063
|
+
static readonly Zero: u256;
|
|
3064
|
+
static readonly One: u256;
|
|
3065
|
+
static readonly Min: u256;
|
|
3066
|
+
static readonly Max: u256;
|
|
3067
|
+
|
|
3068
|
+
static fromU256(value: u256): u256;
|
|
3069
|
+
static fromU128(value: u128): u256;
|
|
3070
|
+
static fromU64(value: u64): u256;
|
|
3071
|
+
static fromI64(value: i64): u256;
|
|
3072
|
+
static fromU32(value: u32): u256;
|
|
3073
|
+
static fromI32(value: i32): u256;
|
|
3074
|
+
static fromBits(l0: u32, l1: u32, l2: u32, l3: u32, h0: u32, h1: u32, h2: u32, h3: u32): u256;
|
|
3075
|
+
static fromBytes<T>(array: T, bigEndian?: bool): u256;
|
|
3076
|
+
static fromBytesLE(array: u8[]): u256;
|
|
3077
|
+
static fromBytesBE(array: u8[]): u256;
|
|
3078
|
+
static fromUint8ArrayLE(array: Uint8Array): u256;
|
|
3079
|
+
static fromUint8ArrayBE(array: Uint8Array): u256;
|
|
3080
|
+
static fromF64(value: f64): u256;
|
|
3081
|
+
static fromF32(value: f32): u256;
|
|
3082
|
+
static from<T>(value: T): u256;
|
|
3083
|
+
static fromString(str: string, radix?: i32): u256;
|
|
3084
|
+
|
|
3085
|
+
static isEmpty(value: u256): bool;
|
|
3086
|
+
static add(a: u256, b: u256): u256;
|
|
3087
|
+
static sub(a: u256, b: u256): u256;
|
|
3088
|
+
static mul(a: u256, b: u256): u256;
|
|
3089
|
+
static or(a: u256, b: u256): u256;
|
|
3090
|
+
static xor(a: u256, b: u256): u256;
|
|
3091
|
+
static and(a: u256, b: u256): u256;
|
|
3092
|
+
static shr(value: u256, shift: i32): u256;
|
|
3093
|
+
static shr_u(value: u256, shift: i32): u256;
|
|
3094
|
+
static eq(a: u256, b: u256): bool;
|
|
3095
|
+
static ne(a: u256, b: u256): bool;
|
|
3096
|
+
static lt(a: u256, b: u256): bool;
|
|
3097
|
+
static gt(a: u256, b: u256): bool;
|
|
3098
|
+
static le(a: u256, b: u256): bool;
|
|
3099
|
+
static ge(a: u256, b: u256): bool;
|
|
3100
|
+
static popcnt(value: u256): i32;
|
|
3101
|
+
static clz(value: u256): i32;
|
|
3102
|
+
static ctz(value: u256): i32;
|
|
3103
|
+
|
|
3104
|
+
set(value: u256): this;
|
|
3105
|
+
setI64(value: i64): this;
|
|
3106
|
+
setU64(value: u64): this;
|
|
3107
|
+
setI32(value: i32): this;
|
|
3108
|
+
setU32(value: u32): this;
|
|
3109
|
+
setU128(value: u128): this;
|
|
3110
|
+
isZero(): bool;
|
|
3111
|
+
not(): u256;
|
|
3112
|
+
neg(): u256;
|
|
3113
|
+
pos(): u256;
|
|
3114
|
+
postInc(): u256;
|
|
3115
|
+
postDec(): u256;
|
|
3116
|
+
clone(): u256;
|
|
3117
|
+
as<T>(): T;
|
|
3118
|
+
toI64(): i64;
|
|
3119
|
+
toU64(): u64;
|
|
3120
|
+
toI32(): i32;
|
|
3121
|
+
toU32(): u32;
|
|
3122
|
+
toBool(): bool;
|
|
3123
|
+
toI128(): i128;
|
|
3124
|
+
toU128(): u128;
|
|
3125
|
+
toU256(): this;
|
|
3126
|
+
toBytes(bigEndian?: bool): u8[];
|
|
3127
|
+
toStaticBytes(bigEndian?: bool): StaticArray<u8>;
|
|
3128
|
+
toUint8Array(bigEndian?: bool): Uint8Array;
|
|
3129
|
+
toString(radix?: i32): string;
|
|
3130
|
+
}
|
|
3131
|
+
|
|
3132
|
+
/** A 256-bit signed integer (backs the signed conversions of the family). */
|
|
3133
|
+
declare class i256 {
|
|
3134
|
+
lo1: i64;
|
|
3135
|
+
lo2: i64;
|
|
3136
|
+
hi1: i64;
|
|
3137
|
+
hi2: i64;
|
|
3138
|
+
constructor(lo1?: i64, lo2?: i64, hi1?: i64, hi2?: i64);
|
|
3139
|
+
|
|
3140
|
+
static readonly Zero: i256;
|
|
3141
|
+
static readonly One: i256;
|
|
3142
|
+
static readonly Min: i256;
|
|
3143
|
+
static readonly Max: i256;
|
|
3144
|
+
|
|
3145
|
+
static isEmpty(value: i256): bool;
|
|
3146
|
+
|
|
3147
|
+
isNeg(): bool;
|
|
3148
|
+
isZero(): bool;
|
|
3149
|
+
}
|
package/std/assembly.json
CHANGED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ToilScript TypeScript Language Service plugin.
|
|
3
|
+
*
|
|
4
|
+
* Stock TypeScript has no grammar for toil-native decorators applied to
|
|
5
|
+
* top-level functions and globals (`@main`, `@inline`, `@unmanaged`, ...), so
|
|
6
|
+
* the editor's language service flags them as errors even though the toilscript
|
|
7
|
+
* compiler (asc) handles them correctly. This plugin runs only inside the
|
|
8
|
+
* editor's language service (VS Code, WebStorm, etc. — never `tsc`/asc builds)
|
|
9
|
+
* and removes exactly those decorator-grammar false positives:
|
|
10
|
+
*
|
|
11
|
+
* TS1206 "Decorators are not valid here."
|
|
12
|
+
* TS1249 "A decorator can only decorate a method implementation, not an overload."
|
|
13
|
+
*
|
|
14
|
+
* Every other diagnostic — unknown types, bad calls, missing names — passes
|
|
15
|
+
* through untouched, so real type errors are still surfaced.
|
|
16
|
+
*/
|
|
17
|
+
const DECORATOR_GRAMMAR_CODES = new Set([1206, 1249]);
|
|
18
|
+
|
|
19
|
+
function init() {
|
|
20
|
+
return {
|
|
21
|
+
create(info) {
|
|
22
|
+
const ls = info.languageService;
|
|
23
|
+
|
|
24
|
+
// Proxy the language service, forwarding everything to the real one.
|
|
25
|
+
const proxy = Object.create(null);
|
|
26
|
+
for (const key of Object.keys(ls)) {
|
|
27
|
+
const value = ls[key];
|
|
28
|
+
proxy[key] = typeof value === 'function' ? value.bind(ls) : value;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const strip = (diagnostics) =>
|
|
32
|
+
diagnostics.filter((d) => !DECORATOR_GRAMMAR_CODES.has(d.code));
|
|
33
|
+
|
|
34
|
+
proxy.getSemanticDiagnostics = (fileName) =>
|
|
35
|
+
strip(ls.getSemanticDiagnostics(fileName));
|
|
36
|
+
proxy.getSyntacticDiagnostics = (fileName) =>
|
|
37
|
+
strip(ls.getSyntacticDiagnostics(fileName));
|
|
38
|
+
|
|
39
|
+
return proxy;
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
module.exports = init;
|