Skip to content

Commit 5c25b0c

Browse files
committed
refactor
1 parent 661e239 commit 5c25b0c

File tree

4 files changed

+116
-34
lines changed

4 files changed

+116
-34
lines changed

std/assembly/runtime/index.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,13 @@ export function FREE(ref: usize): void {
106106
/** ArrayBuffer base class. */
107107
export abstract class ArrayBufferBase {
108108
get byteLength(): i32 {
109-
var header = changetype<HEADER>(changetype<usize>(this) - HEADER_SIZE);
110-
return header.payloadSize;
109+
return changetype<HEADER>(changetype<usize>(this) - HEADER_SIZE).payloadSize;
111110
}
112111
}
113112

114113
/** String base class. */
115114
export abstract class StringBase {
116115
get length(): i32 {
117-
var header = changetype<HEADER>(changetype<usize>(this) - HEADER_SIZE);
118-
return header.payloadSize >>> 1;
116+
return changetype<HEADER>(changetype<usize>(this) - HEADER_SIZE).payloadSize >> 1;
119117
}
120118
}

tests/compiler/std/runtime.optimized.wat

+46-12
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
(global $std/runtime/ref3 (mut i32) (i32.const 0))
3333
(global $std/runtime/ref4 (mut i32) (i32.const 0))
3434
(global $std/runtime/header4 (mut i32) (i32.const 0))
35+
(global $std/runtime/ref5 (mut i32) (i32.const 0))
3536
(export "memory" (memory $0))
3637
(export "table" (table $0))
3738
(start $start)
@@ -2707,7 +2708,7 @@
27072708
else
27082709
i32.const 0
27092710
i32.const 56
2710-
i32.const 32
2711+
i32.const 34
27112712
i32.const 2
27122713
call $~lib/env/abort
27132714
unreachable
@@ -2818,7 +2819,7 @@
28182819
if
28192820
i32.const 0
28202821
i32.const 56
2821-
i32.const 47
2822+
i32.const 49
28222823
i32.const 0
28232824
call $~lib/env/abort
28242825
unreachable
@@ -2830,7 +2831,7 @@
28302831
if
28312832
i32.const 0
28322833
i32.const 56
2833-
i32.const 48
2834+
i32.const 50
28342835
i32.const 0
28352836
call $~lib/env/abort
28362837
unreachable
@@ -2844,7 +2845,7 @@
28442845
if
28452846
i32.const 0
28462847
i32.const 56
2847-
i32.const 49
2848+
i32.const 51
28482849
i32.const 0
28492850
call $~lib/env/abort
28502851
unreachable
@@ -2856,7 +2857,7 @@
28562857
if
28572858
i32.const 0
28582859
i32.const 56
2859-
i32.const 50
2860+
i32.const 52
28602861
i32.const 0
28612862
call $~lib/env/abort
28622863
unreachable
@@ -2871,7 +2872,7 @@
28712872
if
28722873
i32.const 0
28732874
i32.const 56
2874-
i32.const 52
2875+
i32.const 54
28752876
i32.const 0
28762877
call $~lib/env/abort
28772878
unreachable
@@ -2887,7 +2888,7 @@
28872888
if
28882889
i32.const 0
28892890
i32.const 56
2890-
i32.const 54
2891+
i32.const 56
28912892
i32.const 0
28922893
call $~lib/env/abort
28932894
unreachable
@@ -2904,7 +2905,7 @@
29042905
if
29052906
i32.const 0
29062907
i32.const 56
2907-
i32.const 57
2908+
i32.const 59
29082909
i32.const 0
29092910
call $~lib/env/abort
29102911
unreachable
@@ -2929,7 +2930,7 @@
29292930
if
29302931
i32.const 0
29312932
i32.const 56
2932-
i32.const 61
2933+
i32.const 63
29332934
i32.const 0
29342935
call $~lib/env/abort
29352936
unreachable
@@ -2940,7 +2941,7 @@
29402941
if
29412942
i32.const 0
29422943
i32.const 56
2943-
i32.const 62
2944+
i32.const 64
29442945
i32.const 0
29452946
call $~lib/env/abort
29462947
unreachable
@@ -2956,7 +2957,7 @@
29562957
if
29572958
i32.const 0
29582959
i32.const 56
2959-
i32.const 64
2960+
i32.const 66
29602961
i32.const 0
29612962
call $~lib/env/abort
29622963
unreachable
@@ -2968,7 +2969,40 @@
29682969
if
29692970
i32.const 0
29702971
i32.const 56
2971-
i32.const 65
2972+
i32.const 67
2973+
i32.const 0
2974+
call $~lib/env/abort
2975+
unreachable
2976+
end
2977+
i32.const 10
2978+
call $~lib/runtime/index/ALLOC
2979+
global.set $std/runtime/ref5
2980+
global.get $std/runtime/ref5
2981+
i32.const 16
2982+
i32.sub
2983+
i32.load offset=4
2984+
i32.const 10
2985+
i32.ne
2986+
if
2987+
i32.const 0
2988+
i32.const 56
2989+
i32.const 70
2990+
i32.const 0
2991+
call $~lib/env/abort
2992+
unreachable
2993+
end
2994+
global.get $std/runtime/ref5
2995+
i32.const 16
2996+
i32.sub
2997+
i32.load offset=4
2998+
i32.const 1
2999+
i32.shr_u
3000+
i32.const 5
3001+
i32.ne
3002+
if
3003+
i32.const 0
3004+
i32.const 56
3005+
i32.const 71
29723006
i32.const 0
29733007
call $~lib/env/abort
29743008
unreachable

tests/compiler/std/runtime.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ import {
1616
ALLOC,
1717
REALLOC,
1818
FREE,
19-
REGISTER
19+
REGISTER,
20+
ArrayBufferBase,
21+
StringBase
2022
} from "runtime";
2123

2224
class A {}
@@ -63,3 +65,7 @@ assert(register_parentRef == ref3);
6365
var header4 = changetype<HEADER>(register_ref - HEADER_SIZE);
6466
assert(header4.classId == __rt_classid<A>());
6567
assert(header4.payloadSize == barrier1);
68+
69+
var ref5 = ALLOC(10);
70+
assert(changetype<ArrayBufferBase>(ref5).byteLength == 10);
71+
assert(changetype<StringBase>(ref5).length == 5);

tests/compiler/std/runtime.untouched.wat

+61-17
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
(global $std/runtime/ref3 (mut i32) (i32.const 0))
4949
(global $std/runtime/ref4 (mut i32) (i32.const 0))
5050
(global $std/runtime/header4 (mut i32) (i32.const 0))
51+
(global $std/runtime/ref5 (mut i32) (i32.const 0))
5152
(global $~lib/memory/HEAP_BASE i32 (i32.const 208))
5253
(export "memory" (memory $0))
5354
(export "table" (table $0))
@@ -3398,7 +3399,21 @@
33983399
local.get $1
33993400
global.set $std/runtime/register_parentRef
34003401
)
3401-
(func $start:std/runtime (; 32 ;) (type $FUNCSIG$v)
3402+
(func $~lib/runtime/index/ArrayBufferBase#get:byteLength (; 32 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
3403+
local.get $0
3404+
i32.const 16
3405+
i32.sub
3406+
i32.load offset=4
3407+
)
3408+
(func $~lib/runtime/index/StringBase#get:length (; 33 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
3409+
local.get $0
3410+
i32.const 16
3411+
i32.sub
3412+
i32.load offset=4
3413+
i32.const 1
3414+
i32.shr_u
3415+
)
3416+
(func $start:std/runtime (; 34 ;) (type $FUNCSIG$v)
34023417
(local $0 i32)
34033418
(local $1 i32)
34043419
call $start:~lib/allocator/tlsf
@@ -3409,7 +3424,7 @@
34093424
if
34103425
i32.const 0
34113426
i32.const 56
3412-
i32.const 24
3427+
i32.const 26
34133428
i32.const 0
34143429
call $~lib/env/abort
34153430
unreachable
@@ -3422,7 +3437,7 @@
34223437
if
34233438
i32.const 0
34243439
i32.const 56
3425-
i32.const 30
3440+
i32.const 32
34263441
i32.const 0
34273442
call $~lib/env/abort
34283443
unreachable
@@ -3443,7 +3458,7 @@
34433458
if
34443459
i32.const 0
34453460
i32.const 56
3446-
i32.const 32
3461+
i32.const 34
34473462
i32.const 2
34483463
call $~lib/env/abort
34493464
unreachable
@@ -3546,7 +3561,7 @@
35463561
if
35473562
i32.const 0
35483563
i32.const 56
3549-
i32.const 47
3564+
i32.const 49
35503565
i32.const 0
35513566
call $~lib/env/abort
35523567
unreachable
@@ -3559,7 +3574,7 @@
35593574
if
35603575
i32.const 0
35613576
i32.const 56
3562-
i32.const 48
3577+
i32.const 50
35633578
i32.const 0
35643579
call $~lib/env/abort
35653580
unreachable
@@ -3573,7 +3588,7 @@
35733588
if
35743589
i32.const 0
35753590
i32.const 56
3576-
i32.const 49
3591+
i32.const 51
35773592
i32.const 0
35783593
call $~lib/env/abort
35793594
unreachable
@@ -3586,7 +3601,7 @@
35863601
if
35873602
i32.const 0
35883603
i32.const 56
3589-
i32.const 50
3604+
i32.const 52
35903605
i32.const 0
35913606
call $~lib/env/abort
35923607
unreachable
@@ -3602,7 +3617,7 @@
36023617
if
36033618
i32.const 0
36043619
i32.const 56
3605-
i32.const 52
3620+
i32.const 54
36063621
i32.const 0
36073622
call $~lib/env/abort
36083623
unreachable
@@ -3619,7 +3634,7 @@
36193634
if
36203635
i32.const 0
36213636
i32.const 56
3622-
i32.const 54
3637+
i32.const 56
36233638
i32.const 0
36243639
call $~lib/env/abort
36253640
unreachable
@@ -3636,7 +3651,7 @@
36363651
if
36373652
i32.const 0
36383653
i32.const 56
3639-
i32.const 57
3654+
i32.const 59
36403655
i32.const 0
36413656
call $~lib/env/abort
36423657
unreachable
@@ -3664,7 +3679,7 @@
36643679
if
36653680
i32.const 0
36663681
i32.const 56
3667-
i32.const 61
3682+
i32.const 63
36683683
i32.const 0
36693684
call $~lib/env/abort
36703685
unreachable
@@ -3676,7 +3691,7 @@
36763691
if
36773692
i32.const 0
36783693
i32.const 56
3679-
i32.const 62
3694+
i32.const 64
36803695
i32.const 0
36813696
call $~lib/env/abort
36823697
unreachable
@@ -3693,7 +3708,7 @@
36933708
if
36943709
i32.const 0
36953710
i32.const 56
3696-
i32.const 64
3711+
i32.const 66
36973712
i32.const 0
36983713
call $~lib/env/abort
36993714
unreachable
@@ -3706,15 +3721,44 @@
37063721
if
37073722
i32.const 0
37083723
i32.const 56
3709-
i32.const 65
3724+
i32.const 67
3725+
i32.const 0
3726+
call $~lib/env/abort
3727+
unreachable
3728+
end
3729+
i32.const 10
3730+
call $~lib/runtime/index/ALLOC
3731+
global.set $std/runtime/ref5
3732+
global.get $std/runtime/ref5
3733+
call $~lib/runtime/index/ArrayBufferBase#get:byteLength
3734+
i32.const 10
3735+
i32.eq
3736+
i32.eqz
3737+
if
3738+
i32.const 0
3739+
i32.const 56
3740+
i32.const 70
3741+
i32.const 0
3742+
call $~lib/env/abort
3743+
unreachable
3744+
end
3745+
global.get $std/runtime/ref5
3746+
call $~lib/runtime/index/StringBase#get:length
3747+
i32.const 5
3748+
i32.eq
3749+
i32.eqz
3750+
if
3751+
i32.const 0
3752+
i32.const 56
3753+
i32.const 71
37103754
i32.const 0
37113755
call $~lib/env/abort
37123756
unreachable
37133757
end
37143758
)
3715-
(func $start (; 33 ;) (type $FUNCSIG$v)
3759+
(func $start (; 35 ;) (type $FUNCSIG$v)
37163760
call $start:std/runtime
37173761
)
3718-
(func $null (; 34 ;) (type $FUNCSIG$v)
3762+
(func $null (; 36 ;) (type $FUNCSIG$v)
37193763
)
37203764
)

0 commit comments

Comments
 (0)