parseInt compatibility layer around parseI64, see #19

This commit is contained in:
dcodeIO
2018-01-30 01:26:38 +01:00
parent cae89e0b1f
commit ab5a938ea0
9 changed files with 282 additions and 41 deletions

View File

@ -4077,6 +4077,8 @@
ENUM: std:string/CharCode
FUNCTION_PROTOTYPE: std:string/parseInt
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: std:string/parseI64
FUNCTION_PROTOTYPE: parseI64
FUNCTION_PROTOTYPE: std:string/parseFloat
FUNCTION_PROTOTYPE: parseFloat
GLOBAL: std/array/arr
@ -4116,6 +4118,8 @@
CLASS_PROTOTYPE: String
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: std:string/parseInt
FUNCTION_PROTOTYPE: parseI64
FUNCTION_PROTOTYPE: std:string/parseI64
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: std:string/parseFloat
FUNCTION_PROTOTYPE: allocate_memory

View File

@ -284,6 +284,8 @@
ENUM: std:string/CharCode
FUNCTION_PROTOTYPE: std:string/parseInt
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: std:string/parseI64
FUNCTION_PROTOTYPE: parseI64
FUNCTION_PROTOTYPE: std:string/parseFloat
FUNCTION_PROTOTYPE: parseFloat
GLOBAL: std/carray/arr
@ -312,6 +314,8 @@
CLASS_PROTOTYPE: String
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: std:string/parseInt
FUNCTION_PROTOTYPE: parseI64
FUNCTION_PROTOTYPE: std:string/parseI64
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: std:string/parseFloat
;)

View File

@ -2893,6 +2893,8 @@
ENUM: std:string/CharCode
FUNCTION_PROTOTYPE: std:string/parseInt
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: std:string/parseI64
FUNCTION_PROTOTYPE: parseI64
FUNCTION_PROTOTYPE: std:string/parseFloat
FUNCTION_PROTOTYPE: parseFloat
GLOBAL: std/heap/size
@ -2934,6 +2936,8 @@
CLASS_PROTOTYPE: String
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: std:string/parseInt
FUNCTION_PROTOTYPE: parseI64
FUNCTION_PROTOTYPE: std:string/parseI64
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: std:string/parseFloat
FUNCTION_PROTOTYPE: allocate_memory

View File

@ -234,6 +234,8 @@
ENUM: std:string/CharCode
FUNCTION_PROTOTYPE: std:string/parseInt
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: std:string/parseI64
FUNCTION_PROTOTYPE: parseI64
FUNCTION_PROTOTYPE: std:string/parseFloat
FUNCTION_PROTOTYPE: parseFloat
CLASS_PROTOTYPE: std/new/AClass
@ -274,6 +276,8 @@
CLASS_PROTOTYPE: String
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: std:string/parseInt
FUNCTION_PROTOTYPE: parseI64
FUNCTION_PROTOTYPE: std:string/parseI64
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: std:string/parseFloat
FUNCTION_PROTOTYPE: allocate_memory

View File

@ -2802,6 +2802,8 @@
ENUM: std:string/CharCode
FUNCTION_PROTOTYPE: std:string/parseInt
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: std:string/parseI64
FUNCTION_PROTOTYPE: parseI64
FUNCTION_PROTOTYPE: std:string/parseFloat
FUNCTION_PROTOTYPE: parseFloat
GLOBAL: std/set/set
@ -2840,6 +2842,8 @@
CLASS_PROTOTYPE: String
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: std:string/parseInt
FUNCTION_PROTOTYPE: parseI64
FUNCTION_PROTOTYPE: std:string/parseI64
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: std:string/parseFloat
FUNCTION_PROTOTYPE: allocate_memory

View File

