Fork of daniellemaywood.uk/gleam — Wasm codegen work
1

Configure Feed

Select the types of activity you want to include in your feed.

Translate pipeline expressiont to the mir

author
Danielle Maywood
committer
nandi
date (Jul 26, 2026, 12:11 PM -0700) commit e00d1f1c parent 9b133439 change-id tonpuyvt
+136 -4
+34 -4
compiler-core/src/cranelift/mir.rs
··· 726 726 } => self.in_var_scope(|this| this.translate_statements(statements)), 727 727 ast::TypedExpr::Pipeline { 728 728 location: _, 729 - first_value: _, 730 - assignments: _, 731 - finally: _, 729 + first_value, 730 + assignments, 731 + finally, 732 732 finally_kind: _, 733 - } => todo!(), 733 + } => { 734 + let mut block = vec![]; 735 + 736 + let value = self.translate_expression(&first_value.value); 737 + block.push(Expression::Set { 738 + name: self.make_var(first_value.name.clone()), 739 + value: Box::new(value), 740 + }); 741 + 742 + for (assignment, _) in assignments { 743 + let value = self.translate_expression(&assignment.value); 744 + block.push(Expression::Set { 745 + name: self.make_var(assignment.name.clone()), 746 + value: Box::new(value), 747 + }); 748 + } 749 + 750 + block.push(self.translate_expression(finally)); 751 + 752 + Expression::Block(block) 753 + } 734 754 ast::TypedExpr::Var { 735 755 location: _, 736 756 constructor, ··· 1622 1642 let x = Wibble(a: 10, b: 20) 1623 1643 1624 1644 w.a + x.b 1645 + }"# 1646 + )); 1647 + 1648 + insta::assert_debug_snapshot!(translate( 1649 + r#"pub fn add(lhs: Int, rhs: Int) -> Int { 1650 + lhs + rhs 1651 + } 1652 + 1653 + pub fn pipe() { 1654 + 10 |> add(20) |> add(30) 1625 1655 }"# 1626 1656 )); 1627 1657 }
+1
compiler-core/src/cranelift/snapshots/gleam_core__cranelift__mir__tests__translates_samples-10.snap
··· 27 27 target: FunctionRef { 28 28 module: "", 29 29 name: "Wibble", 30 + arity: 2, 30 31 }, 31 32 args: [ 32 33 Int {
+94
compiler-core/src/cranelift/snapshots/gleam_core__cranelift__mir__tests__translates_samples-11.snap
··· 1 + --- 2 + source: compiler-core/src/cranelift/mir.rs 3 + expression: "translate(r#\"pub fn add(lhs: Int, rhs: Int) -> Int {\n lhs + rhs\n }\n\n pub fn pipe() {\n 10 |> add(20) |> add(30)\n }\"#)" 4 + --- 5 + Module { 6 + functions: [ 7 + Function { 8 + name: "add", 9 + return_type: Int, 10 + parameters: [ 11 + FunctionParameter { 12 + type_: Int, 13 + name: Some( 14 + "lhs$1", 15 + ), 16 + }, 17 + FunctionParameter { 18 + type_: Int, 19 + name: Some( 20 + "rhs$2", 21 + ), 22 + }, 23 + ], 24 + body: IntAdd { 25 + lhs: Var( 26 + Var { 27 + name: "lhs$1", 28 + }, 29 + ), 30 + rhs: Var( 31 + Var { 32 + name: "rhs$2", 33 + }, 34 + ), 35 + }, 36 + }, 37 + Function { 38 + name: "pipe", 39 + return_type: Int, 40 + parameters: [], 41 + body: Block( 42 + [ 43 + Set { 44 + name: Var { 45 + name: "_pipe$1", 46 + }, 47 + value: Int { 48 + value: 10, 49 + }, 50 + }, 51 + Set { 52 + name: Var { 53 + name: "_pipe$2", 54 + }, 55 + value: Call { 56 + target: FunctionRef { 57 + module: "", 58 + name: "add", 59 + arity: 2, 60 + }, 61 + args: [ 62 + Var( 63 + Var { 64 + name: "_pipe$1", 65 + }, 66 + ), 67 + Int { 68 + value: 20, 69 + }, 70 + ], 71 + }, 72 + }, 73 + Call { 74 + target: FunctionRef { 75 + module: "", 76 + name: "add", 77 + arity: 2, 78 + }, 79 + args: [ 80 + Var( 81 + Var { 82 + name: "_pipe$2", 83 + }, 84 + ), 85 + Int { 86 + value: 30, 87 + }, 88 + ], 89 + }, 90 + ], 91 + ), 92 + }, 93 + ], 94 + }
+2
compiler-core/src/cranelift/snapshots/gleam_core__cranelift__mir__tests__translates_samples-4.snap
··· 60 60 target: FunctionRef { 61 61 module: "", 62 62 name: "fib", 63 + arity: 1, 63 64 }, 64 65 args: [ 65 66 IntSub { ··· 78 79 target: FunctionRef { 79 80 module: "", 80 81 name: "fib", 82 + arity: 1, 81 83 }, 82 84 args: [ 83 85 IntSub {
+5
test/project_cranelift/src/project_cranelift.gleam
··· 6 6 } 7 7 } 8 8 9 + pub fn add(lhs: Int, rhs: Int) -> Int { 10 + lhs + rhs 11 + } 12 + 9 13 pub fn main() { 10 14 fib(40) 15 + |> add(fib(40)) 11 16 }