Skip to content

Commit

Permalink
fix: Fix parseInt result for some mixed integers (#2193)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxGraey committed Apr 9, 2022
1 parent f79b82e commit a3dcd5d
Show file tree
Hide file tree
Showing 11 changed files with 78,021 additions and 3,724 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion std/assembly/util/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,7 @@ export function strtol<T>(str: string, radix: i32 = 0): T {
// calculate value
// @ts-ignore: type
var num: T = 0;
var initial = len - 1;
while (len--) {
code = <u32>load<u16>(ptr);
if (code - CharCode._0 < 10) {
Expand All @@ -748,7 +749,7 @@ export function strtol<T>(str: string, radix: i32 = 0): T {
code -= CharCode.a - 10;
}
if (code >= <u32>radix) {
if (!num) {
if (initial == len) {
if (isFloat<T>()) {
// @ts-ignore: cast
return <T>NaN;
Expand Down
10 changes: 8 additions & 2 deletions tests/compiler/std/date.debug.wat
Original file line number Diff line number Diff line change
Expand Up @@ -4021,6 +4021,7 @@
(local $5 i32)
(local $6 i32)
(local $7 i32)
(local $8 i32)
local.get $0
call $~lib/string/String#get:length
local.set $2
Expand Down Expand Up @@ -4228,6 +4229,10 @@
end
i32.const 0
local.set $7
local.get $2
i32.const 1
i32.sub
local.set $8
block $while-break|2
loop $while-continue|2
local.get $2
Expand Down Expand Up @@ -4289,8 +4294,9 @@
local.get $1
i32.ge_u
if
local.get $7
i32.eqz
local.get $8
local.get $2
i32.eq
if
i32.const 0
drop
Expand Down
9,789 changes: 9,789 additions & 0 deletions tests/compiler/std/date.optimized.wat

Large diffs are not rendered by default.

76 changes: 41 additions & 35 deletions tests/compiler/std/date.release.wat
Original file line number Diff line number Diff line change
Expand Up @@ -2828,20 +2828,21 @@
(local $3 i32)
(local $4 i32)
(local $5 i32)
(local $6 i32)
local.get $0
i32.const 20
i32.sub
i32.load offset=16
i32.const 1
i32.shr_u
local.tee $2
local.tee $1
i32.eqz
if
i32.const 0
return
end
local.get $0
local.tee $1
local.tee $2
i32.load16_u
local.set $0
loop $while-continue|0
Expand Down Expand Up @@ -2908,21 +2909,21 @@
i32.const 0
end
if
local.get $1
local.get $2
i32.const 2
i32.add
local.tee $1
local.tee $2
i32.load16_u
local.set $0
local.get $2
local.get $1
i32.const 1
i32.sub
local.set $2
local.set $1
br $while-continue|0
end
end
i32.const 1
local.set $5
local.set $4
local.get $0
i32.const 43
i32.eq
Expand All @@ -2931,10 +2932,10 @@
i32.eq
i32.or
if (result i32)
local.get $2
local.get $1
i32.const 1
i32.sub
local.tee $2
local.tee $1
i32.eqz
if
i32.const 0
Expand All @@ -2946,26 +2947,26 @@
i32.const 45
i32.eq
select
local.set $5
local.get $1
local.set $4
local.get $2
i32.const 2
i32.add
local.tee $1
local.tee $2
i32.load16_u
else
local.get $0
end
i32.const 48
i32.eq
local.get $2
local.get $1
i32.const 2
i32.gt_s
i32.and
if
block $break|1
block $case2|1
block $case1|1
local.get $1
local.get $2
i32.load16_u offset=2
i32.const 32
i32.or
Expand All @@ -2983,38 +2984,38 @@
br_if $case2|1
br $break|1
end
local.get $1
local.get $2
i32.const 4
i32.add
local.set $1
local.get $2
local.set $2
local.get $1
i32.const 2
i32.sub
local.set $2
local.set $1
i32.const 2
local.set $3
br $break|1
end
local.get $1
local.get $2
i32.const 4
i32.add
local.set $1
local.get $2
local.set $2
local.get $1
i32.const 2
i32.sub
local.set $2
local.set $1
i32.const 8
local.set $3
br $break|1
end
local.get $1
local.get $2
i32.const 4
i32.add
local.set $1
local.get $2
local.set $2
local.get $1
i32.const 2
i32.sub
local.set $2
local.set $1
i32.const 16
local.set $3
end
Expand All @@ -3024,16 +3025,20 @@
local.get $3
select
local.set $3
local.get $1
i32.const 1
i32.sub
local.set $6
loop $while-continue|2
block $while-break|2
local.get $2
local.get $1
local.tee $0
i32.const 1
i32.sub
local.set $2
local.set $1
local.get $0
if
local.get $1
local.get $2
i32.load16_u
local.tee $0
i32.const 48
Expand Down Expand Up @@ -3071,8 +3076,9 @@
local.get $3
i32.ge_u
if
local.get $4
i32.eqz
local.get $1
local.get $6
i32.eq
if
i32.const 0
return
Expand All @@ -3081,14 +3087,14 @@
end
local.get $0
local.get $3
local.get $4
local.get $5
i32.mul
i32.add
local.set $4
local.get $1
local.set $5
local.get $2
i32.const 2
i32.add
local.set $1
local.set $2
br $while-continue|2
end
end
Expand Down

0 comments on commit a3dcd5d

Please sign in to comment.