Skip to content

Commit a7ec1ce

Browse files
committed
tests: update/add relevant tests
1 parent 4f03585 commit a7ec1ce

7 files changed

Lines changed: 243 additions & 0 deletions
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export function postStart(instance) {
2+
const exports = instance.exports;
3+
4+
const divmod = exports.divmod(1234, 5678);
5+
if (!Array.isArray(divmod) || divmod[0] !== 0 || divmod[1] !== 1234) {
6+
throw Error("unexpected divmod result");
7+
}
8+
9+
const pass = exports.pass(1234n);
10+
if (!Array.isArray(pass) || pass[0] !== 1234n || pass[1] !== 1235n) {
11+
throw Error("unexpected pass result");
12+
}
13+
14+
const swapped = exports.swapTypes(1234, 12.5);
15+
if (!Array.isArray(swapped) || swapped[0] !== 12.5 || swapped[1] !== 1234) {
16+
throw Error("unexpected swapTypes result");
17+
}
18+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"asc_flags": [
3+
"--enable", "multi-value"
4+
],
5+
"stderr": [
6+
"AS100: Not implemented: Using multi-value local results outside of tuple indexing",
7+
"AS100: Not implemented: Assigning to locals that capture multi-value call results is not supported yet",
8+
"AS100: Not implemented: Tuple indexing currently requires a constant integer literal index",
9+
"EOF"
10+
]
11+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function pair(x: i64): [i64, i64] {
2+
return [x, x + 1];
3+
}
4+
5+
function badScalarUse(): i64 {
6+
let p = pair(10);
7+
return p;
8+
}
9+
10+
function badAssign(): i64 {
11+
let p = pair(10);
12+
p = 42;
13+
return p[1];
14+
}
15+
16+
function test(): void {
17+
let p = pair(10);
18+
let i = 1;
19+
assert(p[i] == 11);
20+
}
21+
22+
badScalarUse();
23+
badAssign();
24+
test();
25+
26+
ERROR("EOF");
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
(module
2+
(type $0 (func))
3+
(type $1 (func (param i32 i32) (result i32 i32)))
4+
(type $2 (func (param i32 i32 i32 i32)))
5+
(type $3 (func (param i64) (result i64 i64)))
6+
(import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32)))
7+
(global $~lib/memory/__data_end i32 (i32.const 92))
8+
(global $~lib/memory/__stack_pointer (mut i32) (i32.const 32860))
9+
(global $~lib/memory/__heap_base i32 (i32.const 32860))
10+
(memory $0 1)
11+
(data $0 (i32.const 12) "L\00\00\00\00\00\00\00\00\00\00\00\02\00\00\00.\00\00\00m\00u\00l\00t\00i\00-\00v\00a\00l\00u\00e\00-\00i\00n\00d\00e\00x\00i\00n\00g\00.\00t\00s\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00")
12+
(table $0 1 1 funcref)
13+
(elem $0 (i32.const 1))
14+
(export "memory" (memory $0))
15+
(start $~start)
16+
(func $multi-value-indexing/divmod (param $a i32) (param $b i32) (result i32 i32)
17+
local.get $a
18+
local.get $b
19+
i32.div_s
20+
local.get $a
21+
local.get $b
22+
i32.rem_s
23+
tuple.make 2
24+
return
25+
)
26+
(func $multi-value-indexing/pair (param $x i64) (result i64 i64)
27+
local.get $x
28+
local.get $x
29+
i64.const 1
30+
i64.add
31+
tuple.make 2
32+
return
33+
)
34+
(func $multi-value-indexing/test
35+
(local $dm i32)
36+
(local $1 i32)
37+
(local $2 (tuple i32 i32))
38+
(local $p i64)
39+
(local $4 i64)
40+
(local $5 (tuple i64 i64))
41+
(local $q i64)
42+
(local $7 i64)
43+
(local $8 (tuple i64 i64))
44+
i32.const 1234
45+
i32.const 5678
46+
call $multi-value-indexing/divmod
47+
local.set $2
48+
local.get $2
49+
tuple.extract 2 0
50+
local.set $dm
51+
local.get $2
52+
tuple.extract 2 1
53+
local.set $1
54+
local.get $dm
55+
i32.const 0
56+
i32.eq
57+
i32.eqz
58+
if
59+
i32.const 0
60+
i32.const 32
61+
i32.const 12
62+
i32.const 3
63+
call $~lib/builtins/abort
64+
unreachable
65+
end
66+
local.get $1
67+
i32.const 1234
68+
i32.eq
69+
i32.eqz
70+
if
71+
i32.const 0
72+
i32.const 32
73+
i32.const 13
74+
i32.const 3
75+
call $~lib/builtins/abort
76+
unreachable
77+
end
78+
i64.const 1234
79+
call $multi-value-indexing/pair
80+
local.set $5
81+
local.get $5
82+
tuple.extract 2 0
83+
local.set $p
84+
local.get $5
85+
tuple.extract 2 1
86+
local.set $4
87+
local.get $p
88+
i64.const 1234
89+
i64.eq
90+
i32.eqz
91+
if
92+
i32.const 0
93+
i32.const 32
94+
i32.const 16
95+
i32.const 3
96+
call $~lib/builtins/abort
97+
unreachable
98+
end
99+
local.get $4
100+
i64.const 1235
101+
i64.eq
102+
i32.eqz
103+
if
104+
i32.const 0
105+
i32.const 32
106+
i32.const 17
107+
i32.const 3
108+
call $~lib/builtins/abort
109+
unreachable
110+
end
111+
i64.const 99
112+
call $multi-value-indexing/pair
113+
local.set $8
114+
local.get $8
115+
tuple.extract 2 0
116+
local.set $q
117+
local.get $8
118+
tuple.extract 2 1
119+
local.set $7
120+
local.get $q
121+
i64.const 99
122+
i64.eq
123+
i32.eqz
124+
if
125+
i32.const 0
126+
i32.const 32
127+
i32.const 20
128+
i32.const 3
129+
call $~lib/builtins/abort
130+
unreachable
131+
end
132+
local.get $7
133+
i64.const 100
134+
i64.eq
135+
i32.eqz
136+
if
137+
i32.const 0
138+
i32.const 32
139+
i32.const 21
140+
i32.const 3
141+
call $~lib/builtins/abort
142+
unreachable
143+
end
144+
)
145+
(func $start:multi-value-indexing
146+
call $multi-value-indexing/test
147+
)
148+
(func $~start
149+
call $start:multi-value-indexing
150+
)
151+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"asc_flags": [
3+
"--enable", "multi-value"
4+
]
5+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(module
2+
(memory $0 1)
3+
(data $0 (i32.const 1036) "L")
4+
(data $0.1 (i32.const 1048) "\02\00\00\00.\00\00\00m\00u\00l\00t\00i\00-\00v\00a\00l\00u\00e\00-\00i\00n\00d\00e\00x\00i\00n\00g\00.\00t\00s")
5+
(export "memory" (memory $0))
6+
)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function divmod(a: i32, b: i32): [i32, i32] {
2+
return [a / b, a % b];
3+
}
4+
5+
function pair(x: i64): [i64, i64] {
6+
return [x, x + 1];
7+
}
8+
9+
function test(): void {
10+
// rn, i only have tuples working in function locals to keep the scope smaller
11+
let dm = divmod(1234, 5678);
12+
assert(dm[0] == 0);
13+
assert(dm[1] == 1234);
14+
15+
let p = pair(1234);
16+
assert(p[0] == 1234);
17+
assert(p[1] == 1235);
18+
19+
let q = (pair(99));
20+
assert(q[0] == 99);
21+
assert(q[1] == 100);
22+
}
23+
24+
test();
25+
26+
// so running like assert(pair(100)[0] == 100) here would crash

0 commit comments

Comments
 (0)