|
1801 | 1801 | (else |
1802 | 1802 | (error (string "invalid " syntax-str " \"" (deparse el) "\"")))))))) |
1803 | 1803 |
|
| 1804 | +;; move an assignment into the last statement of a block to keep more statements at top level |
| 1805 | +(define (sink-assignment lhs rhs) |
| 1806 | + (if (and (pair? rhs) (eq? (car rhs) 'block)) |
| 1807 | + (let ((rr (reverse (cdr rhs)))) |
| 1808 | + `(block ,@(reverse (cdr rr)) |
| 1809 | + (= ,lhs ,(car rr)))) |
| 1810 | + `(= ,lhs ,rhs))) |
| 1811 | + |
1804 | 1812 | (define (expand-forms e) |
1805 | 1813 | (if (or (atom? e) (memq (car e) '(quote inert top core globalref outerref line module toplevel ssavalue null meta using import export))) |
1806 | 1814 | e |
|
1889 | 1897 | ,@(map (lambda (l) `(= ,l ,rr)) |
1890 | 1898 | lhss) |
1891 | 1899 | (unnecessary ,rr))))))) |
1892 | | - ((and (symbol-like? lhs) (valid-name? lhs)) |
1893 | | - `(= ,lhs ,(expand-forms (caddr e)))) |
| 1900 | + ((or (and (symbol-like? lhs) (valid-name? lhs)) |
| 1901 | + (globalref? lhs)) |
| 1902 | + (sink-assignment lhs (expand-forms (caddr e)))) |
1894 | 1903 | ((atom? lhs) |
1895 | 1904 | (error (string "invalid assignment location \"" (deparse lhs) "\""))) |
1896 | 1905 | (else |
1897 | 1906 | (case (car lhs) |
1898 | | - ((globalref) |
1899 | | - ;; M.b = |
1900 | | - (let* ((rhs (caddr e)) |
1901 | | - (rr (if (or (symbol-like? rhs) (atom? rhs)) rhs (make-ssavalue)))) |
1902 | | - `(block |
1903 | | - ,.(if (eq? rr rhs) '() `((= ,rr ,(expand-forms rhs)))) |
1904 | | - (= ,lhs ,rr) |
1905 | | - (unnecessary ,rr)))) |
1906 | 1907 | ((|.|) |
1907 | 1908 | ;; a.b = |
1908 | 1909 | (let* ((a (cadr lhs)) |
|
1916 | 1917 | b (make-ssavalue))) |
1917 | 1918 | (rr (if (or (symbol-like? rhs) (atom? rhs)) rhs (make-ssavalue)))) |
1918 | 1919 | `(block |
1919 | | - ,.(if (eq? aa a) '() `((= ,aa ,(expand-forms a)))) |
1920 | | - ,.(if (eq? bb b) '() `((= ,bb ,(expand-forms b)))) |
1921 | | - ,.(if (eq? rr rhs) '() `((= ,rr ,(expand-forms rhs)))) |
| 1920 | + ,.(if (eq? aa a) '() (list (sink-assignment aa (expand-forms a)))) |
| 1921 | + ,.(if (eq? bb b) '() (list (sink-assignment bb (expand-forms b)))) |
| 1922 | + ,.(if (eq? rr rhs) '() (list (sink-assignment rr (expand-forms rhs)))) |
1922 | 1923 | (call (top setproperty!) ,aa ,bb ,rr) |
1923 | 1924 | (unnecessary ,rr))))) |
1924 | 1925 | ((tuple) |
|
1940 | 1941 | (let* ((xx (if (or (and (symbol? x) (not (memq x lhss))) |
1941 | 1942 | (ssavalue? x)) |
1942 | 1943 | x (make-ssavalue))) |
1943 | | - (ini (if (eq? x xx) '() `((= ,xx ,(expand-forms x))))) |
| 1944 | + (ini (if (eq? x xx) '() (list (sink-assignment xx (expand-forms x))))) |
1944 | 1945 | (n (length lhss)) |
1945 | 1946 | (st (gensy))) |
1946 | 1947 | `(block |
|
1972 | 1973 | (stmts (if reuse `((= ,arr ,(expand-forms a))) '())) |
1973 | 1974 | (rrhs (and (pair? rhs) (not (ssavalue? rhs)) (not (quoted? rhs)))) |
1974 | 1975 | (r (if rrhs (make-ssavalue) rhs)) |
1975 | | - (rini (if rrhs `((= ,r ,(expand-forms rhs))) '()))) |
| 1976 | + (rini (if rrhs (list (sink-assignment r (expand-forms rhs))) '()))) |
1976 | 1977 | (receive |
1977 | 1978 | (new-idxs stuff) (process-indices arr idxs) |
1978 | 1979 | `(block |
|
0 commit comments