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:
@@ -954,12 +954,17 @@ impl JsBackend {
|
||||
let r = self.emit_expr(right)?;
|
||||
|
||||
// Check for string concatenation
|
||||
if matches!(op, BinaryOp::Add) {
|
||||
if matches!(op, BinaryOp::Add | BinaryOp::Concat) {
|
||||
if self.is_string_expr(left) || self.is_string_expr(right) {
|
||||
return Ok(format!("({} + {})", l, r));
|
||||
}
|
||||
}
|
||||
|
||||
// ++ on lists: use .concat()
|
||||
if matches!(op, BinaryOp::Concat) {
|
||||
return Ok(format!("{}.concat({})", l, r));
|
||||
}
|
||||
|
||||
let op_str = match op {
|
||||
BinaryOp::Add => "+",
|
||||
BinaryOp::Sub => "-",
|
||||
@@ -974,6 +979,7 @@ impl JsBackend {
|
||||
BinaryOp::Ge => ">=",
|
||||
BinaryOp::And => "&&",
|
||||
BinaryOp::Or => "||",
|
||||
BinaryOp::Concat => unreachable!("handled above"),
|
||||
BinaryOp::Pipe => {
|
||||
// Pipe operator: x |> f becomes f(x)
|
||||
return Ok(format!("{}({})", r, l));
|
||||
@@ -2342,7 +2348,7 @@ impl JsBackend {
|
||||
}
|
||||
}
|
||||
Expr::BinaryOp { op, left, right, .. } => {
|
||||
matches!(op, BinaryOp::Add)
|
||||
matches!(op, BinaryOp::Add | BinaryOp::Concat)
|
||||
&& (self.is_string_expr(left) || self.is_string_expr(right))
|
||||
}
|
||||
_ => false,
|
||||
|
||||
Reference in New Issue
Block a user