Skip to content

Commit abf3de9

Browse files
MaxGraeydcodeIO
authored andcommitted
Fix implicit string to bool conversion (#567)
1 parent 85de20c commit abf3de9

12 files changed

+930
-827
lines changed

std/assembly/string.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class String {
4242
);
4343
} else {
4444
code -= 0x10000;
45-
let hi: u32 = (code >>> 10) + 0xD800;
45+
let hi: u32 = (code >>> 10) + 0xD800;
4646
let lo: u32 = (code & 0x3FF) + 0xDC00;
4747
store<u32>(
4848
changetype<usize>(out),
@@ -110,9 +110,9 @@ export class String {
110110
assert(this !== null);
111111
if (other === null) other = changetype<String>("null");
112112

113-
var thisLen: isize = this.length;
113+
var thisLen: isize = this.length;
114114
var otherLen: isize = other.length;
115-
var outLen: usize = thisLen + otherLen;
115+
var outLen: usize = thisLen + otherLen;
116116
if (outLen == 0) return changetype<String>("");
117117
var out = allocateUnsafe(outLen);
118118
copyUnsafe(out, 0, this, 0, thisLen);
@@ -141,6 +141,11 @@ export class String {
141141
return !compareUnsafe(left, 0, right, 0, leftLength);
142142
}
143143

144+
@operator.prefix("!")
145+
private static __not(str: String): bool {
146+
return str === null || !str.length;
147+
}
148+
144149
@operator("!=")
145150
private static __ne(left: String, right: String): bool {
146151
return !this.__eq(left, right);
@@ -345,8 +350,8 @@ export class String {
345350
var out = allocateUnsafe(targetLength);
346351
if (len > padLen) {
347352
let count = (len - 1) / padLen;
348-
let base = count * padLen;
349-
let rest = len - base;
353+
let base = count * padLen;
354+
let rest = len - base;
350355
repeatUnsafe(out, 0, padString, count);
351356
if (rest) copyUnsafe(out, base, padString, 0, rest);
352357
} else {
@@ -394,9 +399,9 @@ export class String {
394399
}
395400

396401
slice(beginIndex: i32, endIndex: i32 = i32.MAX_VALUE): String {
397-
var len = this.length;
402+
var len = this.length;
398403
var begin = beginIndex < 0 ? max(beginIndex + len, 0) : min(beginIndex, len);
399-
var end = endIndex < 0 ? max(endIndex + len, 0) : min(endIndex, len);
404+
var end = endIndex < 0 ? max(endIndex + len, 0) : min(endIndex, len);
400405
len = end - begin;
401406
if (len <= 0) return changetype<String>("");
402407
var out = allocateUnsafe(len);
@@ -512,7 +517,7 @@ export class String {
512517
cp = (
513518
(cp & 7) << 18 |
514519
(load<u8>(ptr + ptrPos++) & 63) << 12 |
515-
(load<u8>(ptr + ptrPos++) & 63) << 6 |
520+
(load<u8>(ptr + ptrPos++) & 63) << 6 |
516521
load<u8>(ptr + ptrPos++) & 63
517522
) - 0x10000;
518523
store<u16>(buf + bufPos, 0xD800 + (cp >> 10));
@@ -523,7 +528,7 @@ export class String {
523528
assert(ptrPos + 2 <= len);
524529
store<u16>(buf + bufPos,
525530
(cp & 15) << 12 |
526-
(load<u8>(ptr + ptrPos++) & 63) << 6 |
531+
(load<u8>(ptr + ptrPos++) & 63) << 6 |
527532
load<u8>(ptr + ptrPos++) & 63
528533
);
529534
bufPos += 2;
@@ -548,8 +553,8 @@ export class String {
548553
++off; ++pos;
549554
} else if (c1 < 2048) {
550555
let ptr = buf + off;
551-
store<u8>(ptr, c1 >> 6 | 192);
552-
store<u8>(ptr, c1 & 63 | 128, 1);
556+
store<u8>(ptr, c1 >> 6 | 192);
557+
store<u8>(ptr, c1 & 63 | 128, 1);
553558
off += 2; ++pos;
554559
} else {
555560
let ptr = buf + off;
@@ -559,15 +564,15 @@ export class String {
559564
c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);
560565
store<u8>(ptr, c1 >> 18 | 240);
561566
store<u8>(ptr, c1 >> 12 & 63 | 128, 1);
562-
store<u8>(ptr, c1 >> 6 & 63 | 128, 2);
567+
store<u8>(ptr, c1 >> 6 & 63 | 128, 2);
563568
store<u8>(ptr, c1 & 63 | 128, 3);
564569
off += 4; pos += 2;
565570
continue;
566571
}
567572
}
568-
store<u8>(ptr, c1 >> 12 | 224);
569-
store<u8>(ptr, c1 >> 6 & 63 | 128, 1);
570-
store<u8>(ptr, c1 & 63 | 128, 2);
573+
store<u8>(ptr, c1 >> 12 | 224);
574+
store<u8>(ptr, c1 >> 6 & 63 | 128, 1);
575+
store<u8>(ptr, c1 & 63 | 128, 2);
571576
off += 3; ++pos;
572577
}
573578
}

tests/compiler/number.optimized.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2348,7 +2348,7 @@
23482348
if
23492349
i32.const 0
23502350
i32.const 2072
2351-
i32.const 249
2351+
i32.const 254
23522352
i32.const 4
23532353
call $~lib/env/abort
23542354
unreachable

tests/compiler/number.untouched.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3525,7 +3525,7 @@
35253525
if
35263526
i32.const 0
35273527
i32.const 2072
3528-
i32.const 249
3528+
i32.const 254
35293529
i32.const 4
35303530
call $~lib/env/abort
35313531
unreachable

tests/compiler/std/array-access.optimized.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
if
116116
i32.const 0
117117
i32.const 16
118-
i32.const 224
118+
i32.const 229
119119
i32.const 4
120120
call $~lib/env/abort
121121
unreachable

tests/compiler/std/array-access.untouched.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@
199199
if
200200
i32.const 0
201201
i32.const 16
202-
i32.const 224
202+
i32.const 229
203203
i32.const 4
204204
call $~lib/env/abort
205205
unreachable

tests/compiler/std/array.optimized.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6238,7 +6238,7 @@
62386238
if
62396239
i32.const 0
62406240
i32.const 4056
6241-
i32.const 249
6241+
i32.const 254
62426242
i32.const 4
62436243
call $~lib/env/abort
62446244
unreachable

tests/compiler/std/array.untouched.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11617,7 +11617,7 @@
1161711617
if
1161811618
i32.const 0
1161911619
i32.const 4056
11620-
i32.const 249
11620+
i32.const 254
1162111621
i32.const 4
1162211622
call $~lib/env/abort
1162311623
unreachable

tests/compiler/std/string-utf8.optimized.wat

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,7 +1525,7 @@
15251525
if
15261526
i32.const 0
15271527
i32.const 72
1528-
i32.const 507
1528+
i32.const 512
15291529
i32.const 8
15301530
call $~lib/env/abort
15311531
unreachable
@@ -1572,7 +1572,7 @@
15721572
if
15731573
i32.const 0
15741574
i32.const 72
1575-
i32.const 511
1575+
i32.const 516
15761576
i32.const 8
15771577
call $~lib/env/abort
15781578
unreachable
@@ -1651,7 +1651,7 @@
16511651
if
16521652
i32.const 0
16531653
i32.const 72
1654-
i32.const 523
1654+
i32.const 528
16551655
i32.const 8
16561656
call $~lib/env/abort
16571657
unreachable
@@ -1706,7 +1706,7 @@
17061706
if
17071707
i32.const 0
17081708
i32.const 72
1709-
i32.const 532
1709+
i32.const 537
17101710
i32.const 4
17111711
call $~lib/env/abort
17121712
unreachable

tests/compiler/std/string-utf8.untouched.wat

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,7 +2008,7 @@
20082008
if
20092009
i32.const 0
20102010
i32.const 72
2011-
i32.const 507
2011+
i32.const 512
20122012
i32.const 8
20132013
call $~lib/env/abort
20142014
unreachable
@@ -2062,7 +2062,7 @@
20622062
if
20632063
i32.const 0
20642064
i32.const 72
2065-
i32.const 511
2065+
i32.const 516
20662066
i32.const 8
20672067
call $~lib/env/abort
20682068
unreachable
@@ -2157,7 +2157,7 @@
21572157
if
21582158
i32.const 0
21592159
i32.const 72
2160-
i32.const 523
2160+
i32.const 528
21612161
i32.const 8
21622162
call $~lib/env/abort
21632163
unreachable
@@ -2220,7 +2220,7 @@
22202220
if
22212221
i32.const 0
22222222
i32.const 72
2223-
i32.const 532
2223+
i32.const 537
22242224
i32.const 4
22252225
call $~lib/env/abort
22262226
unreachable

0 commit comments

Comments
 (0)