feat: add ++ concat operator and auto-invoke main
BUG-004: Add ++ operator for string and list concatenation across all backends (interpreter, C, JS) with type checking and formatting support. BUG-001: Auto-invoke top-level `let main = fn () => ...` when main is a zero-parameter function, instead of just printing the function value. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -730,10 +730,10 @@ impl CBackend {
|
||||
}
|
||||
|
||||
// Check for string concatenation - use lux_string_concat instead of +
|
||||
if matches!(op, BinaryOp::Add) {
|
||||
if matches!(op, BinaryOp::Add | BinaryOp::Concat) {
|
||||
let left_is_string = self.infer_expr_type(left).as_deref() == Some("LuxString");
|
||||
let right_is_string = self.infer_expr_type(right).as_deref() == Some("LuxString");
|
||||
if left_is_string || right_is_string {
|
||||
if left_is_string || right_is_string || matches!(op, BinaryOp::Concat) {
|
||||
return Ok(format!("lux_string_concat({}, {})", l, r));
|
||||
}
|
||||
}
|
||||
@@ -2839,8 +2839,18 @@ impl CBackend {
|
||||
}
|
||||
}
|
||||
|
||||
// String concatenation for ++ and +
|
||||
if matches!(op, BinaryOp::Add | BinaryOp::Concat) {
|
||||
let left_is_string = self.infer_expr_type(left).as_deref() == Some("LuxString");
|
||||
let right_is_string = self.infer_expr_type(right).as_deref() == Some("LuxString");
|
||||
if left_is_string || right_is_string || matches!(op, BinaryOp::Concat) {
|
||||
return Ok(format!("lux_string_concat({}, {})", l, r));
|
||||
}
|
||||
}
|
||||
|
||||
let op_str = match op {
|
||||
BinaryOp::Add => "+",
|
||||
BinaryOp::Concat => unreachable!("handled above"),
|
||||
BinaryOp::Sub => "-",
|
||||
BinaryOp::Mul => "*",
|
||||
BinaryOp::Div => "/",
|
||||
|
||||
Reference in New Issue
Block a user