toilscript 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +94 -0
  3. package/README.md +114 -0
  4. package/bin/asc.js +35 -0
  5. package/bin/asinit.js +468 -0
  6. package/dist/asc.d.ts +4 -0
  7. package/dist/toilscript.d.ts +4 -0
  8. package/dist/transform.cjs +1 -0
  9. package/dist/transform.d.ts +1 -0
  10. package/dist/transform.js +1 -0
  11. package/lib/binaryen.d.ts +2 -0
  12. package/lib/binaryen.js +2 -0
  13. package/package.json +114 -0
  14. package/std/README.md +6 -0
  15. package/std/assembly/array.ts +550 -0
  16. package/std/assembly/arraybuffer.ts +77 -0
  17. package/std/assembly/atomics.ts +127 -0
  18. package/std/assembly/bindings/asyncify.ts +16 -0
  19. package/std/assembly/bindings/dom.ts +291 -0
  20. package/std/assembly/bindings/node.ts +6 -0
  21. package/std/assembly/bitflags.ts +53 -0
  22. package/std/assembly/builtins.ts +2650 -0
  23. package/std/assembly/byteslice.ts +177 -0
  24. package/std/assembly/compat.ts +2 -0
  25. package/std/assembly/console.ts +42 -0
  26. package/std/assembly/crypto.ts +9 -0
  27. package/std/assembly/dataview.ts +181 -0
  28. package/std/assembly/date.ts +375 -0
  29. package/std/assembly/diagnostics.ts +11 -0
  30. package/std/assembly/encoding.ts +151 -0
  31. package/std/assembly/endian.ts +45 -0
  32. package/std/assembly/error.ts +44 -0
  33. package/std/assembly/fixedarray.ts +173 -0
  34. package/std/assembly/fixedmap.ts +326 -0
  35. package/std/assembly/fixedset.ts +275 -0
  36. package/std/assembly/function.ts +42 -0
  37. package/std/assembly/index.d.ts +2891 -0
  38. package/std/assembly/iterator.ts +35 -0
  39. package/std/assembly/map.ts +269 -0
  40. package/std/assembly/math.ts +3289 -0
  41. package/std/assembly/memory.ts +123 -0
  42. package/std/assembly/number.ts +388 -0
  43. package/std/assembly/object.ts +36 -0
  44. package/std/assembly/performance.ts +9 -0
  45. package/std/assembly/pointer.ts +80 -0
  46. package/std/assembly/polyfills.ts +27 -0
  47. package/std/assembly/process.ts +50 -0
  48. package/std/assembly/reference.ts +48 -0
  49. package/std/assembly/regexp.ts +12 -0
  50. package/std/assembly/rt/README.md +83 -0
  51. package/std/assembly/rt/common.ts +81 -0
  52. package/std/assembly/rt/index-incremental.ts +2 -0
  53. package/std/assembly/rt/index-memory.ts +1 -0
  54. package/std/assembly/rt/index-minimal.ts +2 -0
  55. package/std/assembly/rt/index-stub.ts +1 -0
  56. package/std/assembly/rt/index.d.ts +37 -0
  57. package/std/assembly/rt/itcms.ts +419 -0
  58. package/std/assembly/rt/memory-runtime.ts +94 -0
  59. package/std/assembly/rt/rtrace.ts +15 -0
  60. package/std/assembly/rt/stub.ts +133 -0
  61. package/std/assembly/rt/tcms.ts +254 -0
  62. package/std/assembly/rt/tlsf.ts +592 -0
  63. package/std/assembly/rt.ts +90 -0
  64. package/std/assembly/set.ts +225 -0
  65. package/std/assembly/shared/feature.ts +68 -0
  66. package/std/assembly/shared/runtime.ts +13 -0
  67. package/std/assembly/shared/target.ts +11 -0
  68. package/std/assembly/shared/tsconfig.json +11 -0
  69. package/std/assembly/shared/typeinfo.ts +72 -0
  70. package/std/assembly/staticarray.ts +423 -0
  71. package/std/assembly/string.ts +850 -0
  72. package/std/assembly/symbol.ts +114 -0
  73. package/std/assembly/table.ts +16 -0
  74. package/std/assembly/tsconfig.json +6 -0
  75. package/std/assembly/typedarray.ts +1954 -0
  76. package/std/assembly/uri.ts +17 -0
  77. package/std/assembly/util/bytes.ts +107 -0
  78. package/std/assembly/util/casemap.ts +497 -0
  79. package/std/assembly/util/error.ts +58 -0
  80. package/std/assembly/util/hash.ts +117 -0
  81. package/std/assembly/util/math.ts +1922 -0
  82. package/std/assembly/util/memory.ts +290 -0
  83. package/std/assembly/util/number.ts +873 -0
  84. package/std/assembly/util/sort.ts +313 -0
  85. package/std/assembly/util/string.ts +1202 -0
  86. package/std/assembly/util/uri.ts +275 -0
  87. package/std/assembly/vector.ts +4 -0
  88. package/std/assembly.json +16 -0
  89. package/std/portable/index.d.ts +461 -0
  90. package/std/portable/index.js +416 -0
  91. package/std/portable.json +11 -0
  92. package/std/types/assembly/index.d.ts +1 -0
  93. package/std/types/assembly/package.json +3 -0
  94. package/std/types/portable/index.d.ts +1 -0
  95. package/std/types/portable/package.json +3 -0
  96. package/tsconfig-base.json +13 -0
  97. package/util/README.md +23 -0
  98. package/util/browser/fs.js +1 -0
  99. package/util/browser/module.js +5 -0
  100. package/util/browser/path.js +520 -0
  101. package/util/browser/process.js +59 -0
  102. package/util/browser/url.js +23 -0
  103. package/util/cpu.d.ts +9 -0
  104. package/util/cpu.js +42 -0
  105. package/util/find.d.ts +6 -0
  106. package/util/find.js +20 -0
  107. package/util/node.d.ts +21 -0
  108. package/util/node.js +34 -0
  109. package/util/options.d.ts +70 -0
  110. package/util/options.js +262 -0
  111. package/util/terminal.d.ts +52 -0
  112. package/util/terminal.js +35 -0
  113. package/util/text.d.ts +26 -0
  114. package/util/text.js +114 -0
  115. package/util/tsconfig.json +9 -0
  116. package/util/web.d.ts +11 -0
  117. package/util/web.js +33 -0
