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

Configure Feed

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

Translate strings and related concat operator

author
Danielle Maywood
committer
nandi
date (Jul 26, 2026, 12:11 PM -0700) commit aa7ffca1 parent f0e9bd9e change-id wvuyxrmk
+85 -8
+42 -8
compiler-core/src/cranelift/mir.rs
··· 35 35 Int, 36 36 Float, 37 37 Bool, 38 + String, 38 39 Generic, 39 40 } 40 41 ··· 64 65 65 66 Bool { 66 67 value: bool, 68 + }, 69 + 70 + String { 71 + value: EcoString, 67 72 }, 68 73 69 74 Equals { ··· 156 161 rhs: Box<Expression>, 157 162 }, 158 163 164 + StringConcat { 165 + lhs: Box<Expression>, 166 + rhs: Box<Expression>, 167 + }, 168 + 159 169 Set { 160 170 name: Var, 161 171 value: Box<Expression>, ··· 236 246 ("gleam", "Int") => Type::Int, 237 247 ("gleam", "Float") => Type::Float, 238 248 ("gleam", "Bool") => Type::Bool, 249 + ("gleam", "String") => Type::String, 239 250 (_, _) => todo!(), 240 251 }, 241 252 type_::Type::Fn { ··· 267 278 | Expression::Int { .. } 268 279 | Expression::Float { .. } 269 280 | Expression::Bool { .. } 281 + | Expression::String { .. } 270 282 | Expression::Equals { .. } 271 283 | Expression::NotEquals { .. } 272 284 | Expression::IntGt { .. } ··· 285 297 | Expression::FloatSub { .. } 286 298 | Expression::FloatMul { .. } 287 299 | Expression::FloatDiv { .. } 300 + | Expression::StringConcat { .. } 288 301 | Expression::Set { .. } 289 302 | Expression::If { .. } 290 303 | Expression::Call { .. } => block.push(expression), ··· 301 314 Expression::Int { value } => Expression::Int { value }, 302 315 Expression::Float { value } => Expression::Float { value }, 303 316 Expression::Bool { value } => Expression::Bool { value }, 317 + Expression::String { value } => Expression::String { value }, 304 318 Expression::Equals { lhs, rhs } => Expression::Equals { 305 319 lhs: Box::new(Self::flatten_expression(*lhs)), 306 320 rhs: Box::new(Self::flatten_expression(*rhs)), ··· 373 387 lhs: Box::new(Self::flatten_expression(*lhs)), 374 388 rhs: Box::new(Self::flatten_expression(*rhs)), 375 389 }, 390 + Expression::StringConcat { lhs, rhs } => Expression::StringConcat { 391 + lhs: Box::new(Self::flatten_expression(*lhs)), 392 + rhs: Box::new(Self::flatten_expression(*rhs)), 393 + }, 376 394 Expression::Set { name, value } => Expression::Set { 377 395 name, 378 396 value: Box::new(Self::flatten_expression(*value)), ··· 405 423 | Expression::Int { .. } 406 424 | Expression::Float { .. } 407 425 | Expression::Bool { .. } 426 + | Expression::String { .. } 408 427 if index != last_expression_index => {} 409 428 410 429 Expression::Block(_) ··· 413 432 | Expression::Int { .. } 414 433 | Expression::Float { .. } 415 434 | Expression::Bool { .. } 435 + | Expression::String { .. } 416 436 | Expression::Equals { .. } 417 437 | Expression::NotEquals { .. } 418 438 | Expression::IntGt { .. } ··· 431 451 | Expression::FloatSub { .. } 432 452 | Expression::FloatMul { .. } 433 453 | Expression::FloatDiv { .. } 454 + | Expression::StringConcat { .. } 434 455 | Expression::Set { .. } 435 456 | Expression::If { .. } 436 457 | Expression::Call { .. } => block.push(expression), ··· 447 468 Expression::Int { value } => Expression::Int { value }, 448 469 Expression::Float { value } => Expression::Float { value }, 449 470 Expression::Bool { value } => Expression::Bool { value }, 471 + Expression::String { value } => Expression::String { value }, 450 472 Expression::Equals { lhs, rhs } => Expression::Equals { 451 473 lhs: Box::new(Self::remove_unused_code(*lhs)), 452 474 rhs: Box::new(Self::remove_unused_code(*rhs)), ··· 519 541 lhs: Box::new(Self::remove_unused_code(*lhs)), 520 542 rhs: Box::new(Self::remove_unused_code(*rhs)), 521 543 }, 544 + Expression::StringConcat { lhs, rhs } => Expression::StringConcat { 545 + lhs: Box::new(Self::remove_unused_code(*lhs)), 546 + rhs: Box::new(Self::remove_unused_code(*rhs)), 547 + }, 522 548 Expression::Set { name, value } => Expression::Set { 523 549 name, 524 550 value: Box::new(Self::remove_unused_code(*value)), ··· 618 644 ast::TypedExpr::String { 619 645 location: _, 620 646 type_: _, 621 - value: _, 622 - } => todo!(), 647 + value, 648 + } => Expression::String { 649 + value: value.clone(), 650 + }, 623 651 ast::TypedExpr::Block { 624 652 location: _, 625 653 statements, ··· 753 781 ast::BinOp::DivInt => Expression::IntDiv { lhs, rhs }, 754 782 ast::BinOp::DivFloat => Expression::FloatDiv { lhs, rhs }, 755 783 ast::BinOp::RemainderInt => todo!(), 756 - ast::BinOp::Concatenate => todo!(), 784 + ast::BinOp::Concatenate => Expression::StringConcat { lhs, rhs }, 757 785 } 758 786 } 759 787 ast::TypedExpr::Case { ··· 1204 1232 ast::Constant::Float { location: _, value } => Expression::Float { 1205 1233 value: value.clone(), 1206 1234 }, 1207 - ast::Constant::String { 1208 - location: _, 1209 - value: _, 1210 - } => todo!(), 1235 + ast::Constant::String { location: _, value } => Expression::String { 1236 + value: value.clone(), 1237 + }, 1211 1238 ast::Constant::Tuple { 1212 1239 location: _, 1213 1240 elements: _, ··· 1461 1488 _, _ -> 0 1462 1489 } 1463 1490 }"# 1464 - )) 1491 + )); 1492 + 1493 + insta::assert_debug_snapshot!(translate( 1494 + r#"pub fn strings() { 1495 + let _ = "hello" 1496 + let _ = "hello, " <> "world!" 1497 + }"# 1498 + )); 1465 1499 } 1466 1500 }
+43
compiler-core/src/cranelift/snapshots/gleam_core__cranelift__mir__tests__translates_samples-8.snap
··· 1 + --- 2 + source: compiler-core/src/cranelift/mir.rs 3 + expression: "translate(r#\"pub fn strings() {\n let _ = \"hello\"\n let _ = \"hello, \" <> \"world!\"\n }\"#)" 4 + --- 5 + Module { 6 + functions: [ 7 + Function { 8 + name: "strings", 9 + return_type: String, 10 + parameters: [], 11 + body: Block( 12 + [ 13 + Set { 14 + name: Var { 15 + name: "_tmp$1", 16 + }, 17 + value: String { 18 + value: "hello", 19 + }, 20 + }, 21 + Set { 22 + name: Var { 23 + name: "_tmp$2", 24 + }, 25 + value: StringConcat { 26 + lhs: String { 27 + value: "hello, ", 28 + }, 29 + rhs: String { 30 + value: "world!", 31 + }, 32 + }, 33 + }, 34 + Var( 35 + Var { 36 + name: "_tmp$2", 37 + }, 38 + ), 39 + ], 40 + ), 41 + }, 42 + ], 43 + }