feat: add Int.toFloat/Float.toInt JS backend support and fix Map C codegen

- JS backend: Add Int/Float module dispatch in both Call and EffectOp paths
  for toFloat, toInt, and toString operations
- C backend: Fix lux_strdup → lux_string_dup in Map module codegen

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-19 02:05:40 -05:00
parent a5762d0397
commit 3cdde02eb2
2 changed files with 29 additions and 13 deletions

View File

@@ -1082,16 +1082,24 @@ impl JsBackend {
}
}
// Int module
// Int/Float module operations
if let Expr::Field { object, field, .. } = func.as_ref() {
if let Expr::Var(module_name) = object.as_ref() {
if module_name.name == "Int" && field.name == "toFloat" {
if module_name.name == "Int" {
let arg = self.emit_expr(&args[0])?;
return Ok(arg); // JS numbers are already floats
match field.name.as_str() {
"toFloat" => return Ok(arg),
"toString" => return Ok(format!("String({})", arg)),
_ => {}
}
}
if module_name.name == "Float" && field.name == "toInt" {
if module_name.name == "Float" {
let arg = self.emit_expr(&args[0])?;
return Ok(format!("Math.trunc({})", arg));
match field.name.as_str() {
"toInt" => return Ok(format!("Math.trunc({})", arg)),
"toString" => return Ok(format!("String({})", arg)),
_ => {}
}
}
}
}
@@ -1183,15 +1191,23 @@ impl JsBackend {
}
// Special case: Int module operations
if effect.name == "Int" && operation.name == "toFloat" {
if effect.name == "Int" {
let arg = self.emit_expr(&args[0])?;
return Ok(arg); // JS numbers are already floats
match operation.name.as_str() {
"toFloat" => return Ok(arg), // JS numbers are already floats
"toString" => return Ok(format!("String({})", arg)),
_ => {}
}
}
// Special case: Float module operations
if effect.name == "Float" && operation.name == "toInt" {
if effect.name == "Float" {
let arg = self.emit_expr(&args[0])?;
return Ok(format!("Math.trunc({})", arg));
match operation.name.as_str() {
"toInt" => return Ok(format!("Math.trunc({})", arg)),
"toString" => return Ok(format!("String({})", arg)),
_ => {}
}
}
// Special case: Result module operations (not an effect)