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
Allow matching against records
author
Danielle Maywood
committer
nandi
date
13 hours ago
(Jul 26, 2026, 12:11 PM -0700)
commit
7ebc2fc0
7ebc2fc07ce872a9dbfcf895afdc4e7610ce4e85
parent
a9943d88
a9943d8822c6a4370472a5b0af666196424e4ddf
change-id
yzmkqqst
yzmkqqsttvrqwzllsttwnyuonskzqrsx
+108
-4
5 changed files
Expand all
Collapse all
Unified
Split
compiler-core
src
cranelift
mir
ast.rs
visit.rs
mir.rs
snapshots
gleam_core__cranelift__mir__tests__translates_samples-13.snap
cranelift.rs
+1
compiler-core/src/cranelift.rs
View file
Reviewed
···
189
189
mir::ast::Expression::StringConcat { lhs: _, rhs: _ } => todo!(),
190
190
mir::ast::Expression::List { items: _, tail: _ } => todo!(),
191
191
mir::ast::Expression::Struct { tag: _, items: _ } => todo!(),
192
192
+
mir::ast::Expression::StructTag { value: _ } => todo!(),
192
193
mir::ast::Expression::StructAccess { value: _, index: _ } => todo!(),
193
194
mir::ast::Expression::Set { name, value } => {
194
195
let var = self.make_var(name.name);
+35
-4
compiler-core/src/cranelift/mir.rs
View file
Reviewed
···
996
996
rhs: Box::new(Expression::Int { value }),
997
997
}
998
998
}
999
999
-
exhaustiveness::RuntimeCheck::Float { value: _ } => todo!(),
1000
1000
-
exhaustiveness::RuntimeCheck::String { value: _ } => todo!(),
999
999
+
exhaustiveness::RuntimeCheck::Float { value } => Expression::Equals {
1000
1000
+
lhs: Box::new(against),
1001
1001
+
rhs: Box::new(Expression::Float {
1002
1002
+
value: value.clone(),
1003
1003
+
}),
1004
1004
+
},
1005
1005
+
exhaustiveness::RuntimeCheck::String { value } => Expression::Equals {
1006
1006
+
lhs: Box::new(against),
1007
1007
+
rhs: Box::new(Expression::String {
1008
1008
+
value: value.clone(),
1009
1009
+
}),
1010
1010
+
},
1001
1011
exhaustiveness::RuntimeCheck::StringPrefix { prefix: _, rest: _ } => todo!(),
1002
1012
exhaustiveness::RuntimeCheck::Tuple {
1003
1013
size: _,
···
1006
1016
exhaustiveness::RuntimeCheck::BitArray { test: _ } => todo!(),
1007
1017
exhaustiveness::RuntimeCheck::Variant {
1008
1018
match_: _,
1009
1009
-
index: _,
1019
1019
+
index,
1010
1020
labels: _,
1011
1021
fields: _,
1012
1012
-
} => todo!(),
1022
1022
+
} => Expression::Equals {
1023
1023
+
lhs: Box::new(Expression::Int {
1024
1024
+
value: BigInt::from(*index),
1025
1025
+
}),
1026
1026
+
rhs: Box::new(Expression::StructTag {
1027
1027
+
value: Box::new(against),
1028
1028
+
}),
1029
1029
+
},
1013
1030
exhaustiveness::RuntimeCheck::NonEmptyList { first: _, rest: _ } => todo!(),
1014
1031
exhaustiveness::RuntimeCheck::EmptyList => todo!(),
1015
1032
}
···
1209
1226
insta::assert_debug_snapshot!(translate(
1210
1227
r#"pub fn pipe() {
1211
1228
[1, 2, 3, ..[4, 5, 6]]
1229
1229
+
}"#
1230
1230
+
));
1231
1231
+
1232
1232
+
insta::assert_debug_snapshot!(translate(
1233
1233
+
r#"pub type Wibble {
1234
1234
+
Wibble
1235
1235
+
Wobble
1236
1236
+
}
1237
1237
+
1238
1238
+
pub fn check(wibble: Wibble) {
1239
1239
+
case wibble {
1240
1240
+
Wibble -> 0
1241
1241
+
Wobble -> 1
1242
1242
+
}
1212
1243
}"#
1213
1244
));
1214
1245
}
+4
compiler-core/src/cranelift/mir/ast.rs
View file
Reviewed
···
174
174
items: Vec<Expression>,
175
175
},
176
176
177
177
+
StructTag {
178
178
+
value: Box<Expression>,
179
179
+
},
180
180
+
177
181
StructAccess {
178
182
value: Box<Expression>,
179
183
index: u64,
+12
compiler-core/src/cranelift/mir/visit.rs
View file
Reviewed
···
161
161
visit_expression_struct(self, tag, items);
162
162
}
163
163
164
164
+
fn visit_expression_struct_tag(&mut self, value: &'mir mut Expression) {
165
165
+
visit_expression_struct_tag(self, value);
166
166
+
}
167
167
+
164
168
fn visit_expression_struct_access(
165
169
&mut self,
166
170
value: &'mir mut Expression,
···
245
249
Expression::StringConcat { lhs, rhs } => v.visit_expression_string_concat(lhs, rhs),
246
250
Expression::List { items, tail } => v.visit_expression_list(items, tail),
247
251
Expression::Struct { tag, items } => v.visit_expression_struct(tag, items),
252
252
+
Expression::StructTag { value } => v.visit_expression_struct_tag(value),
248
253
Expression::StructAccess { value, index } => v.visit_expression_struct_access(value, index),
249
254
Expression::Set { name, value } => v.visit_expression_set(name, value),
250
255
Expression::If { cond, then, else_ } => v.visit_expression_if(cond, then, else_),
···
546
551
for item in items {
547
552
v.visit_expression(item);
548
553
}
554
554
+
}
555
555
+
556
556
+
pub fn visit_expression_struct_tag<'mir, V>(v: &mut V, value: &'mir mut Expression)
557
557
+
where
558
558
+
V: Visit<'mir> + ?Sized,
559
559
+
{
560
560
+
v.visit_expression(value);
549
561
}
550
562
551
563
pub fn visit_expression_struct_access<'mir, V>(
+56
compiler-core/src/cranelift/snapshots/gleam_core__cranelift__mir__tests__translates_samples-13.snap
View file
Reviewed
···
1
1
+
---
2
2
+
source: compiler-core/src/cranelift/mir.rs
3
3
+
expression: "translate(r#\"pub type Wibble {\n Wibble\n Wobble\n }\n\n pub fn check(wibble: Wibble) {\n case wibble {\n Wibble -> 0\n Wobble -> 1\n }\n }\"#)"
4
4
+
---
5
5
+
Module {
6
6
+
functions: [
7
7
+
Function {
8
8
+
name: "check",
9
9
+
return_type: Int,
10
10
+
parameters: [
11
11
+
FunctionParameter {
12
12
+
type_: Struct {
13
13
+
elements: [],
14
14
+
},
15
15
+
name: Some(
16
16
+
"wibble$1",
17
17
+
),
18
18
+
},
19
19
+
],
20
20
+
body: Block(
21
21
+
[
22
22
+
Set {
23
23
+
name: Var {
24
24
+
name: "_tmp$2",
25
25
+
},
26
26
+
value: Var(
27
27
+
Var {
28
28
+
name: "wibble$1",
29
29
+
},
30
30
+
),
31
31
+
},
32
32
+
If {
33
33
+
cond: Equals {
34
34
+
lhs: Int {
35
35
+
value: 0,
36
36
+
},
37
37
+
rhs: StructTag {
38
38
+
value: Var(
39
39
+
Var {
40
40
+
name: "_tmp$2",
41
41
+
},
42
42
+
),
43
43
+
},
44
44
+
},
45
45
+
then: Int {
46
46
+
value: 0,
47
47
+
},
48
48
+
else_: Int {
49
49
+
value: 1,
50
50
+
},
51
51
+
},
52
52
+
],
53
53
+
),
54
54
+
},
55
55
+
],
56
56
+
}