toilscript 0.1.18 → 0.1.20
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/dist/cli.js +55 -8
- package/dist/cli.js.map +2 -2
- package/dist/importmap.json +2 -2
- package/dist/toilscript.js +171 -153
- package/dist/toilscript.js.map +3 -3
- package/dist/web.js +3 -3
- package/package.json +1 -1
- package/std/assembly/bignum/integer/i128.ts +10 -0
- package/std/assembly/bignum/integer/i256.ts +38 -6
- package/std/assembly/json.ts +5 -0
package/dist/web.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var ASSEMBLYSCRIPT_VERSION = "0.1.
|
|
1
|
+
var ASSEMBLYSCRIPT_VERSION = "0.1.20";
|
|
2
2
|
var ASSEMBLYSCRIPT_IMPORTMAP = {
|
|
3
3
|
"imports": {
|
|
4
|
-
"toilscript": "https://cdn.jsdelivr.net/npm/toilscript@0.1.
|
|
5
|
-
"toilscript/cli": "https://cdn.jsdelivr.net/npm/toilscript@0.1.
|
|
4
|
+
"toilscript": "https://cdn.jsdelivr.net/npm/toilscript@0.1.20/dist/toilscript.js",
|
|
5
|
+
"toilscript/cli": "https://cdn.jsdelivr.net/npm/toilscript@0.1.20/dist/cli.js",
|
|
6
6
|
"binaryen": "https://cdn.jsdelivr.net/npm/binaryen@129.0.0-nightly.20260428/index.js",
|
|
7
7
|
"long": "https://cdn.jsdelivr.net/npm/long@5.3.2/index.js"
|
|
8
8
|
}
|
package/package.json
CHANGED
|
@@ -355,6 +355,16 @@ export class i128 {
|
|
|
355
355
|
return new i128(sum, hi2);
|
|
356
356
|
}
|
|
357
357
|
|
|
358
|
+
/**
|
|
359
|
+
* Decimal (or `radix`) string. Sign + unsigned magnitude: negate (two's complement)
|
|
360
|
+
* and reinterpret as u128, which is layout-identical. i128.Min survives because
|
|
361
|
+
* neg(Min) == Min and its bit pattern reinterpreted unsigned is exactly 2^127.
|
|
362
|
+
*/
|
|
363
|
+
toString(radix: i32 = 10): string {
|
|
364
|
+
if (!this.isNeg()) return changetype<u128>(this).toString(radix);
|
|
365
|
+
return '-' + changetype<u128>(this.neg()).toString(radix);
|
|
366
|
+
}
|
|
367
|
+
|
|
358
368
|
/**
|
|
359
369
|
* Convert to a normal array of bytes (16 bytes for 128 bits).
|
|
360
370
|
* @param bigEndian If true, the highest bytes come first.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { u256 } from './u256';
|
|
2
|
+
|
|
1
3
|
export class i256 {
|
|
2
4
|
|
|
3
5
|
constructor(
|
|
@@ -24,6 +26,17 @@ export class i256 {
|
|
|
24
26
|
return new i256(u64.MAX_VALUE, u64.MAX_VALUE, u64.MAX_VALUE, 0x7FFFFFFFFFFFFFFF);
|
|
25
27
|
}
|
|
26
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Construct from a decimal (or `radix`) string. A leading `-` parses the magnitude
|
|
31
|
+
* and negates (two's complement), mirroring `i128.fromString`.
|
|
32
|
+
*/
|
|
33
|
+
static fromString(str: string, radix: i32 = 10): i256 {
|
|
34
|
+
if (str.length > 0 && str.charCodeAt(0) == 0x2D /* '-' */) {
|
|
35
|
+
return changetype<i256>(u256.fromString(str.substring(1), radix)).neg();
|
|
36
|
+
}
|
|
37
|
+
return changetype<i256>(u256.fromString(str, radix));
|
|
38
|
+
}
|
|
39
|
+
|
|
27
40
|
@inline @operator.prefix('!')
|
|
28
41
|
static isEmpty(value: i256): bool {
|
|
29
42
|
return value.isZero();
|
|
@@ -39,12 +52,31 @@ export class i256 {
|
|
|
39
52
|
return !(this.lo1 | this.lo2 | this.hi1 | this.hi2);
|
|
40
53
|
}
|
|
41
54
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
55
|
+
@inline @operator.prefix('-')
|
|
56
|
+
neg(): i256 {
|
|
57
|
+
// two's complement: ~x + 1, carrying across the four limbs
|
|
58
|
+
let l1 = ~(<u64>this.lo1);
|
|
59
|
+
let l2 = ~(<u64>this.lo2);
|
|
60
|
+
let h1 = ~(<u64>this.hi1);
|
|
61
|
+
let h2 = ~(<u64>this.hi2);
|
|
62
|
+
l1 += 1;
|
|
63
|
+
if (!l1) {
|
|
64
|
+
l2 += 1;
|
|
65
|
+
if (!l2) {
|
|
66
|
+
h1 += 1;
|
|
67
|
+
if (!h1) h2 += 1;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return new i256(<i64>l1, <i64>l2, <i64>h1, <i64>h2);
|
|
46
71
|
}
|
|
47
|
-
*/
|
|
48
72
|
|
|
49
|
-
|
|
73
|
+
/**
|
|
74
|
+
* Decimal (or `radix`) string. Sign + unsigned magnitude: negate (two's complement)
|
|
75
|
+
* and reinterpret as u256, which is layout-identical. i256.Min survives because
|
|
76
|
+
* neg(Min) == Min and its bit pattern reinterpreted unsigned is exactly 2^255.
|
|
77
|
+
*/
|
|
78
|
+
toString(radix: i32 = 10): string {
|
|
79
|
+
if (!this.isNeg()) return changetype<u256>(this).toString(radix);
|
|
80
|
+
return '-' + changetype<u256>(this.neg()).toString(radix);
|
|
81
|
+
}
|
|
50
82
|
}
|
package/std/assembly/json.ts
CHANGED
|
@@ -126,6 +126,9 @@ export class JSON {
|
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
asI64(): i64 {
|
|
129
|
+
// 64-bit integers cross JSON as decimal strings (JS numbers lose precision past
|
|
130
|
+
// 2^53), so a string token reads as its integer value, not 0.
|
|
131
|
+
if (this.kind == JSON.STR) return this.str.length ? i64.parse(this.str) : 0;
|
|
129
132
|
if (this.kind != JSON.NUM) return 0;
|
|
130
133
|
if (this.numKind == JSON.N_I64) return this.inum;
|
|
131
134
|
if (this.numKind == JSON.N_U64) return <i64>this.unum;
|
|
@@ -133,6 +136,8 @@ export class JSON {
|
|
|
133
136
|
}
|
|
134
137
|
|
|
135
138
|
asU64(): u64 {
|
|
139
|
+
// See asI64: decimal-string tokens are first-class for 64-bit integers.
|
|
140
|
+
if (this.kind == JSON.STR) return this.str.length ? u64.parse(this.str) : 0;
|
|
136
141
|
if (this.kind != JSON.NUM) return 0;
|
|
137
142
|
if (this.numKind == JSON.N_U64) return this.unum;
|
|
138
143
|
if (this.numKind == JSON.N_I64) return <u64>this.inum;
|