More std array

This commit is contained in:
dcodeIO
2018-01-14 21:17:43 +01:00
parent 827bb4afe8
commit 49d29fc9f2
13 changed files with 1149 additions and 313 deletions

View File

@ -5,6 +5,7 @@
(type $iv (func (param i32)))
(type $iiv (func (param i32 i32)))
(type $iii (func (param i32 i32) (result i32)))
(type $iiii (func (param i32 i32 i32) (result i32)))
(type $v (func))
(global $std:heap/HEAP_OFFSET (mut i32) (i32.const 0))
(global $std:heap/ALIGN_LOG2 i32 (i32.const 3))
@ -113,7 +114,14 @@
(get_local $4)
)
)
(func $std:heap/copy_memory (; 1 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(func $std:array/Array#get:length (; 1 ;) (type $ii) (param $0 i32) (result i32)
(return
(i32.load offset=8
(get_local $0)
)
)
)
(func $std:heap/copy_memory (; 2 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
@ -1913,7 +1921,7 @@
)
)
)
(func $std:heap/move_memory (; 2 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(func $std:heap/move_memory (; 3 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(local $3 i32)
(if
(i32.eq
@ -2237,9 +2245,9 @@
)
)
)
(func $std:heap/free_memory (; 3 ;) (type $iv) (param $0 i32)
(func $std:heap/free_memory (; 4 ;) (type $iv) (param $0 i32)
)
(func $std:array/Array#__grow (; 4 ;) (type $iiv) (param $0 i32) (param $1 i32)
(func $std:array/Array#__grow (; 5 ;) (type $iiv) (param $0 i32) (param $1 i32)
(local $2 i32)
(if
(i32.eqz
@ -2295,11 +2303,10 @@
(get_local $1)
)
)
(func $std:array/Array#push (; 5 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(func $std:array/Array#push (; 6 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(local $2 i32)
(local $3 i32)
(if
(i32.ge_u
(i32.eq
(i32.load offset=8
(get_local $0)
)
@ -2309,27 +2316,17 @@
)
(call $std:array/Array#__grow
(get_local $0)
(select
(tee_local $2
(i32.add
(i32.load offset=8
(get_local $0)
)
(i32.const 1)
(if (result i32)
(i32.load offset=4
(get_local $0)
)
(i32.shl
(i32.load offset=4
(get_local $0)
)
(i32.const 1)
)
(tee_local $3
(i32.shl
(i32.load offset=4
(get_local $0)
)
(i32.const 1)
)
)
(i32.gt_s
(get_local $2)
(get_local $3)
)
(i32.const 1)
)
)
)
@ -2365,7 +2362,7 @@
)
)
)
(func $std:array/Array#__get (; 6 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(func $std:array/Array#__get (; 7 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(if
(i32.ge_u
(get_local $1)
@ -2389,44 +2386,16 @@
)
)
)
(func $std:array/Array#pop (; 7 ;) (type $ii) (param $0 i32) (result i32)
(func $std:array/Array#pop (; 8 ;) (type $ii) (param $0 i32) (result i32)
(local $1 i32)
(if
(i32.and
(if (result i32)
(i32.ne
(tee_local $1
(i32.lt_s
(i32.load offset=8
(get_local $0)
)
(i32.const 1)
)
)
(i32.const 0)
)
(get_local $1)
(i32.gt_u
(i32.load offset=8
(get_local $0)
)
(i32.load offset=4
(get_local $0)
)
)
)
(i32.const 1)
)
(unreachable)
)
(i32.store offset=8
(get_local $0)
(i32.sub
(i32.lt_s
(i32.load offset=8
(get_local $0)
)
(i32.const 1)
)
(unreachable)
)
(return
(i32.load
@ -2435,8 +2404,20 @@
(get_local $0)
)
(i32.mul
(i32.load offset=8
(get_local $0)
(block (result i32)
(set_local $1
(i32.sub
(i32.load offset=8
(get_local $0)
)
(i32.const 1)
)
)
(i32.store offset=8
(get_local $0)
(get_local $1)
)
(get_local $1)
)
(i32.const 4)
)
@ -2444,12 +2425,11 @@
)
)
)
(func $std:array/Array#unshift (; 8 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(func $std:array/Array#unshift (; 9 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
(local $6 i32)
(block
(set_local $2
(i32.load offset=4
@ -2458,7 +2438,7 @@
)
)
(if
(i32.ge_u
(i32.eq
(i32.load offset=8
(get_local $0)
)
@ -2466,33 +2446,21 @@
)
(block
(block
(set_local $5
(select
(tee_local $3
(i32.add
(i32.load offset=8
(get_local $0)
)
(i32.const 1)
)
)
(tee_local $4
(i32.mul
(get_local $2)
(i32.const 2)
)
)
(i32.gt_s
(get_local $3)
(get_local $4)
(set_local $3
(if (result i32)
(get_local $2)
(i32.shl
(get_local $2)
(i32.const 1)
)
(i32.const 1)
)
)
)
(if
(i32.eqz
(i32.gt_s
(get_local $5)
(get_local $3)
(i32.load offset=4
(get_local $0)
)
@ -2501,10 +2469,10 @@
(unreachable)
)
(block
(set_local $6
(set_local $4
(call $std:heap/allocate_memory
(i32.mul
(get_local $5)
(get_local $3)
(i32.const 4)
)
)
@ -2517,7 +2485,7 @@
(block
(call $std:heap/move_memory
(i32.add
(get_local $6)
(get_local $4)
(i32.const 4)
)
(i32.load
@ -2537,11 +2505,11 @@
)
(i32.store
(get_local $0)
(get_local $6)
(get_local $4)
)
(i32.store offset=4
(get_local $0)
(get_local $5)
(get_local $3)
)
)
(call $std:heap/move_memory
@ -2568,7 +2536,7 @@
)
(return
(block (result i32)
(set_local $3
(set_local $5
(i32.add
(i32.load offset=8
(get_local $0)
@ -2578,13 +2546,13 @@
)
(i32.store offset=8
(get_local $0)
(get_local $3)
(get_local $5)
)
(get_local $3)
(get_local $5)
)
)
)
(func $std:heap/set_memory (; 9 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(func $std:heap/set_memory (; 10 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(local $3 i32)
(local $4 i32)
(local $5 i64)
@ -2945,39 +2913,19 @@
)
)
)
(func $std:array/Array#shift (; 10 ;) (type $ii) (param $0 i32) (result i32)
(func $std:array/Array#shift (; 11 ;) (type $ii) (param $0 i32) (result i32)
(local $1 i32)
(local $2 i32)
(if
(i32.and
(if (result i32)
(i32.ne
(tee_local $1
(i32.lt_s
(i32.load offset=8
(get_local $0)
)
(i32.const 1)
)
)
(i32.const 0)
)
(get_local $1)
(i32.gt_u
(i32.load offset=8
(get_local $0)
)
(i32.load offset=4
(get_local $0)
)
)
(i32.lt_s
(i32.load offset=8
(get_local $0)
)
(i32.const 1)
)
(unreachable)
)
(block
(set_local $2
(set_local $1
(i32.load
(i32.load
(get_local $0)
@ -3033,10 +2981,282 @@
)
)
(return
(get_local $2)
(get_local $1)
)
)
(func $start (; 11 ;) (type $v)
(func $std:array/Array#reverse (; 12 ;) (type $ii) (param $0 i32) (result i32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
(block $break|0
(block
(set_local $1
(i32.const 0)
)
(set_local $2
(i32.sub
(i32.load offset=8
(get_local $0)
)
(i32.const 1)
)
)
)
(loop $continue|0
(if
(i32.lt_u
(get_local $1)
(get_local $2)
)
(block
(block
(block
(set_local $3
(i32.load
(i32.add
(i32.load
(get_local $0)
)
(i32.mul
(get_local $1)
(i32.const 4)
)
)
)
)
)
(i32.store
(i32.add
(i32.load
(get_local $0)
)
(i32.mul
(get_local $1)
(i32.const 4)
)
)
(i32.load
(i32.add
(i32.load
(get_local $0)
)
(i32.mul
(get_local $2)
(i32.const 4)
)
)
)
)
(i32.store
(i32.add
(i32.load
(get_local $0)
)
(i32.mul
(get_local $2)
(i32.const 4)
)
)
(get_local $3)
)
)
(block
(set_local $1
(i32.add
(get_local $1)
(i32.const 1)
)
)
(set_local $2
(i32.sub
(get_local $2)
(i32.const 1)
)
)
)
(br $continue|0)
)
)
)
)
(return
(get_local $0)
)
)
(func $std:array/Array#indexOf (; 13 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(if
(i32.lt_s
(get_local $2)
(i32.const 0)
)
(set_local $2
(i32.add
(i32.load offset=8
(get_local $0)
)
(get_local $2)
)
)
)
(block $break|0
(loop $continue|0
(if
(i32.lt_u
(get_local $2)
(i32.load offset=8
(get_local $0)
)
)
(block
(block
(if
(i32.eq
(i32.load
(i32.add
(i32.load
(get_local $0)
)
(i32.mul
(get_local $2)
(i32.const 4)
)
)
)
(get_local $1)
)
(return
(get_local $2)
)
)
(set_local $2
(i32.add
(get_local $2)
(i32.const 1)
)
)
)
(br $continue|0)
)
)
)
)
(return
(i32.sub
(i32.const 0)
(i32.const 1)
)
)
)
(func $std:array/Array#splice (; 14 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(local $3 i32)
(local $4 i32)
(if
(i32.lt_s
(get_local $2)
(i32.const 1)
)
(return)
)
(if
(i32.lt_s
(get_local $1)
(i32.const 0)
)
(block
(set_local $1
(i32.add
(i32.load offset=8
(get_local $0)
)
(get_local $1)
)
)
(if
(i32.lt_s
(get_local $1)
(i32.const 0)
)
(set_local $1
(i32.const 0)
)
(if
(i32.ge_s
(get_local $1)
(i32.load offset=8
(get_local $0)
)
)
(return)
)
)
)
(if
(i32.ge_s
(get_local $1)
(i32.load offset=8
(get_local $0)
)
)
(return)
)
)
(set_local $2
(select
(tee_local $3
(get_local $2)
)
(tee_local $4
(i32.sub
(i32.load offset=8
(get_local $0)
)
(get_local $1)
)
)
(i32.lt_s
(get_local $3)
(get_local $4)
)
)
)
(call $std:heap/move_memory
(i32.add
(i32.load
(get_local $0)
)
(i32.mul
(get_local $1)
(i32.const 4)
)
)
(i32.add
(i32.load
(get_local $0)
)
(i32.mul
(i32.add
(get_local $1)
(get_local $2)
)
(i32.const 4)
)
)
(i32.mul
(get_local $2)
(i32.const 4)
)
)
(i32.store offset=8
(get_local $0)
(i32.sub
(i32.load offset=8
(get_local $0)
)
(get_local $2)
)
)
)
(func $start (; 15 ;) (type $v)
(set_global $std:heap/HEAP_OFFSET
(get_global $HEAP_BASE)
)
@ -3054,7 +3274,7 @@
(if
(i32.eqz
(i32.eq
(i32.load offset=8
(call $std:array/Array#get:length
(get_global $std/array/arr)
)
(i32.const 0)
@ -3094,7 +3314,7 @@
(if
(i32.eqz
(i32.eq
(i32.load offset=8
(call $std:array/Array#get:length
(get_global $std/array/arr)
)
(i32.const 1)
@ -3130,7 +3350,7 @@
(if
(i32.eqz
(i32.eq
(i32.load offset=8
(call $std:array/Array#get:length
(get_global $std/array/arr)
)
(i32.const 0)
@ -3158,7 +3378,7 @@
(if
(i32.eqz
(i32.eq
(i32.load offset=8
(call $std:array/Array#get:length
(get_global $std/array/arr)
)
(i32.const 1)
@ -3198,7 +3418,7 @@
(if
(i32.eqz
(i32.eq
(i32.load offset=8
(call $std:array/Array#get:length
(get_global $std/array/arr)
)
(i32.const 2)
@ -3250,7 +3470,7 @@
(if
(i32.eqz
(i32.eq
(i32.load offset=8
(call $std:array/Array#get:length
(get_global $std/array/arr)
)
(i32.const 3)
@ -3314,7 +3534,7 @@
(if
(i32.eqz
(i32.eq
(i32.load offset=8
(call $std:array/Array#get:length
(get_global $std/array/arr)
)
(i32.const 4)
@ -3390,7 +3610,7 @@
(if
(i32.eqz
(i32.eq
(i32.load offset=8
(call $std:array/Array#get:length
(get_global $std/array/arr)
)
(i32.const 5)
@ -3486,7 +3706,7 @@
(if
(i32.eqz
(i32.eq
(i32.load offset=8
(call $std:array/Array#get:length
(get_global $std/array/arr)
)
(i32.const 4)
@ -3570,7 +3790,7 @@
(if
(i32.eqz
(i32.eq
(i32.load offset=8
(call $std:array/Array#get:length
(get_global $std/array/arr)
)
(i32.const 3)
@ -3625,6 +3845,171 @@
)
(unreachable)
)
(drop
(call $std:array/Array#reverse
(get_global $std/array/arr)
)
)
(if
(i32.eqz
(i32.eq
(call $std:array/Array#get:length
(get_global $std/array/arr)
)
(i32.const 3)
)
)
(unreachable)
)
(if
(i32.eqz
(i32.eq
(i32.load offset=4
(get_global $std/array/arr)
)
(i32.const 8)
)
)
(unreachable)
)
(if
(i32.eqz
(i32.eq
(call $std:array/Array#__get
(get_global $std/array/arr)
(i32.const 0)
)
(i32.const 44)
)
)
(unreachable)
)
(if
(i32.eqz
(i32.eq
(call $std:array/Array#__get
(get_global $std/array/arr)
(i32.const 1)
)
(i32.const 43)
)
)
(unreachable)
)
(if
(i32.eqz
(i32.eq
(call $std:array/Array#__get
(get_global $std/array/arr)
(i32.const 2)
)
(i32.const 42)
)
)
(unreachable)
)
(set_global $std/array/i
(call $std:array/Array#indexOf
(get_global $std/array/arr)
(i32.const 44)
(i32.const 0)
)
)
(if
(i32.eqz
(i32.eq
(get_global $std/array/i)
(i32.const 0)
)
)
(unreachable)
)
(set_global $std/array/i
(call $std:array/Array#indexOf
(get_global $std/array/arr)
(i32.const 42)
(i32.const 0)
)
)
(if
(i32.eqz
(i32.eq
(get_global $std/array/i)
(i32.const 2)
)
)
(unreachable)
)
(set_global $std/array/i
(call $std:array/Array#indexOf
(get_global $std/array/arr)
(i32.const 45)
(i32.const 0)
)
)
(if
(i32.eqz
(i32.eq
(get_global $std/array/i)
(i32.sub
(i32.const 0)
(i32.const 1)
)
)
)
(unreachable)
)
(call $std:array/Array#splice
(get_global $std/array/arr)
(i32.const 1)
(i32.const 1)
)
(if
(i32.eqz
(i32.eq
(call $std:array/Array#get:length
(get_global $std/array/arr)
)
(i32.const 2)
)
)
(unreachable)
)
(if
(i32.eqz
(i32.eq
(i32.load offset=4
(get_global $std/array/arr)
)
(i32.const 8)
)
)
(unreachable)
)
(if
(i32.eqz
(i32.eq
(call $std:array/Array#__get
(get_global $std/array/arr)
(i32.const 0)
)
(i32.const 44)
)
)
(unreachable)
)
(if
(i32.eqz
(i32.eq
(call $std:array/Array#__get
(get_global $std/array/arr)
(i32.const 1)
)
(i32.const 42)
)
)
(unreachable)
)
)
)
(;
@ -3673,6 +4058,7 @@
GLOBAL: HEAP_BASE
CLASS_PROTOTYPE: std:array/Array
CLASS_PROTOTYPE: Array
PROPERTY: std:array/Array#length
CLASS_PROTOTYPE: std:array/CArray
CLASS_PROTOTYPE: CArray
CLASS_PROTOTYPE: std:error/Error