Skip to content

Commit b55c739

Browse files
committed
Add a test for calling a function from an array
1 parent 0ce8c03 commit b55c739

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed

tests/compiler/std/array-access.debug.wat

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
(global $~lib/shared/runtime/Runtime.Minimal i32 (i32.const 1))
1111
(global $~lib/shared/runtime/Runtime.Incremental i32 (i32.const 2))
1212
(global $~lib/native/ASC_SHRINK_LEVEL i32 (i32.const 0))
13+
(global $~argumentsLength (mut i32) (i32.const 0))
1314
(global $~lib/memory/__data_end i32 (i32.const 284))
1415
(global $~lib/memory/__stack_pointer (mut i32) (i32.const 33052))
1516
(global $~lib/memory/__heap_base i32 (i32.const 33052))
@@ -26,6 +27,7 @@
2627
(export "stringArrayMethodCall" (func $export:std/array-access/stringArrayMethodCall))
2728
(export "stringArrayArrayPropertyAccess" (func $export:std/array-access/stringArrayArrayPropertyAccess))
2829
(export "stringArrayArrayMethodCall" (func $export:std/array-access/stringArrayArrayMethodCall))
30+
(export "functionArrayElementCall" (func $export:std/array-access/functionArrayElementCall))
2931
(func $~lib/array/Array<i32>#__get (type $i32_i32_=>_i32) (param $this i32) (param $index i32) (result i32)
3032
(local $value i32)
3133
local.get $index
@@ -213,6 +215,16 @@
213215
call $~lib/util/string/compareImpl
214216
i32.eqz
215217
)
218+
(func $std/array-access/functionArrayElementCall (type $i32_=>_i32) (param $a i32) (result i32)
219+
i32.const 123
220+
i32.const 1
221+
global.set $~argumentsLength
222+
local.get $a
223+
i32.const 0
224+
call $~lib/array/Array<%28i32%29=>i32>#__get
225+
i32.load $0
226+
call_indirect $0 (type $i32_=>_i32)
227+
)
216228
(func $~stack_check (type $none_=>_none)
217229
global.get $~lib/memory/__stack_pointer
218230
global.get $~lib/memory/__data_end
@@ -556,6 +568,62 @@
556568
global.set $~lib/memory/__stack_pointer
557569
local.get $3
558570
)
571+
(func $~lib/array/Array<%28i32%29=>i32>#__get (type $i32_i32_=>_i32) (param $this i32) (param $index i32) (result i32)
572+
(local $value i32)
573+
(local $3 i32)
574+
global.get $~lib/memory/__stack_pointer
575+
i32.const 4
576+
i32.sub
577+
global.set $~lib/memory/__stack_pointer
578+
call $~stack_check
579+
global.get $~lib/memory/__stack_pointer
580+
i32.const 0
581+
i32.store $0
582+
local.get $index
583+
local.get $this
584+
i32.load $0 offset=12
585+
i32.ge_u
586+
if
587+
i32.const 32
588+
i32.const 96
589+
i32.const 114
590+
i32.const 42
591+
call $~lib/builtins/abort
592+
unreachable
593+
end
594+
global.get $~lib/memory/__stack_pointer
595+
local.get $this
596+
i32.load $0 offset=4
597+
local.get $index
598+
i32.const 2
599+
i32.shl
600+
i32.add
601+
i32.load $0
602+
local.tee $value
603+
i32.store $0
604+
i32.const 1
605+
drop
606+
i32.const 0
607+
i32.eqz
608+
drop
609+
local.get $value
610+
i32.eqz
611+
if
612+
i32.const 144
613+
i32.const 96
614+
i32.const 118
615+
i32.const 40
616+
call $~lib/builtins/abort
617+
unreachable
618+
end
619+
local.get $value
620+
local.set $3
621+
global.get $~lib/memory/__stack_pointer
622+
i32.const 4
623+
i32.add
624+
global.set $~lib/memory/__stack_pointer
625+
local.get $3
626+
)
559627
(func $export:std/array-access/i32ArrayArrayElementAccess (type $i32_=>_i32) (param $0 i32) (result i32)
560628
(local $1 i32)
561629
global.get $~lib/memory/__stack_pointer
@@ -651,4 +719,23 @@
651719
global.set $~lib/memory/__stack_pointer
652720
local.get $1
653721
)
722+
(func $export:std/array-access/functionArrayElementCall (type $i32_=>_i32) (param $0 i32) (result i32)
723+
(local $1 i32)
724+
global.get $~lib/memory/__stack_pointer
725+
i32.const 4
726+
i32.sub
727+
global.set $~lib/memory/__stack_pointer
728+
call $~stack_check
729+
global.get $~lib/memory/__stack_pointer
730+
local.get $0
731+
i32.store $0
732+
local.get $0
733+
call $std/array-access/functionArrayElementCall
734+
local.set $1
735+
global.get $~lib/memory/__stack_pointer
736+
i32.const 4
737+
i32.add
738+
global.set $~lib/memory/__stack_pointer
739+
local.get $1
740+
)
654741
)

