Skip to content

Commit 388caee

Browse files
committed
v2: lots of arm64/ssa fixes; make array_test and string_test pass with arm64
1 parent b1ea29c commit 388caee

33 files changed

Lines changed: 3253 additions & 470 deletions

‎cmd/v2/test_all.sh‎

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,53 @@ set -euo pipefail
33

44
cd "$(dirname "$0")"
55

6-
echo "=== 1/7: Self-host test ==="
6+
echo "=== 1/9: Self-host test ==="
77
bash test_v2_self.sh
88

99
echo ""
10-
echo "=== 2/7: Rebuild v2 and run builtin test files ==="
10+
echo "=== 2/9: Rebuild v2 and run builtin test files ==="
11+
rm -rf /tmp/v2_cleanc_obj_cache
1112
v self && v -o v2 v2.v
1213
./v2 ../../vlib/builtin/array_test.v
1314
./v2 ../../vlib/builtin/string_test.v
1415
./v2 ../../vlib/builtin/map_test.v
1516

1617
echo ""
17-
echo "=== 3/7: Math test ==="
18+
echo "=== 3/9: Builtin test files (arm64) ==="
19+
./v2 -backend arm64 ../../vlib/builtin/array_test.v
20+
./v2 -backend arm64 ../../vlib/builtin/string_test.v
21+
22+
echo ""
23+
echo "=== 4/9: Math test ==="
1824
./v2 ../../vlib/math/math_test.v
1925

2026
echo ""
21-
echo "=== 4/7: SSA backends test (arm64) ==="
27+
echo "=== 5/9: Sumtype tests ==="
28+
./v2 test_sumtype.v
29+
./v2 test_sumtype2.v
30+
./v2 test_sumtype3.v
31+
./v2 test_sumtype4.v
32+
./v2 test_sumtype_pos.v
33+
./v2 test_sumtype_data.v
34+
./v2 test_sumtype_ifexpr.v
35+
./v2 test_sumtype_nested.v
36+
./v2 test_sumtype_many.v
37+
./v2 test_sumtype_global.v
38+
39+
echo ""
40+
echo "=== 6/9: SSA backends test (arm64) ==="
2241
v -gc none run test_ssa_backends.v arm64
2342

2443
echo ""
25-
echo "=== 5/7: SSA backends test (cleanc) ==="
44+
echo "=== 7/9: SSA backends test (cleanc) ==="
2645
v -gc none run test_ssa_backends.v cleanc
2746

2847
echo ""
29-
echo "=== 6/7: Transformer test ==="
48+
echo "=== 8/9: Transformer test ==="
3049
v ../../vlib/v2/transformer/transformer_v2_darwin_test.v
3150

3251
echo ""
33-
echo "=== 7/7: Cleanc runtime tests ==="
52+
echo "=== 9/9: Cleanc runtime tests ==="
3453
v -gc none run ../../vlib/v2/gen/cleanc/tests/run_tests.v
3554

3655
echo ""

‎cmd/v2/test_sumtype.v‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
type Animal = Cat | Dog
2+
3+
struct Cat {
4+
name string
5+
}
6+
7+
struct Dog {
8+
name string
9+
age int
10+
}
11+
12+
fn make_animal() Animal {
13+
return Animal(Cat{
14+
name: 'whiskers'
15+
})
16+
}
17+
18+
fn main() {
19+
a := make_animal()
20+
match a {
21+
Cat {
22+
println(a.name)
23+
}
24+
Dog {
25+
println(a.name)
26+
}
27+
}
28+
}

‎cmd/v2/test_sumtype2.v‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
struct Cat {
2+
name string
3+
}
4+
5+
struct Dog {
6+
name string
7+
age int
8+
}
9+
10+
struct Bird {
11+
name string
12+
can_fly bool
13+
}
14+
15+
type Animal = Bird | Cat | Dog
16+
17+
fn make_cat() Animal {
18+
return Animal(Cat{
19+
name: 'whiskers'
20+
})
21+
}
22+
23+
fn make_bird() Animal {
24+
return Animal(Bird{
25+
name: 'tweety'
26+
can_fly: true
27+
})
28+
}
29+
30+
fn indirect() Animal {
31+
a := make_cat()
32+
return a
33+
}
34+
35+
fn get_name(a Animal) string {
36+
match a {
37+
Cat { return a.name }
38+
Dog { return a.name }
39+
Bird { return a.name }
40+
}
41+
}
42+
43+
fn main() {
44+
a := make_cat()
45+
b := make_bird()
46+
c := indirect()
47+
println(get_name(a))
48+
println(get_name(b))
49+
println(get_name(c))
50+
}

‎cmd/v2/test_sumtype3.v‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
struct Cat {
2+
name string
3+
}
4+
5+
struct Dog {
6+
name string
7+
age int
8+
}
9+
10+
struct Bird {
11+
name string
12+
can_fly bool
13+
}
14+
15+
type Animal = Bird | Cat | Dog
16+
17+
fn make_conditional(which int) Animal {
18+
result := if which == 0 {
19+
Animal(Cat{
20+
name: 'whiskers'
21+
})
22+
} else {
23+
Animal(Bird{
24+
name: 'tweety'
25+
can_fly: true
26+
})
27+
}
28+
return result
29+
}
30+
31+
fn get_name(a Animal) string {
32+
match a {
33+
Cat { return a.name }
34+
Dog { return a.name }
35+
Bird { return a.name }
36+
}
37+
}
38+
39+
fn main() {
40+
a := make_conditional(0)
41+
b := make_conditional(1)
42+
println(get_name(a))
43+
println(get_name(b))
44+
}

