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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user