@@ -0,0 +1,416 @@
1
+ /** @module std/portable *//***/
2
+
3
+ let globalScope = typeof window !== "undefined" && window || typeof global !== "undefined" && global || self;
4
+ if (typeof globalScope.ASC_TARGET === "undefined") {
5
+
6
+ globalScope.ASC_TARGET = 0; // Target.JS
7
+ globalScope.ASC_RUNTIME = 0; // Runtime.Stub
8
+ globalScope.ASC_NO_ASSERT = false;
9
+ globalScope.ASC_MEMORY_BASE = 0;
10
+ globalScope.ASC_OPTIMIZE_LEVEL = 3;
11
+ globalScope.ASC_SHRINK_LEVEL = 0;
12
+ globalScope.ASC_FEATURE_MUTABLE_GLOBAL = false;
13
+ globalScope.ASC_FEATURE_SIGN_EXTENSION = false;
14
+ globalScope.ASC_FEATURE_BULK_MEMORY = false;
15
+ globalScope.ASC_FEATURE_SIMD = false;
16
+ globalScope.ASC_FEATURE_THREADS = false;
17
+
18
+ let F64 = new Float64Array(1);
19
+ let U64 = new Uint32Array(F64.buffer);
20
+
21
+ Object.defineProperties(
22
+ globalScope["i8"] = function i8(value) { return value << 24 >> 24; },
23
+ {
24
+ "MIN_VALUE": { value: -128 },
25
+ "MAX_VALUE": { value: 127 },
26
+
27
+ parse(str, radix) { return parseInt(str, radix) << 24 >> 24; }
28
+ }
29
+ );
30
+
31
+ Object.defineProperties(
32
+ globalScope["i16"] = function i16(value) { return value << 16 >> 16; },
33
+ {
34
+ "MIN_VALUE": { value: -32768 },
35
+ "MAX_VALUE": { value: 32767 },
36
+
37
+ parse(str, radix) { return parseInt(str, radix) << 16 >> 16; }
38
+ }
39
+ );
40
+
41
+ Object.defineProperties(
42
+ globalScope["i32"] = globalScope["isize"] = function i32(value) { return value | 0; },
43
+ {
44
+ "MIN_VALUE": { value: -2147483648 },
45
+ "MAX_VALUE": { value: 2147483647 },
46
+
47
+ parse(str, radix) { return parseInt(str, radix) | 0; }
48
+ }
49
+ );
50
+
51
+ Object.defineProperties(
52
+ globalScope["u8"] = function u8(value) { return value & 0xff; },
53
+ {
54
+ "MIN_VALUE": { value: 0 },
55
+ "MAX_VALUE": { value: 255 },
56
+
57
+ parse(str, radix) { return parseInt(str, radix) & 0xff; }
58
+ }
59
+ );
60
+
61
+ Object.defineProperties(
62
+ globalScope["u16"] = function u16(value) { return value & 0xffff; },
63
+ {
64
+ "MIN_VALUE": { value: 0 },
65
+ "MAX_VALUE": { value: 65535 },
66
+
67
+ parse(str, radix) { return parseInt(str, radix) & 0xffff; }
68
+ }
69
+ );
70
+
71
+ Object.defineProperties(
72
+ globalScope["u32"] = globalScope["usize"] = function u32(value) { return value >>> 0; },
73
+ {
74
+ "MIN_VALUE": { value: 0 },
75
+ "MAX_VALUE": { value: 4294967295 },
76
+
77
+ parse(str, radix) { return parseInt(str, radix) >>> 0; }
78
+ }
79
+ );
80
+
81
+ Object.defineProperties(
82
+ globalScope["bool"] = function bool(value) { return !!value; },
83
+ {
84
+ "MIN_VALUE": { value: false },
85
+ "MAX_VALUE": { value: true },
86
+
87
+ parse(str) { return str.trim() === "true"; }
88
+ }
89
+ );
90
+
91
+ Object.defineProperties(
92
+ globalScope["f32"] = function f32(value) { return Math.fround(value); },
93
+ {
94
+ "EPSILON": { value: 1.1920928955078125e-07 },
95
+ "MIN_VALUE": { value: 1.401298464324817e-45 },
96
+ "MAX_VALUE": { value: 3.4028234663852886e+38 },
97
+ "MIN_NORMAL_VALUE": { value: 1.1754943508222875e-38 },
98
+ "MIN_SAFE_INTEGER": { value: -16777215 },
99
+ "MAX_SAFE_INTEGER": { value: 16777215 },
100
+ "POSITIVE_INFINITY": { value: Infinity },
101
+ "NEGATIVE_INFINITY": { value: -Infinity },
102
+ "NaN": { value: NaN },
103
+
104
+ parse(str) { return Math.fround(parseFloat(str)); }
105
+ }
106
+ );
107
+
108
+ Object.defineProperties(
109
+ globalScope["f64"] = function f64(value) { return +value; },
110
+ {
111
+ "EPSILON": { value: 2.2204460492503131e-016 },
112
+ "MIN_VALUE": { value: 5e-324 },
113
+ "MAX_VALUE": { value: 1.7976931348623157e+308 },
114
+ "MIN_NORMAL_VALUE": { value: 2.2250738585072014e-308 },
115
+ "MIN_SAFE_INTEGER": { value: -9007199254740991 },
116
+ "MAX_SAFE_INTEGER": { value: 9007199254740991 },
117
+ "POSITIVE_INFINITY": { value: Infinity },
118
+ "NEGATIVE_INFINITY": { value: -Infinity },
119
+ "NaN": { value: NaN },
120
+
121
+ parse(str) { return parseFloat(str); }
122
+ }
123
+ );
124
+
125
+ globalScope["clz"] = Math.clz32;
126
+
127
+ globalScope["ctz"] = function ctz(value) {
128
+ return 32 - Math.clz32(~value & (value - 1));
129
+ };
130
+
131
+ globalScope["popcnt"] = function popcnt(value) {
132
+ value -= value >>> 1 & 0x55555555;
133
+ value = (value & 0x33333333) + (value >>> 2 & 0x33333333);
134
+ return (((value + (value >>> 4)) & 0x0F0F0F0F) * 0x01010101) >>> 24;
135
+ };
136
+
137
+ globalScope["rotl"] = function rotl(value, shift) {
138
+ shift &= 31;
139
+ return (value << shift) | (value >>> (32 - shift));
140
+ };
141
+
142
+ globalScope["rotr"] = function rotr(value, shift) {
143
+ shift &= 31;
144
+ return (value >>> shift) | (value << (32 - shift));
145
+ };
146
+
147
+ globalScope["abs"] = Math.abs;
148
+
149
+ globalScope["max"] = Math.max;
150
+
151
+ globalScope["min"] = Math.min;
152
+
153
+ globalScope["ceil"] = Math.ceil;
154
+
155
+ globalScope["floor"] = Math.floor;
156
+
157
+ globalScope["nearest"] = function nearest(value) {
158
+ const INV_EPS64 = 4503599627370496.0;
159
+ const y = Math.abs(value);
160
+ return y < INV_EPS64
161
+ ? (y + INV_EPS64 - INV_EPS64) * Math.sign(value)
162
+ : value;
163
+ };
164
+
165
+ globalScope["select"] = function select(ifTrue, ifFalse, condition) {
166
+ return condition ? ifTrue : ifFalse;
167
+ };
168
+
169
+ globalScope["sqrt"] = Math.sqrt;
170
+
171
+ globalScope["trunc"] = Math.trunc;
172
+
173
+ globalScope["copysign"] = function copysign(x, y) {
174
+ return y
175
+ ? Math.abs(x) * Math.sign(y)
176
+ : (F64[0] = y, U64[1] >>> 31 ? -1 : 1); // +0, -0, -NaN, +NaN
177
+ };
178
+
179
+ globalScope["bswap"] = function bswap(value) {
180
+ let a = value >> 8 & 0x00FF00FF;
181
+ let b = (value & 0x00FF00FF) << 8;
182
+ value = a | b;
183
+ a = value >> 16 & 0x0000FFFF;
184
+ b = (value & 0x0000FFFF) << 16;
185
+ return a | b;
186
+ };
187
+
188
+ function UnreachableError() {
189
+ if (Error.captureStackTrace) {
190
+ Error.captureStackTrace(this, UnreachableError);
191
+ } else {
192
+ this.stack = this.name + ": " + this.message + "\n" + new Error().stack;
193
+ }
194
+ }
195
+ UnreachableError.prototype = Object.create(Error.prototype);
196
+ UnreachableError.prototype.name = "UnreachableError";
197
+ UnreachableError.prototype.message = "unreachable";
198
+
199
+ globalScope["unreachable"] = function unreachable() {
200
+ throw new UnreachableError();
201
+ };
202
+
203
+ function AssertionError(message) {
204
+ this.message = message || "assertion failed";
205
+ if (Error.captureStackTrace) {
206
+ Error.captureStackTrace(this, AssertionError);
207
+ } else {
208
+ this.stack = this.name + ": " + this.message + "\n" + new Error().stack;
209
+ }
210
+ }
211
+ AssertionError.prototype = Object.create(Error.prototype);
212
+ AssertionError.prototype.name = "AssertionError";
213
+
214
+ globalScope["assert"] = function assert(isTrueish, message) {
215
+ if (isTrueish) return isTrueish;
216
+ throw new AssertionError(message);
217
+ };
218
+
219
+ globalScope["changetype"] = function changetype(value) {
220
+ return value;
221
+ };
222
+
223
+ String["fromCharCodes"] = function fromCharCodes(arr) {
224
+ const CHUNKSIZE = 1 << 13;
225
+ const len = arr.length;
226
+ if (len <= CHUNKSIZE) {
227
+ return String.fromCharCode.apply(String, arr);
228
+ }
229
+ let index = 0;
230
+ let parts = '';
231
+ while (index < len) {
232
+ parts += String.fromCharCode.apply(
233
+ String,
234
+ arr.slice(index, Math.min(index + CHUNKSIZE, len))
235
+ );
236
+ index += CHUNKSIZE;
237
+ }
238
+ return parts;
239
+ };
240
+
241
+ String["fromCodePoints"] = function fromCodePoints(arr) {
242
+ const CHUNKSIZE = 1 << 13;
243
+ const len = arr.length;
244
+ if (len <= CHUNKSIZE) {
245
+ return String.fromCodePoint.apply(String, arr);
246
+ }
247
+ let index = 0;
248
+ let parts = '';
249
+ while (index < len) {
250
+ parts += String.fromCodePoint.apply(
251
+ String,
252
+ arr.slice(index, Math.min(index + CHUNKSIZE, len))
253
+ );
254
+ index += CHUNKSIZE;
255
+ }
256
+ return parts;
257
+ };
258
+
259
+ if (!String.prototype.at) {
260
+ Object.defineProperty(String.prototype, "at", {
261
+ value: function at(index) {
262
+ return this.charAt(index >= 0 ? index : index + this.length);
263
+ },
264
+ configurable: true
265
+ });
266
+ }
267
+
268
+ if (!String.prototype.replaceAll) {
269
+ Object.defineProperty(String.prototype, "replaceAll", {
270
+ value: function replaceAll(search, replacement) {
271
+ let res = this.split(search).join(replacement);
272
+ if (!search.length) res = replacement + res + replacement;
273
+ return res;
274
+ },
275
+ configurable: true
276
+ });
277
+ }
278
+
279
+ function defaultComparator(a, b) {
280
+ if (a == b) {
281
+ if (a != 0) return 0;
282
+ a = 1 / a;
283
+ b = 1 / b;
284
+ } else {
285
+ let nanA = a != a, nanB = b != b;
286
+ if (nanA | nanB) return nanA - nanB;
287
+ if (a == null) a = String(a);
288
+ if (b == null) b = String(b);
289
+ }
290
+ return a > b ? 1 : -1;
291
+ }
292
+
293
+ const arraySort = Array.prototype.sort;
294
+ Array.prototype.sort = function sort(comparator) {
295
+ return arraySort.call(this, comparator || defaultComparator);
296
+ };
297
+
298
+ [ Array,
299
+ Uint8ClampedArray,
300
+ Uint8Array, Int8Array,
301
+ Uint16Array, Int16Array,
302
+ Uint32Array, Int32Array,
303
+ Float32Array, Float64Array
304
+ ].forEach(Ctr => {
305
+ if (!Ctr.prototype.at) {
306
+ Object.defineProperty(Ctr.prototype, "at", {
307
+ value: function at(index) {
308
+ return this[index >= 0 ? index : index + this.length];
309
+ },
310
+ configurable: true
311
+ });
312
+ }
313
+
314
+ if (!Ctr.prototype.findLastIndex) {
315
+ Object.defineProperty(Ctr.prototype, "findLastIndex", {
316
+ value: function findLastIndex(fn) {
317
+ for (let i = this.length - 1; i >= 0; --i) {
318
+ if (fn(this[i], i, this)) return i;
319
+ }
320
+ return -1;
321
+ },
322
+ configurable: true
323
+ });
324
+ }
325
+
326
+ if (Ctr != Array) {
327
+ Object.defineProperty(Ctr, "wrap", {
328
+ value: function wrap(buffer, byteOffset, length) {
329
+ return new Ctr(buffer, byteOffset, length);
330
+ },
331
+ configurable: true
332
+ });
333
+ }
334
+ });
335
+
336
+ globalScope["isInteger"] = Number.isInteger;
337
+
338
+ globalScope["isFloat"] = function isFloat(arg) {
339
+ return typeof arg === "number";
340
+ };
341
+
342
+ globalScope["isNullable"] = function isNullable(arg) {
343
+ return true;
344
+ };
345
+
346
+ globalScope["isReference"] = function isReference(arg) {
347
+ return typeof arg === "object" || typeof arg === "string";
348
+ };
349
+
350
+ globalScope["isFunction"] = function isFunction(arg) {
351
+ return typeof arg === "function";
352
+ };
353
+
354
+ globalScope["isString"] = function isString(arg) {
355
+ return typeof arg === "string" || arg instanceof String;
356
+ };
357
+
358
+ globalScope["isArray"] = Array.isArray;
359
+ globalScope["isArrayLike"] = function isArrayLike(expr) {
360
+ return expr
361
+ && typeof expr === 'object'
362
+ && typeof expr.length === 'number'
363
+ && expr.length >= 0
364
+ && Math.trunc(expr.length) === expr.length;
365
+ };
366
+
367
+ globalScope["isDefined"] = function isDefined(expr) {
368
+ return typeof expr !== "undefined";
369
+ };
370
+
371
+ globalScope["isConstant"] = function isConstant(expr) {
372
+ return false;
373
+ };
374
+
375
+ globalScope["unchecked"] = function unchecked(expr) {
376
+ return expr;
377
+ };
378
+
379
+ globalScope["fmod"] = function fmod(x, y) {
380
+ return x % y;
381
+ };
382
+
383
+ globalScope["fmodf"] = function fmodf(x, y) {
384
+ return Math.fround(x % y);
385
+ };
386
+
387
+ globalScope["JSMath"] = Math;
388
+
389
+ Object.defineProperties(globalScope["JSMath"], {
390
+ sincos_sin: { value: 0.0, writable: true },
391
+ sincos_cos: { value: 0.0, writable: true },
392
+ signbit: {
393
+ value: function signbit(x) {
394
+ F64[0] = x; return Boolean(U64[1] >>> 31);
395
+ }
396
+ },
397
+ sincos: {
398
+ value: function sincos(x) {
399
+ this.sincos_sin = Math.sin(x);
400
+ this.sincos_cos = Math.cos(x);
401
+ }
402
+ },
403
+ exp2: {
404
+ value: function exp2(x) {
405
+ return Math.pow(2, x);
406
+ }
407
+ }
408
+ });
409
+
410
+ globalScope["unmanaged"] = function() { /* nop */ };
411
+
412
+ globalScope["trace"] = function(message, n) {
413
+ if (n) message += Array.prototype.slice.call(arguments, 2, 2 + n);
414
+ console.error("trace: " + message);
415
+ };
416
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "../tsconfig-base.json",
3
+ "compilerOptions": {
4
+ "target": "esnext",
5
+ "module": "commonjs",
6
+ "allowJs": true,
7
+ "typeRoots": [ "types" ],
8
+ "types": [ "portable" ],
9
+ "lib": ["esnext", "esnext.string"]
10
+ }
11
+ }
@@ -0,0 +1 @@
1
+ import "../../assembly/index";
@@ -0,0 +1,3 @@
1
+ {
2
+ "types": "index.d.ts"
3
+ }
@@ -0,0 +1 @@
1
+ import "../../portable/index";
@@ -0,0 +1,3 @@
1
+ {
2
+ "types": "index.d.ts"
3
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "compilerOptions": {
3
+ "strict": true,
4
+ "alwaysStrict": true,
5
+ "noImplicitAny": true,
6
+ "noImplicitReturns": true,
7
+ "noImplicitThis": true,
8
+ "noEmitOnError": true,
9
+ "strictNullChecks": true,
10
+ "experimentalDecorators": true,
11
+ "preserveConstEnums": false
12
+ }
13
+ }
package/util/README.md ADDED
@@ -0,0 +1,23 @@
1
+ Utility
2
+ =======
3
+
4
+ Various utility functions shared accross the codebase.
5
+
6
+ | Utility | Description
7
+ |----------|-------------------------------------------
8
+ | cpu | Obtains information about the CPU
9
+ | find | Provides support for finding files etc.
10
+ | node | Minimal polyfills for Node.js builtins
11
+ | options | Support for command line options parsing
12
+ | terminal | Provides support for terminal colors
13
+ | text | Utility for text processing
14
+ | web | Minimal polyfills for browser builtins
15
+
16
+ It is possible to reuse the utility in your own project like so:
17
+
18
+ ```ts
19
+ import { ... } from "assemblyscript/util/terminal.js";
20
+ ...
21
+ ```
22
+
23
+ Keep in mind, however, that utility can change at any time.
@@ -0,0 +1 @@
1
+ export const promises = {};
@@ -0,0 +1,5 @@
1
+ export function createRequire() {
2
+ return function require(path) {
3
+ throw new Error(`Cannot find module: '${path}'`);
4
+ };
5
+ }