|
1542 | 1542 | (cadr expr) ;; eta reduce `x->f(x)` => `f`
|
1543 | 1543 | `(-> ,argname (block ,@splat ,expr)))))
|
1544 | 1544 |
|
| 1545 | +(define (ref-to-view expr) |
| 1546 | + (if (and (pair? expr) (eq? (car expr) 'ref)) |
| 1547 | + (let* ((ex (partially-expand-ref expr)) |
| 1548 | + (stmts (butlast (cdr ex))) |
| 1549 | + (refex (last (cdr ex))) |
| 1550 | + (nuref `(call view ,(caddr refex) ,@(cdddr refex)))) |
| 1551 | + `(block ,@stmts ,nuref)) |
| 1552 | + expr)) |
| 1553 | + |
1545 | 1554 | ; fuse nested calls to expr == f.(args...) into a single broadcast call,
|
1546 | 1555 | ; or a broadcast! call if lhs is non-null.
|
1547 | 1556 | (define (expand-fuse-broadcast lhs rhs)
|
|
1657 | 1666 | (cons farg new-fargs) (cons arg new-args) renames varfarg vararg))))))
|
1658 | 1667 | (cf (cdadr f) args '() '() '() '() '()))
|
1659 | 1668 | e)) ; (not (fuse? e))
|
1660 |
| - (let ((e (compress-fuse (dot-to-fuse rhs)))) ; an expression '(fuse func args) if expr is a dot call |
| 1669 | + (let ((e (compress-fuse (dot-to-fuse rhs))) ; an expression '(fuse func args) if expr is a dot call |
| 1670 | + (lhs_ (ref-to-view lhs))) ; x[...] expressions on lhs turn in to view(x, ...) to update x in-place |
1661 | 1671 | (if (fuse? e)
|
1662 | 1672 | (if (null? lhs)
|
1663 | 1673 | (expand-forms `(call broadcast ,(from-lambda (cadr e)) ,@(caddr e)))
|
1664 |
| - (expand-forms `(call broadcast! ,(from-lambda (cadr e)) ,lhs ,@(caddr e)))) |
| 1674 | + (expand-forms `(call broadcast! ,(from-lambda (cadr e)) ,lhs_ ,@(caddr e)))) |
1665 | 1675 | (if (null? lhs)
|
1666 | 1676 | (expand-forms e)
|
1667 |
| - (expand-forms `(call broadcast! identity ,lhs ,e)))))) |
| 1677 | + (expand-forms `(call broadcast! identity ,lhs_ ,e)))))) |
1668 | 1678 |
|
1669 | 1679 | ;; table mapping expression head to a function expanding that form
|
1670 | 1680 | (define expand-table
|
|
0 commit comments