tests/compiler/std/array-access.release.wat

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313
(data (i32.const 1160) "\01\00\00\00^\00\00\00E\00l\00e\00m\00e\00n\00t\00 \00t\00y\00p\00e\00 \00m\00u\00s\00t\00 \00b\00e\00 \00n\00u\00l\00l\00a\00b\00l\00e\00 \00i\00f\00 \00a\00r\00r\00a\00y\00 \00i\00s\00 \00h\00o\00l\00e\00y")
1414
(data (i32.const 1276) "\1c")
1515
(data (i32.const 1288) "\01")
16+
(table $0 1 1 funcref)
1617
(export "memory" (memory $0))
1718
(export "i32ArrayArrayElementAccess" (func $export:std/array-access/i32ArrayArrayElementAccess))
1819
(export "stringArrayPropertyAccess" (func $export:std/array-access/stringArrayPropertyAccess))
1920
(export "stringArrayMethodCall" (func $export:std/array-access/stringArrayMethodCall))
2021
(export "stringArrayArrayPropertyAccess" (func $export:std/array-access/stringArrayArrayPropertyAccess))
2122
(export "stringArrayArrayMethodCall" (func $export:std/array-access/stringArrayArrayMethodCall))
23+
(export "functionArrayElementCall" (func $export:std/array-access/functionArrayElementCall))
2224
(func $~lib/string/String#startsWith (type $i32_=>_i32) (param $0 i32) (result i32)
2325
(local $1 i32)
2426
(local $2 i32)
@@ -489,4 +491,32 @@
489491
call $~lib/builtins/abort
490492
unreachable
491493
)
494+
(func $export:std/array-access/functionArrayElementCall (type $i32_=>_i32) (param $0 i32) (result i32)
495+
global.get $~lib/memory/__stack_pointer
496+
i32.const 4
497+
i32.sub
498+
global.set $~lib/memory/__stack_pointer
499+
global.get $~lib/memory/__stack_pointer
500+
i32.const 1308
501+
i32.lt_s
502+
if
503+
i32.const 34096
504+
i32.const 34144
505+
i32.const 1
506+
i32.const 1
507+
call $~lib/builtins/abort
508+
unreachable
509+
end
510+
global.get $~lib/memory/__stack_pointer
511+
local.get $0
512+
i32.store $0
513+
i32.const 123
514+
local.get $0
515+
i32.const 0
516+
call $~lib/array/Array<~lib/array/Array<i32>>#__get
517+
i32.load $0
518+
call_indirect $0 (type $i32_=>_i32)
519+
drop
520+
unreachable
521+
)
492522
)

tests/compiler/std/array-access.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,9 @@ export function stringArrayArrayPropertyAccess(a: string[][]): i32 {
1717
export function stringArrayArrayMethodCall(a: string[][]): i32 {
1818
return a[0][1].startsWith("");
1919
}
20+
21+
// FIXME: Parenthesizing types is not supported
22+
type T = (x: i32) => i32
23+
export function functionArrayElementCall(a: T[]): i32 {
24+
return a[0](123);
25+
}

0 commit comments

Comments
 (0)