Merge branch 'improve_str_concat' into optimize_mcode

This commit is contained in:
2026-02-20 21:55:22 -06:00
9 changed files with 389 additions and 15 deletions

View File

@@ -1576,8 +1576,10 @@ var mcode = function(ast) {
// Standard binary ops
left_slot = gen_expr(left, -1)
right_slot = gen_expr(right, -1)
// Use target slot for ops without multi-type dispatch (add has text+num paths)
dest = (target >= 0 && kind != "+") ? target : alloc_slot()
// Use target slot for ops without multi-type dispatch (add has text+num paths).
// Exception: allow + to write directly to target when target == left_slot
// (self-assign pattern like s = s + x) since concat/add reads before writing.
dest = (target >= 0 && (kind != "+" || target == left_slot)) ? target : alloc_slot()
op = binop_map[kind]
if (op == null) {
op = "add"