alpha
Login
or
Join now
nandi.uk
/
gleam
Star
1
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
Fork of daniellemaywood.uk/gleam — Wasm codegen work
Star
1
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
Overview
Issues
Pulls
Pipelines
Begin translation of lists to mir
author
Danielle Maywood
committer
nandi
date
13 hours ago
(Jul 26, 2026, 12:11 PM -0700)
commit
3cdc483f
3cdc483f9474aafeb4190cdb950df73d1822779d
parent
e00d1f1c
e00d1f1cd62d44ad41018b79edfeee43090a2baa
change-id
lvnpnsst
lvnpnsstnssmsltlpksxzqyrylqqtvoy
+95
-19
4 changed files
Expand all
Collapse all
Unified
Split
compiler-core
src
cranelift
mir.rs
snapshots
gleam_core__cranelift__mir__tests__translates_samples-12.snap
cranelift.rs
test
project_cranelift
src
project_cranelift.gleam
+1
compiler-core/src/cranelift.rs
View file
Reviewed
···
187
187
mir::Expression::FloatMul { lhs: _, rhs: _ } => todo!(),
188
188
mir::Expression::FloatDiv { lhs: _, rhs: _ } => todo!(),
189
189
mir::Expression::StringConcat { lhs: _, rhs: _ } => todo!(),
190
190
+
mir::Expression::List { items: _, tail: _ } => todo!(),
190
191
mir::Expression::Struct { tag: _, items: _ } => todo!(),
191
192
mir::Expression::StructAccess { value: _, index: _ } => todo!(),
192
193
mir::Expression::Set { name, value } => {
+49
-5
compiler-core/src/cranelift/mir.rs
View file
Reviewed
···
37
37
Bool,
38
38
String,
39
39
Struct { elements: Vec<Type> },
40
40
+
List(Box<Type>),
40
41
Generic,
41
42
}
42
43
···
173
174
rhs: Box<Expression>,
174
175
},
175
176
177
177
+
List {
178
178
+
items: Vec<Expression>,
179
179
+
tail: Option<Box<Expression>>,
180
180
+
},
181
181
+
176
182
Struct {
177
183
tag: Option<u32>,
178
184
items: Vec<Expression>,
···
268
274
("gleam", "Float") => Type::Float,
269
275
("gleam", "Bool") => Type::Bool,
270
276
("gleam", "String") => Type::String,
277
277
+
("gleam", "List") => {
278
278
+
let list_type = Self::translate_type(&arguments[0]);
279
279
+
280
280
+
Type::List(Box::new(list_type))
281
281
+
}
271
282
(_, _) => Type::Struct {
272
283
elements: arguments
273
284
.iter()
···
325
336
| Expression::FloatMul { .. }
326
337
| Expression::FloatDiv { .. }
327
338
| Expression::StringConcat { .. }
339
339
+
| Expression::List { .. }
328
340
| Expression::Struct { .. }
329
341
| Expression::StructAccess { .. }
330
342
| Expression::Set { .. }
···
432
444
lhs: Box::new(Self::flatten_expression(*lhs)),
433
445
rhs: Box::new(Self::flatten_expression(*rhs)),
434
446
},
447
447
+
Expression::List { items, tail } => Expression::List {
448
448
+
items: items.into_iter().map(Self::flatten_expression).collect(),
449
449
+
tail: tail.map(|tail| Box::new(Self::flatten_expression(*tail))),
450
450
+
},
435
451
Expression::Struct { tag, items } => Expression::Struct {
436
452
tag,
437
453
items: items.into_iter().map(Self::flatten_expression).collect(),
···
502
518
| Expression::FloatMul { .. }
503
519
| Expression::FloatDiv { .. }
504
520
| Expression::StringConcat { .. }
521
521
+
| Expression::List { .. }
505
522
| Expression::Struct { .. }
506
523
| Expression::StructAccess { .. }
507
524
| Expression::Set { .. }
···
608
625
Expression::StringConcat { lhs, rhs } => Expression::StringConcat {
609
626
lhs: Box::new(Self::remove_unused_code(*lhs)),
610
627
rhs: Box::new(Self::remove_unused_code(*rhs)),
628
628
+
},
629
629
+
Expression::List { items, tail } => Expression::List {
630
630
+
items: items.into_iter().map(Self::remove_unused_code).collect(),
631
631
+
tail: tail.map(|tail| Box::new(Self::remove_unused_code(*tail))),
611
632
},
612
633
Expression::Struct { tag, items } => Expression::Struct {
613
634
tag,
···
817
838
ast::TypedExpr::List {
818
839
location: _,
819
840
type_: _,
820
820
-
elements: _,
821
821
-
tail: _,
822
822
-
} => todo!(),
841
841
+
elements,
842
842
+
tail,
843
843
+
} => {
844
844
+
let items = elements
845
845
+
.iter()
846
846
+
.map(|element| self.translate_expression(element))
847
847
+
.collect();
848
848
+
849
849
+
let tail = tail
850
850
+
.as_ref()
851
851
+
.map(|tail| Box::new(self.translate_expression(tail)));
852
852
+
853
853
+
Expression::List { items, tail }
854
854
+
}
823
855
ast::TypedExpr::Call {
824
856
location: _,
825
857
type_: _,
···
1365
1397
},
1366
1398
ast::Constant::List {
1367
1399
location: _,
1368
1368
-
elements: _,
1400
1400
+
elements,
1369
1401
type_: _,
1370
1370
-
} => todo!(),
1402
1402
+
} => Expression::List {
1403
1403
+
items: elements
1404
1404
+
.iter()
1405
1405
+
.map(|element| self.translate_constant(element))
1406
1406
+
.collect(),
1407
1407
+
tail: None,
1408
1408
+
},
1371
1409
ast::Constant::Record {
1372
1410
location: _,
1373
1411
module: _,
···
1652
1690
1653
1691
pub fn pipe() {
1654
1692
10 |> add(20) |> add(30)
1693
1693
+
}"#
1694
1694
+
));
1695
1695
+
1696
1696
+
insta::assert_debug_snapshot!(translate(
1697
1697
+
r#"pub fn pipe() {
1698
1698
+
[1, 2, 3, ..[4, 5, 6]]
1655
1699
}"#
1656
1700
));
1657
1701
}
+44
compiler-core/src/cranelift/snapshots/gleam_core__cranelift__mir__tests__translates_samples-12.snap
View file
Reviewed
···
1
1
+
---
2
2
+
source: compiler-core/src/cranelift/mir.rs
3
3
+
expression: "translate(r#\"pub fn pipe() {\n [1, 2, 3, ..[4, 5, 6]]\n }\"#)"
4
4
+
---
5
5
+
Module {
6
6
+
functions: [
7
7
+
Function {
8
8
+
name: "pipe",
9
9
+
return_type: List(
10
10
+
Int,
11
11
+
),
12
12
+
parameters: [],
13
13
+
body: List {
14
14
+
items: [
15
15
+
Int {
16
16
+
value: 1,
17
17
+
},
18
18
+
Int {
19
19
+
value: 2,
20
20
+
},
21
21
+
Int {
22
22
+
value: 3,
23
23
+
},
24
24
+
],
25
25
+
tail: Some(
26
26
+
List {
27
27
+
items: [
28
28
+
Int {
29
29
+
value: 4,
30
30
+
},
31
31
+
Int {
32
32
+
value: 5,
33
33
+
},
34
34
+
Int {
35
35
+
value: 6,
36
36
+
},
37
37
+
],
38
38
+
tail: None,
39
39
+
},
40
40
+
),
41
41
+
},
42
42
+
},
43
43
+
],
44
44
+
}
+1
-14
test/project_cranelift/src/project_cranelift.gleam
View file
Reviewed
···
1
1
-
pub fn fib(n: Int) -> Int {
2
2
-
case n {
3
3
-
0 -> 0
4
4
-
1 -> 1
5
5
-
_ -> fib(n - 1) + fib(n - 2)
6
6
-
}
7
7
-
}
8
8
-
9
9
-
pub fn add(lhs: Int, rhs: Int) -> Int {
10
10
-
lhs + rhs
11
11
-
}
12
12
-
13
1
pub fn main() {
14
14
-
fib(40)
15
15
-
|> add(fib(40))
2
2
+
let _ = [1, 2, 3]
16
3
}