‎cmd/v2/test_sumtype4.v‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
struct Ident {
2+
name string
3+
line int
4+
col int
5+
}
6+
7+
struct Literal {
8+
value string
9+
}
10+
11+
type Expr = Ident | Literal
12+
13+
fn make_ident() Ident {
14+
return Ident{
15+
name: 'foo'
16+
line: 42
17+
col: 10
18+
}
19+
}
20+
21+
fn wrap_expr() Expr {
22+
i := make_ident()
23+
return i
24+
}
25+
26+
fn main() {
27+
e := wrap_expr()
28+
match e {
29+
Ident {
30+
println(e.name)
31+
println(e.line)
32+
println(e.col)
33+
}
34+
Literal {
35+
println(e.value)
36+
}
37+
}
38+
}

‎cmd/v2/test_sumtype_data.v‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
struct Pos {
2+
x int
3+
y int
4+
}
5+
6+
struct Ident {
7+
pos Pos
8+
name string
9+
}
10+
11+
struct Lit {
12+
pos Pos
13+
val int
14+
}
15+
16+
type Expr = Ident | Lit
17+
18+
fn (e Expr) get_pos() Pos {
19+
return match e {
20+
Ident { e.pos }
21+
Lit { e.pos }
22+
}
23+
}
24+
25+
fn make_ident() Expr {
26+
return Expr(Ident{
27+
pos: Pos{
28+
x: 10
29+
y: 20
30+
}
31+
name: 'hello'
32+
})
33+
}
34+
35+
fn main() {
36+
e := make_ident()
37+
p := e.get_pos()
38+
println(p.x.str())
39+
println(p.y.str())
40+
}

‎cmd/v2/test_sumtype_global.v‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
struct Pos {
2+
x int
3+
y int
4+
}
5+
6+
struct Ident {
7+
pos Pos
8+
name string
9+
}
10+
11+
struct EmptyExpr {
12+
dummy u8
13+
}
14+
15+
type Expr = EmptyExpr | Ident
16+
17+
const empty_expr = Expr(EmptyExpr{})
18+
19+
fn (e Expr) get_pos() Pos {
20+
return match e {
21+
Ident { e.pos }
22+
EmptyExpr { Pos{} }
23+
}
24+
}
25+
26+
fn parse_expr() Expr {
27+
return Expr(Ident{
28+
pos: Pos{
29+
x: 42
30+
y: 99
31+
}
32+
name: 'macos'
33+
})
34+
}
35+
36+
struct Parser {
37+
mut:
38+
tok int
39+
comptime bool
40+
}
41+
42+
fn (mut p Parser) expr_or_type() Expr {
43+
return Expr(Ident{
44+
pos: Pos{
45+
x: 77
46+
y: 88
47+
}
48+
name: 'linux'
49+
})
50+
}
51+
52+
fn (mut p Parser) if_expr(is_comptime bool) {
53+
// Exact pattern from the real parser
54+
mut cond := if p.tok == 42 {
55+
empty_expr // global constant
56+
} else {
57+
if is_comptime { p.expr_or_type() } else { p.expr_or_type() }
58+
}
59+
// This line is what crashes in v3
60+
guard_pos := cond.get_pos()
61+
println(guard_pos.x.str())
62+
println(guard_pos.y.str())
63+
}
64+
65+
fn main() {
66+
mut parser := Parser{
67+
tok: 99
68+
comptime: true
69+
}
70+
parser.if_expr(true) // should print 77, 88
71+
}

‎cmd/v2/test_sumtype_ifexpr.v‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
struct Pos {
2+
x int
3+
y int
4+
}
5+
6+
struct Ident {
7+
pos Pos
8+
name string
9+
}
10+
11+
struct EmptyExpr {
12+
dummy u8
13+
}
14+
15+
type Expr = EmptyExpr | Ident
16+
17+
fn (e Expr) get_pos() Pos {
18+
return match e {
19+
Ident { e.pos }
20+
EmptyExpr { Pos{} }
21+
}
22+
}
23+
24+
fn parse_expr() Expr {
25+
return Expr(Ident{
26+
pos: Pos{
27+
x: 42
28+
y: 99
29+
}
30+
name: 'macos'
31+
})
32+
}
33+
34+
fn test_if_expr(is_lcbr bool) {
35+
mut cond := if is_lcbr {
36+
Expr(EmptyExpr{})
37+
} else {
38+
parse_expr()
39+
}
40+
p := cond.get_pos()
41+
println(p.x.str())
42+
println(p.y.str())
43+
}
44+
45+
fn main() {
46+
test_if_expr(false) // should print 42, 99
47+
test_if_expr(true) // should print 0, 0
48+
}

0 commit comments

Comments
 (0)