Browse Source

Fix #2002 (allow `array *= matrix`)

gingerBill 3 years ago
parent
commit
19ae6122c7
1 changed files with 11 additions and 1 deletions
  1. 11 1
      src/llvm_backend_stmt.cpp

+ 11 - 1
src/llvm_backend_stmt.cpp

@@ -1959,8 +1959,18 @@ void lb_build_assign_stmt(lbProcedure *p, AstAssignStmt *as) {
 	} else {
 	} else {
 		lbAddr lhs = lb_build_addr(p, as->lhs[0]);
 		lbAddr lhs = lb_build_addr(p, as->lhs[0]);
 		lbValue value = lb_build_expr(p, as->rhs[0]);
 		lbValue value = lb_build_expr(p, as->rhs[0]);
-
 		Type *lhs_type = lb_addr_type(lhs);
 		Type *lhs_type = lb_addr_type(lhs);
+
+		// NOTE(bill): Allow for the weird edge case of:
+		// array *= matrix
+		if (op == Token_Mul && is_type_matrix(value.type) && is_type_array(lhs_type)) {
+			lbValue old_value = lb_addr_load(p, lhs);
+			Type *type = old_value.type;
+			lbValue new_value = lb_emit_vector_mul_matrix(p, old_value, value, type);
+			lb_addr_store(p, lhs, new_value);
+			return;
+		}
+
 		if (is_type_array(lhs_type)) {
 		if (is_type_array(lhs_type)) {
 			lb_build_assign_stmt_array(p, op, lhs, value);
 			lb_build_assign_stmt_array(p, op, lhs, value);
 			return;
 			return;