|
86 | 86 | (define (expand-compare-chain e)
|
87 | 87 | (car (expand-vector-compare e)))
|
88 | 88 |
|
89 |
| -;; return the appropriate computation for a `begin` or `end` symbol for indexing |
| 89 | +;; return the appropriate computation for an `end` symbol for indexing |
90 | 90 | ;; the array `a` in the `n`th index.
|
91 | 91 | ;; `tuples` are a list of the splatted arguments that precede index `n`
|
92 | 92 | ;; `last` = is this last index?
|
93 |
| -;; returns a call to, e.g., lastindex(a) or last(axes(a,n)) |
| 93 | +;; returns a call to lastindex(a) or last(axes(a,n)) |
94 | 94 | (define (end-val a n tuples last)
|
95 | 95 | (if (null? tuples)
|
96 | 96 | (if (and last (= n 1))
|
|
101 | 101 | tuples))))
|
102 | 102 | `(call (top last) (call (top axes) ,a ,dimno)))))
|
103 | 103 |
|
104 |
| -(define (begin-val a n tuples last) |
105 |
| - (if (null? tuples) |
106 |
| - (if (and last (= n 1)) |
107 |
| - `(call (top firstindex) ,a) |
108 |
| - `(call (top first) (call (top axes) ,a ,n))) |
109 |
| - (let ((dimno `(call (top +) ,(- n (length tuples)) |
110 |
| - ,.(map (lambda (t) `(call (top length) ,t)) |
111 |
| - tuples)))) |
112 |
| - `(call (top first) (call (top axes) ,a ,dimno))))) |
113 |
| - |
114 |
| -;; replace `begin` and `end` for the closest ref expression, so doesn't go inside nested refs |
115 |
| -(define (replace-beginend ex a n tuples last) |
| 104 | +;; replace `end` for the closest ref expression, so doesn't go inside nested refs |
| 105 | +(define (replace-end ex a n tuples last) |
116 | 106 | (cond ((eq? ex 'end) (end-val a n tuples last))
|
117 |
| - ((eq? ex 'begin) (begin-val a n tuples last)) |
118 | 107 | ((or (atom? ex) (quoted? ex)) ex)
|
119 | 108 | ((eq? (car ex) 'ref)
|
120 | 109 | ;; inside ref only replace within the first argument
|
121 |
| - (list* 'ref (replace-beginend (cadr ex) a n tuples last) |
| 110 | + (list* 'ref (replace-end (cadr ex) a n tuples last) |
122 | 111 | (cddr ex)))
|
123 | 112 | (else
|
124 | 113 | (cons (car ex)
|
125 |
| - (map (lambda (x) (replace-beginend x a n tuples last)) |
| 114 | + (map (lambda (x) (replace-end x a n tuples last)) |
126 | 115 | (cdr ex))))))
|
127 | 116 |
|
128 |
| -;; go through indices and replace the `begin` or `end` symbol |
| 117 | +;; go through indices and replace the `end` symbol |
129 | 118 | ;; a = array being indexed, i = list of indices
|
130 | 119 | ;; returns (values index-list stmts) where stmts are statements that need
|
131 | 120 | ;; to execute first.
|
|
144 | 133 | (loop (cdr lst) (+ n 1)
|
145 | 134 | stmts
|
146 | 135 | (cons (cadr idx) tuples)
|
147 |
| - (cons `(... ,(replace-beginend (cadr idx) a n tuples last)) |
| 136 | + (cons `(... ,(replace-end (cadr idx) a n tuples last)) |
148 | 137 | ret))
|
149 | 138 | (let ((g (make-ssavalue)))
|
150 | 139 | (loop (cdr lst) (+ n 1)
|
151 |
| - (cons `(= ,g ,(replace-beginend (cadr idx) a n tuples last)) |
| 140 | + (cons `(= ,g ,(replace-end (cadr idx) a n tuples last)) |
152 | 141 | stmts)
|
153 | 142 | (cons g tuples)
|
154 | 143 | (cons `(... ,g) ret))))
|
155 | 144 | (loop (cdr lst) (+ n 1)
|
156 | 145 | stmts tuples
|
157 |
| - (cons (replace-beginend idx a n tuples last) ret))))))) |
| 146 | + (cons (replace-end idx a n tuples last) ret))))))) |
158 | 147 |
|
159 | 148 | ;; GF method does not need to keep decl expressions on lambda args
|
160 | 149 | ;; except for rest arg
|
|
1511 | 1500 | (idxs (cddr e)))
|
1512 | 1501 | (let* ((reuse (and (pair? a)
|
1513 | 1502 | (contains (lambda (x)
|
1514 |
| - (or (eq? x 'begin) |
1515 |
| - (eq? x 'end) |
| 1503 | + (or (eq? x 'end) |
1516 | 1504 | (eq? x ':)
|
1517 | 1505 | (and (pair? x)
|
1518 | 1506 | (eq? (car x) ':))))
|
|
1527 | 1515 |
|
1528 | 1516 | (define (expand-update-operator op op= lhs rhs . declT)
|
1529 | 1517 | (cond ((and (pair? lhs) (eq? (car lhs) 'ref))
|
1530 |
| - ;; expand indexing inside op= first, to remove "begin", "end", and ":" |
| 1518 | + ;; expand indexing inside op= first, to remove "end" and ":" |
1531 | 1519 | (let* ((ex (partially-expand-ref lhs))
|
1532 | 1520 | (stmts (butlast (cdr ex)))
|
1533 | 1521 | (refex (last (cdr ex)))
|
|
0 commit comments