mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-09 21:11:27 +00:00
Fix some cases in string comparision (#66)
This commit is contained in:
parent
26601dcfb1
commit
70a0123554
@ -63,9 +63,7 @@ export class String {
|
|||||||
changetype<usize>(this) + ((<usize>pos + 1) << 1),
|
changetype<usize>(this) + ((<usize>pos + 1) << 1),
|
||||||
HEADER_SIZE
|
HEADER_SIZE
|
||||||
);
|
);
|
||||||
if (second < 0xDC00 || second > 0xDFFF) {
|
if (second < 0xDC00 || second > 0xDFFF) return first;
|
||||||
return first;
|
|
||||||
}
|
|
||||||
return ((first - 0xD800) << 10) + (second - 0xDC00) + 0x10000;
|
return ((first - 0xD800) << 10) + (second - 0xDC00) + 0x10000;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,16 +81,19 @@ export class String {
|
|||||||
var outLen: usize = thisLen + otherLen;
|
var outLen: usize = thisLen + otherLen;
|
||||||
if (outLen == 0) return EMPTY;
|
if (outLen == 0) return EMPTY;
|
||||||
var out = allocate(outLen);
|
var out = allocate(outLen);
|
||||||
|
|
||||||
move_memory(
|
move_memory(
|
||||||
changetype<usize>(out) + HEADER_SIZE,
|
changetype<usize>(out) + HEADER_SIZE,
|
||||||
changetype<usize>(this) + HEADER_SIZE,
|
changetype<usize>(this) + HEADER_SIZE,
|
||||||
thisLen << 1
|
thisLen << 1
|
||||||
);
|
);
|
||||||
|
|
||||||
move_memory(
|
move_memory(
|
||||||
changetype<usize>(out) + HEADER_SIZE + (thisLen << 1),
|
changetype<usize>(out) + HEADER_SIZE + (thisLen << 1),
|
||||||
changetype<usize>(other) + HEADER_SIZE,
|
changetype<usize>(other) + HEADER_SIZE,
|
||||||
otherLen << 1
|
otherLen << 1
|
||||||
);
|
);
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,9 +103,7 @@ export class String {
|
|||||||
var end: isize = <isize>min(max(endPosition, 0), this.length);
|
var end: isize = <isize>min(max(endPosition, 0), this.length);
|
||||||
var searchLength: isize = searchString.length;
|
var searchLength: isize = searchString.length;
|
||||||
var start: isize = end - searchLength;
|
var start: isize = end - searchLength;
|
||||||
if (start < 0) {
|
if (start < 0) return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return !compare_memory(
|
return !compare_memory(
|
||||||
changetype<usize>(this) + HEADER_SIZE + (start << 1),
|
changetype<usize>(this) + HEADER_SIZE + (start << 1),
|
||||||
changetype<usize>(searchString) + HEADER_SIZE,
|
changetype<usize>(searchString) + HEADER_SIZE,
|
||||||
@ -116,8 +115,10 @@ export class String {
|
|||||||
private static __eq(left: String, right: String): bool {
|
private static __eq(left: String, right: String): bool {
|
||||||
if (left === null) return right === null;
|
if (left === null) return right === null;
|
||||||
else if (right === null) return false;
|
else if (right === null) return false;
|
||||||
|
|
||||||
var leftLength = left.length;
|
var leftLength = left.length;
|
||||||
if (leftLength != right.length) return false;
|
if (leftLength != right.length) return false;
|
||||||
|
|
||||||
return !compare_memory(
|
return !compare_memory(
|
||||||
changetype<usize>(left) + HEADER_SIZE,
|
changetype<usize>(left) + HEADER_SIZE,
|
||||||
changetype<usize>(right) + HEADER_SIZE,
|
changetype<usize>(right) + HEADER_SIZE,
|
||||||
@ -132,9 +133,7 @@ export class String {
|
|||||||
|
|
||||||
@operator(">")
|
@operator(">")
|
||||||
private static __gt(left: String, right: String): bool {
|
private static __gt(left: String, right: String): bool {
|
||||||
if (!changetype<usize>(left) || !changetype<usize>(right)) {
|
if (left === null || right === null) return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var leftLength = left.length;
|
var leftLength = left.length;
|
||||||
var rightLength = right.length;
|
var rightLength = right.length;
|
||||||
@ -152,9 +151,8 @@ export class String {
|
|||||||
|
|
||||||
@operator(">=")
|
@operator(">=")
|
||||||
private static __gte(left: String, right: String): bool {
|
private static __gte(left: String, right: String): bool {
|
||||||
if (!changetype<usize>(left) || !changetype<usize>(right)) {
|
if (left === null) return right === null;
|
||||||
return false;
|
else if (right === null) return false;
|
||||||
}
|
|
||||||
|
|
||||||
var leftLength = left.length;
|
var leftLength = left.length;
|
||||||
var rightLength = right.length;
|
var rightLength = right.length;
|
||||||
@ -172,9 +170,7 @@ export class String {
|
|||||||
|
|
||||||
@operator("<")
|
@operator("<")
|
||||||
private static __lt(left: String, right: String): bool {
|
private static __lt(left: String, right: String): bool {
|
||||||
if (!changetype<usize>(left) || !changetype<usize>(right)) {
|
if (left === null || right === null) return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var leftLength = left.length;
|
var leftLength = left.length;
|
||||||
var rightLength = right.length;
|
var rightLength = right.length;
|
||||||
@ -192,9 +188,8 @@ export class String {
|
|||||||
|
|
||||||
@operator("<=")
|
@operator("<=")
|
||||||
private static __lte(left: String, right: String): bool {
|
private static __lte(left: String, right: String): bool {
|
||||||
if (!changetype<usize>(left) || !changetype<usize>(right)) {
|
if (left === null) return right === null;
|
||||||
return false;
|
else if (right === null) return false;
|
||||||
}
|
|
||||||
|
|
||||||
var leftLength = left.length;
|
var leftLength = left.length;
|
||||||
var rightLength = right.length;
|
var rightLength = right.length;
|
||||||
|
@ -125,7 +125,7 @@
|
|||||||
(call $abort
|
(call $abort
|
||||||
(i32.const 0)
|
(i32.const 0)
|
||||||
(i32.const 8)
|
(i32.const 8)
|
||||||
(i32.const 239)
|
(i32.const 234)
|
||||||
(i32.const 4)
|
(i32.const 4)
|
||||||
)
|
)
|
||||||
(unreachable)
|
(unreachable)
|
||||||
|
@ -195,7 +195,7 @@
|
|||||||
(call $abort
|
(call $abort
|
||||||
(i32.const 0)
|
(i32.const 0)
|
||||||
(i32.const 8)
|
(i32.const 8)
|
||||||
(i32.const 239)
|
(i32.const 234)
|
||||||
(i32.const 4)
|
(i32.const 4)
|
||||||
)
|
)
|
||||||
(unreachable)
|
(unreachable)
|
||||||
|
@ -154,7 +154,7 @@
|
|||||||
(call $abort
|
(call $abort
|
||||||
(i32.const 0)
|
(i32.const 0)
|
||||||
(i32.const 72)
|
(i32.const 72)
|
||||||
(i32.const 239)
|
(i32.const 234)
|
||||||
(i32.const 4)
|
(i32.const 4)
|
||||||
)
|
)
|
||||||
(unreachable)
|
(unreachable)
|
||||||
@ -264,7 +264,7 @@
|
|||||||
(call $abort
|
(call $abort
|
||||||
(i32.const 0)
|
(i32.const 0)
|
||||||
(i32.const 72)
|
(i32.const 72)
|
||||||
(i32.const 100)
|
(i32.const 101)
|
||||||
(i32.const 4)
|
(i32.const 4)
|
||||||
)
|
)
|
||||||
(unreachable)
|
(unreachable)
|
||||||
@ -374,7 +374,7 @@
|
|||||||
(call $abort
|
(call $abort
|
||||||
(i32.const 0)
|
(i32.const 0)
|
||||||
(i32.const 72)
|
(i32.const 72)
|
||||||
(i32.const 218)
|
(i32.const 213)
|
||||||
(i32.const 4)
|
(i32.const 4)
|
||||||
)
|
)
|
||||||
(unreachable)
|
(unreachable)
|
||||||
@ -1085,7 +1085,7 @@
|
|||||||
(call $abort
|
(call $abort
|
||||||
(i32.const 0)
|
(i32.const 0)
|
||||||
(i32.const 72)
|
(i32.const 72)
|
||||||
(i32.const 563)
|
(i32.const 558)
|
||||||
(i32.const 10)
|
(i32.const 10)
|
||||||
)
|
)
|
||||||
(unreachable)
|
(unreachable)
|
||||||
@ -3171,7 +3171,7 @@
|
|||||||
(call $abort
|
(call $abort
|
||||||
(i32.const 0)
|
(i32.const 0)
|
||||||
(i32.const 72)
|
(i32.const 72)
|
||||||
(i32.const 79)
|
(i32.const 77)
|
||||||
(i32.const 4)
|
(i32.const 4)
|
||||||
)
|
)
|
||||||
(unreachable)
|
(unreachable)
|
||||||
@ -3394,32 +3394,29 @@
|
|||||||
(local $2 i32)
|
(local $2 i32)
|
||||||
(local $3 i32)
|
(local $3 i32)
|
||||||
(if
|
(if
|
||||||
(i32.and
|
(get_local $0)
|
||||||
(if (result i32)
|
(if
|
||||||
(tee_local $2
|
(i32.eqz
|
||||||
(i32.eqz
|
(get_local $1)
|
||||||
(get_local $0)
|
)
|
||||||
)
|
(return
|
||||||
)
|
(i32.const 0)
|
||||||
(get_local $2)
|
|
||||||
(i32.eqz
|
|
||||||
(get_local $1)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
(i32.const 1)
|
|
||||||
)
|
)
|
||||||
(return
|
(return
|
||||||
(i32.const 0)
|
(i32.eqz
|
||||||
|
(get_local $1)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(set_local $3
|
(set_local $2
|
||||||
(i32.load
|
(i32.load
|
||||||
(get_local $1)
|
(get_local $1)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(if
|
(if
|
||||||
(i32.eqz
|
(i32.eqz
|
||||||
(tee_local $2
|
(tee_local $3
|
||||||
(i32.load
|
(i32.load
|
||||||
(get_local $0)
|
(get_local $0)
|
||||||
)
|
)
|
||||||
@ -3427,13 +3424,13 @@
|
|||||||
)
|
)
|
||||||
(return
|
(return
|
||||||
(i32.eqz
|
(i32.eqz
|
||||||
(get_local $3)
|
(get_local $2)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(if
|
(if
|
||||||
(i32.eqz
|
(i32.eqz
|
||||||
(get_local $3)
|
(get_local $2)
|
||||||
)
|
)
|
||||||
(return
|
(return
|
||||||
(i32.const 1)
|
(i32.const 1)
|
||||||
@ -3451,11 +3448,11 @@
|
|||||||
)
|
)
|
||||||
(i32.shl
|
(i32.shl
|
||||||
(select
|
(select
|
||||||
(get_local $2)
|
|
||||||
(get_local $3)
|
(get_local $3)
|
||||||
|
(get_local $2)
|
||||||
(i32.lt_s
|
(i32.lt_s
|
||||||
(get_local $2)
|
|
||||||
(get_local $3)
|
(get_local $3)
|
||||||
|
(get_local $2)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(i32.const 1)
|
(i32.const 1)
|
||||||
@ -3540,22 +3537,19 @@
|
|||||||
(local $2 i32)
|
(local $2 i32)
|
||||||
(local $3 i32)
|
(local $3 i32)
|
||||||
(if
|
(if
|
||||||
(i32.and
|
(get_local $0)
|
||||||
(if (result i32)
|
(if
|
||||||
(tee_local $2
|
(i32.eqz
|
||||||
(i32.eqz
|
(get_local $1)
|
||||||
(get_local $0)
|
)
|
||||||
)
|
(return
|
||||||
)
|
(i32.const 0)
|
||||||
(get_local $2)
|
|
||||||
(i32.eqz
|
|
||||||
(get_local $1)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
(i32.const 1)
|
|
||||||
)
|
)
|
||||||
(return
|
(return
|
||||||
(i32.const 0)
|
(i32.eqz
|
||||||
|
(get_local $1)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(set_local $2
|
(set_local $2
|
||||||
|
@ -203,7 +203,7 @@
|
|||||||
(call $abort
|
(call $abort
|
||||||
(i32.const 0)
|
(i32.const 0)
|
||||||
(i32.const 72)
|
(i32.const 72)
|
||||||
(i32.const 239)
|
(i32.const 234)
|
||||||
(i32.const 4)
|
(i32.const 4)
|
||||||
)
|
)
|
||||||
(unreachable)
|
(unreachable)
|
||||||
@ -333,7 +333,7 @@
|
|||||||
(call $abort
|
(call $abort
|
||||||
(i32.const 0)
|
(i32.const 0)
|
||||||
(i32.const 72)
|
(i32.const 72)
|
||||||
(i32.const 100)
|
(i32.const 101)
|
||||||
(i32.const 4)
|
(i32.const 4)
|
||||||
)
|
)
|
||||||
(unreachable)
|
(unreachable)
|
||||||
@ -461,7 +461,7 @@
|
|||||||
(call $abort
|
(call $abort
|
||||||
(i32.const 0)
|
(i32.const 0)
|
||||||
(i32.const 72)
|
(i32.const 72)
|
||||||
(i32.const 218)
|
(i32.const 213)
|
||||||
(i32.const 4)
|
(i32.const 4)
|
||||||
)
|
)
|
||||||
(unreachable)
|
(unreachable)
|
||||||
@ -1263,7 +1263,7 @@
|
|||||||
(call $abort
|
(call $abort
|
||||||
(i32.const 0)
|
(i32.const 0)
|
||||||
(i32.const 72)
|
(i32.const 72)
|
||||||
(i32.const 563)
|
(i32.const 558)
|
||||||
(i32.const 10)
|
(i32.const 10)
|
||||||
)
|
)
|
||||||
(unreachable)
|
(unreachable)
|
||||||
@ -3649,7 +3649,7 @@
|
|||||||
(call $abort
|
(call $abort
|
||||||
(i32.const 0)
|
(i32.const 0)
|
||||||
(i32.const 72)
|
(i32.const 72)
|
||||||
(i32.const 79)
|
(i32.const 77)
|
||||||
(i32.const 4)
|
(i32.const 4)
|
||||||
)
|
)
|
||||||
(unreachable)
|
(unreachable)
|
||||||
@ -3826,13 +3826,15 @@
|
|||||||
(i32.and
|
(i32.and
|
||||||
(if (result i32)
|
(if (result i32)
|
||||||
(tee_local $2
|
(tee_local $2
|
||||||
(i32.eqz
|
(i32.eq
|
||||||
(get_local $0)
|
(get_local $0)
|
||||||
|
(i32.const 0)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(get_local $2)
|
(get_local $2)
|
||||||
(i32.eqz
|
(i32.eq
|
||||||
(get_local $1)
|
(get_local $1)
|
||||||
|
(i32.const 0)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(i32.const 1)
|
(i32.const 1)
|
||||||
@ -3908,62 +3910,64 @@
|
|||||||
(local $5 i32)
|
(local $5 i32)
|
||||||
(local $6 i32)
|
(local $6 i32)
|
||||||
(if
|
(if
|
||||||
(i32.and
|
(i32.eq
|
||||||
(if (result i32)
|
(get_local $0)
|
||||||
(tee_local $2
|
|
||||||
(i32.eqz
|
|
||||||
(get_local $0)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
(get_local $2)
|
|
||||||
(i32.eqz
|
|
||||||
(get_local $1)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
(i32.const 1)
|
|
||||||
)
|
|
||||||
(return
|
|
||||||
(i32.const 0)
|
(i32.const 0)
|
||||||
)
|
)
|
||||||
|
(return
|
||||||
|
(i32.eq
|
||||||
|
(get_local $1)
|
||||||
|
(i32.const 0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(if
|
||||||
|
(i32.eq
|
||||||
|
(get_local $1)
|
||||||
|
(i32.const 0)
|
||||||
|
)
|
||||||
|
(return
|
||||||
|
(i32.const 0)
|
||||||
|
)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
(set_local $3
|
(set_local $2
|
||||||
(i32.load
|
(i32.load
|
||||||
(get_local $0)
|
(get_local $0)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(set_local $4
|
(set_local $3
|
||||||
(i32.load
|
(i32.load
|
||||||
(get_local $1)
|
(get_local $1)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
(if
|
||||||
|
(i32.eqz
|
||||||
|
(get_local $2)
|
||||||
|
)
|
||||||
|
(return
|
||||||
|
(i32.eqz
|
||||||
|
(get_local $3)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
(if
|
(if
|
||||||
(i32.eqz
|
(i32.eqz
|
||||||
(get_local $3)
|
(get_local $3)
|
||||||
)
|
)
|
||||||
(return
|
|
||||||
(i32.eqz
|
|
||||||
(get_local $4)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
(if
|
|
||||||
(i32.eqz
|
|
||||||
(get_local $4)
|
|
||||||
)
|
|
||||||
(return
|
(return
|
||||||
(i32.const 1)
|
(i32.const 1)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(set_local $6
|
(set_local $6
|
||||||
(select
|
(select
|
||||||
(tee_local $2
|
(tee_local $4
|
||||||
(get_local $3)
|
(get_local $2)
|
||||||
)
|
)
|
||||||
(tee_local $5
|
(tee_local $5
|
||||||
(get_local $4)
|
(get_local $3)
|
||||||
)
|
)
|
||||||
(i32.lt_s
|
(i32.lt_s
|
||||||
(get_local $2)
|
(get_local $4)
|
||||||
(get_local $5)
|
(get_local $5)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -3998,13 +4002,15 @@
|
|||||||
(i32.and
|
(i32.and
|
||||||
(if (result i32)
|
(if (result i32)
|
||||||
(tee_local $2
|
(tee_local $2
|
||||||
(i32.eqz
|
(i32.eq
|
||||||
(get_local $0)
|
(get_local $0)
|
||||||
|
(i32.const 0)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(get_local $2)
|
(get_local $2)
|
||||||
(i32.eqz
|
(i32.eq
|
||||||
(get_local $1)
|
(get_local $1)
|
||||||
|
(i32.const 0)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(i32.const 1)
|
(i32.const 1)
|
||||||
@ -4080,62 +4086,64 @@
|
|||||||
(local $5 i32)
|
(local $5 i32)
|
||||||
(local $6 i32)
|
(local $6 i32)
|
||||||
(if
|
(if
|
||||||
(i32.and
|
(i32.eq
|
||||||
(if (result i32)
|
(get_local $0)
|
||||||
(tee_local $2
|
|
||||||
(i32.eqz
|
|
||||||
(get_local $0)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
(get_local $2)
|
|
||||||
(i32.eqz
|
|
||||||
(get_local $1)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
(i32.const 1)
|
|
||||||
)
|
|
||||||
(return
|
|
||||||
(i32.const 0)
|
(i32.const 0)
|
||||||
)
|
)
|
||||||
|
(return
|
||||||
|
(i32.eq
|
||||||
|
(get_local $1)
|
||||||
|
(i32.const 0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(if
|
||||||
|
(i32.eq
|
||||||
|
(get_local $1)
|
||||||
|
(i32.const 0)
|
||||||
|
)
|
||||||
|
(return
|
||||||
|
(i32.const 0)
|
||||||
|
)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
(set_local $3
|
(set_local $2
|
||||||
(i32.load
|
(i32.load
|
||||||
(get_local $0)
|
(get_local $0)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(set_local $4
|
(set_local $3
|
||||||
(i32.load
|
(i32.load
|
||||||
(get_local $1)
|
(get_local $1)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(if
|
|
||||||
(i32.eqz
|
|
||||||
(get_local $4)
|
|
||||||
)
|
|
||||||
(return
|
|
||||||
(i32.eqz
|
|
||||||
(get_local $3)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
(if
|
(if
|
||||||
(i32.eqz
|
(i32.eqz
|
||||||
(get_local $3)
|
(get_local $3)
|
||||||
)
|
)
|
||||||
|
(return
|
||||||
|
(i32.eqz
|
||||||
|
(get_local $2)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(if
|
||||||
|
(i32.eqz
|
||||||
|
(get_local $2)
|
||||||
|
)
|
||||||
(return
|
(return
|
||||||
(i32.const 1)
|
(i32.const 1)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(set_local $6
|
(set_local $6
|
||||||
(select
|
(select
|
||||||
(tee_local $2
|
(tee_local $4
|
||||||
(get_local $3)
|
(get_local $2)
|
||||||
)
|
)
|
||||||
(tee_local $5
|
(tee_local $5
|
||||||
(get_local $4)
|
(get_local $3)
|
||||||
)
|
)
|
||||||
(i32.lt_s
|
(i32.lt_s
|
||||||
(get_local $2)
|
(get_local $4)
|
||||||
(get_local $5)
|
(get_local $5)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user