Skip to content

Commit 74b3925

Browse files
committed
Add a test for calling a function from an array
1 parent 0b97e33 commit 74b3925

File tree

3 files changed

+127
-0
lines changed

3 files changed

+127
-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 16668))
1516
(global $~lib/memory/__heap_base i32 (i32.const 16668))
@@ -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 (param $this i32) (param $index i32) (result i32)
3032
(local $value i32)
3133
local.get $index
@@ -210,6 +212,16 @@
210212
call $~lib/util/string/compareImpl
211213
i32.eqz
212214
)
215+
(func $std/array-access/functionArrayElementCall (param $a i32) (result i32)
216+
i32.const 123
217+
i32.const 1
218+
global.set $~argumentsLength
219+
local.get $a
220+
i32.const 0
221+
call $~lib/array/Array<%28i32%29=>i32>#__get
222+
i32.load $0
223+
call_indirect $0 (type $i32_=>_i32)
224+
)
213225
(func $~stack_check
214226
global.get $~lib/memory/__stack_pointer
215227
global.get $~lib/memory/__data_end
@@ -553,6 +565,62 @@
553565
global.set $~lib/memory/__stack_pointer
554566
local.get $3
555567
)
568+
(func $~lib/array/Array<%28i32%29=>i32>#__get (param $this i32) (param $index i32) (result i32)
569+
(local $value i32)
570+
(local $3 i32)
571+
global.get $~lib/memory/__stack_pointer
572+
i32.const 4
573+
i32.sub
574+
global.set $~lib/memory/__stack_pointer
575+
call $~stack_check
576+
global.get $~lib/memory/__stack_pointer
577+
i32.const 0
578+
i32.store $0
579+
local.get $index
580+
local.get $this
581+
i32.load $0 offset=12
582+
i32.ge_u
583+
if
584+
i32.const 32
585+
i32.const 96
586+
i32.const 114
587+
i32.const 42
588+
call $~lib/builtins/abort
589+
unreachable
590+
end
591+
global.get $~lib/memory/__stack_pointer
592+
local.get $this
593+
i32.load $0 offset=4
594+
local.get $index
595+
i32.const 2
596+
i32.shl
597+
i32.add
598+
i32.load $0
599+
local.tee $value
600+
i32.store $0
601+
i32.const 1
602+
drop
603+
i32.const 0
604+
i32.eqz
605+
drop
606+
local.get $value
607+
i32.eqz
608+
if
609+
i32.const 144
610+
i32.const 96
611+
i32.const 118
612+
i32.const 40
613+
call $~lib/builtins/abort
614+
unreachable
615+
end
616+
local.get $value
617+
local.set $3
618+
global.get $~lib/memory/__stack_pointer
619+
i32.const 4
620+
i32.add
621+
global.set $~lib/memory/__stack_pointer
622+
local.get $3
623+
)
556624
(func $export:std/array-access/i32ArrayArrayElementAccess (param $0 i32) (result i32)
557625
(local $1 i32)
558626
global.get $~lib/memory/__stack_pointer
@@ -648,4 +716,23 @@
648716
global.set $~lib/memory/__stack_pointer
649717
local.get $1
650718
)
719+
(func $export:std/array-access/functionArrayElementCall (param $0 i32) (result i32)
720+
(local $1 i32)
721+
global.get $~lib/memory/__stack_pointer
722+
i32.const 4
723+
i32.sub
724+
global.set $~lib/memory/__stack_pointer
725+
call $~stack_check
726+
global.get $~lib/memory/__stack_pointer
727+
local.get $0
728+
i32.store $0
729+
local.get $0
730+
call $std/array-access/functionArrayElementCall
731+
local.set $1
732+
global.get $~lib/memory/__stack_pointer
733+
i32.const 4
734+
i32.add
735+
global.set $~lib/memory/__stack_pointer
736+
local.get $1
737+
)
651738
)

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

Lines changed: 34 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 (param $0 i32) (result i32)
2325
(local $1 i32)
2426
(local $2 i32)
@@ -489,4 +491,36 @@
489491
call $~lib/builtins/abort
490492
unreachable
491493
)
494+
(func $export:std/array-access/functionArrayElementCall (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 17712
504+
i32.const 17760
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+
local.set $0
520+
global.get $~lib/memory/__stack_pointer
521+
i32.const 4
522+
i32.add
523+
global.set $~lib/memory/__stack_pointer
524+
local.get $0
525+
)
492526
)

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)