@ -3,6 +3,7 @@
(type $iii (func (param i32 i32) (result i32)))
(type $iiii (func (param i32 i32 i32) (result i32)))
(type $iiI (func (param i32 i32) (result i64)))
(type $iiF (func (param i32 i32) (result f64)))
(type $iF (func (param i32) (result f64)))
(type $v (func))
(global $std/string/str (mut i32) (i32.const 8))
@ -374,7 +375,7 @@
(func $std/string/getString (; 5 ;) (type $i) (result i32)
(get_global $std/string/str)
)
(func $std:string/parseInt (; 6 ;) (type $iiI) (param $0 i32) (param $1 i32) (result i64)
(func $std:string/parseI64 (; 6 ;) (type $iiI) (param $0 i32) (param $1 i32) (result i64)
(local $2 i32)
(local $3 i32)
(local $4 i64)
@ -741,7 +742,93 @@
(get_local $4)
)
)
(func $std:string/parseFloat (; 7 ;) (type $iF) (param $0 i32) (result f64)
(func $std:string/parseInt (; 7 ;) (type $iiF) (param $0 i32) (param $1 i32) (result f64)
(local $2 i32)
(local $3 i32)
(if
(i32.eqz
(tee_local $2
(i32.load
(get_local $0)
)
)
)
(return
(f64.const nan:0x8000000000000)
)
)
(if
(i32.eq
(tee_local $3
(i32.load16_u offset=4
(get_local $0)
)
)
(i32.const 45)
)
(if
(i32.eqz
(i32.sub
(get_local $2)
(i32.const 1)
)
)
(return
(f64.const nan:0x8000000000000)
)
)
(if
(i32.eq
(get_local $3)
(i32.const 43)
)
(if
(i32.eqz
(i32.sub
(get_local $2)
(i32.const 1)
)
)
(return
(f64.const nan:0x8000000000000)
)
)
)
)
(if
(select
(i32.and
(select
(i32.lt_s
(get_local $1)
(i32.const 2)
)
(i32.gt_s
(get_local $1)
(i32.const 36)
)
(i32.lt_s
(get_local $1)
(i32.const 2)
)
)
(i32.const 1)
)
(get_local $1)
(get_local $1)
)
(return
(f64.const nan:0x8000000000000)
)
)
(f64.convert_s/i64
(call $std:string/parseI64
(get_local $0)
(get_local $1)
)
)
)
(func $std:string/parseFloat (; 8 ;) (type $iF) (param $0 i32) (result f64)
(local $1 i32)
(local $2 i32)
(local $3 f64)
@ -985,7 +1072,7 @@
(get_local $3)
)
)
(func $start (; 8 ;) (type $v)
(func $start (; 9 ;) (type $v)
(if
(i32.ne
(get_global $std/string/str)
@ -1068,82 +1155,82 @@
(unreachable)
)
(if
(i64.ne
(f64.ne
(call $std:string/parseInt
(i32.const 120)
(i32.const 0)
)
(i64.const 0)
(f64.const 0)
)
(unreachable)
)
(if
(i64.ne
(f64.ne
(call $std:string/parseInt
(i32.const 128)
(i32.const 0)
)
(i64.const 1)
(f64.const 1)
)
(unreachable)
)
(if
(i64.ne
(f64.ne
(call $std:string/parseInt
(i32.const 136)
(i32.const 0)
)
(i64.const 5)
(f64.const 5)
)
(unreachable)
)
(if
(i64.ne
(f64.ne
(call $std:string/parseInt
(i32.const 152)
(i32.const 0)
)
(i64.const 455)
(f64.const 455)
)
(unreachable)
)
(if
(i64.ne
(f64.ne
(call $std:string/parseInt
(i32.const 168)
(i32.const 0)
)
(i64.const 3855)
(f64.const 3855)
)
(unreachable)
)
(if
(i64.ne
(f64.ne
(call $std:string/parseInt
(i32.const 184)
(i32.const 0)
)
(i64.const 3855)
(f64.const 3855)
)
(unreachable)
)
(if
(i64.ne
(f64.ne
(call $std:string/parseInt
(i32.const 200)
(i32.const 0)
)
(i64.const 11)
(f64.const 11)
)
(unreachable)
)
(if
(i64.ne
(f64.ne
(call $std:string/parseInt
(i32.const 216)
(i32.const 0)
)
(i64.const 1)
(f64.const 1)
)
(unreachable)
)

View File

@ -3,6 +3,7 @@
(type $iii (func (param i32 i32) (result i32)))
(type $iiii (func (param i32 i32 i32) (result i32)))
(type $iiI (func (param i32 i32) (result i64)))
(type $iiF (func (param i32 i32) (result f64)))
(type $iF (func (param i32) (result f64)))
(type $v (func))
(global $std/string/str (mut i32) (i32.const 8))
@ -499,7 +500,7 @@
(get_global $std/string/str)
)
)
(func $std:string/parseInt (; 7 ;) (type $iiI) (param $0 i32) (param $1 i32) (result i64)
(func $std:string/parseI64 (; 7 ;) (type $iiI) (param $0 i32) (param $1 i32) (result i64)
(local $2 i32)
(local $3 i32)
(local $4 i32)
@ -924,7 +925,111 @@
)
)
)
(func $std:string/parseFloat (; 8 ;) (type $iF) (param $0 i32) (result f64)
(func $std:string/parseInt (; 8 ;) (type $iiF) (param $0 i32) (param $1 i32) (result f64)
(local $2 i32)
(local $3 i32)
(local $4 i32)
(set_local $2
(i32.load
(get_local $0)
)
)
(if
(i32.eqz
(get_local $2)
)
(return
(f64.const nan:0x8000000000000)
)
)
(set_local $3
(get_local $0)
)
(set_local $4
(i32.load16_u offset=4
(get_local $3)
)
)
(if
(i32.eq
(get_local $4)
(i32.const 45)
)
(if
(i32.eqz
(tee_local $2
(i32.sub
(get_local $2)
(i32.const 1)
)
)
)
(return
(f64.const nan:0x8000000000000)
)
)
(if
(i32.eq
(get_local $4)
(i32.const 43)
)
(if
(i32.eqz
(tee_local $2
(i32.sub
(get_local $2)
(i32.const 1)
)
)
)
(return
(f64.const nan:0x8000000000000)
)
)
)
)
(if
(if (result i32)
(i32.ne
(get_local $1)
(i32.const 0)
)
(i32.and
(if (result i32)
(i32.ne
(i32.lt_s
(get_local $1)
(i32.const 2)
)
(i32.const 0)
)
(i32.lt_s
(get_local $1)
(i32.const 2)
)
(i32.gt_s
(get_local $1)
(i32.const 36)
)
)
(i32.const 1)
)
(get_local $1)
)
(return
(f64.const nan:0x8000000000000)
)
)
(return
(f64.convert_s/i64
(call $std:string/parseI64
(get_local $0)
(get_local $1)
)
)
)
)
(func $std:string/parseFloat (; 9 ;) (type $iF) (param $0 i32) (result f64)
(local $1 i32)
(local $2 i32)
(local $3 i32)
@ -1205,7 +1310,7 @@
)
)
)
(func $start (; 9 ;) (type $v)
(func $start (; 10 ;) (type $v)
(if
(i32.eqz
(i32.eq
@ -1299,96 +1404,96 @@
)
(if
(i32.eqz
(i64.eq
(f64.eq
(call $std:string/parseInt
(i32.const 120)
(i32.const 0)
)
(i64.const 0)
(f64.const 0)
)
)
(unreachable)
)
(if
(i32.eqz
(i64.eq
(f64.eq
(call $std:string/parseInt
(i32.const 128)
(i32.const 0)
)
(i64.const 1)
(f64.const 1)
)
)
(unreachable)
)
(if
(i32.eqz
(i64.eq
(f64.eq
(call $std:string/parseInt
(i32.const 136)
(i32.const 0)
)
(i64.const 5)
(f64.const 5)
)
)
(unreachable)
)
(if
(i32.eqz
(i64.eq
(f64.eq
(call $std:string/parseInt
(i32.const 152)
(i32.const 0)
)
(i64.const 455)
(f64.const 455)
)
)
(unreachable)
)
(if
(i32.eqz
(i64.eq
(f64.eq
(call $std:string/parseInt
(i32.const 168)
(i32.const 0)
)
(i64.const 3855)
(f64.const 3855)
)
)
(unreachable)
)
(if
(i32.eqz
(i64.eq
(f64.eq
(call $std:string/parseInt
(i32.const 184)
(i32.const 0)
)
(i64.const 3855)
(f64.const 3855)
)
)
(unreachable)
)
(if
(i32.eqz
(i64.eq
(f64.eq
(call $std:string/parseInt
(i32.const 200)
(i32.const 0)
)
(i64.const 11)
(f64.const 11)
)
)
(unreachable)
)
(if
(i32.eqz
(i64.eq
(f64.eq
(call $std:string/parseInt
(i32.const 216)
(i32.const 0)
)
(i64.const 1)
(f64.const 1)
)
)
(unreachable)
@ -1529,6 +1634,8 @@
ENUM: std:string/CharCode
FUNCTION_PROTOTYPE: std:string/parseInt
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: std:string/parseI64
FUNCTION_PROTOTYPE: parseI64
FUNCTION_PROTOTYPE: std:string/parseFloat
FUNCTION_PROTOTYPE: parseFloat
GLOBAL: std/string/str
@ -1558,6 +1665,8 @@
CLASS_PROTOTYPE: String
FUNCTION_PROTOTYPE: parseInt
FUNCTION_PROTOTYPE: std:string/parseInt
FUNCTION_PROTOTYPE: parseI64
FUNCTION_PROTOTYPE: std:string/parseI64
FUNCTION_PROTOTYPE: parseFloat
FUNCTION_PROTOTYPE: std:string/parseFloat
FUNCTION_PROTOTYPE: std/string/getString