|
301 | 301 | (define (expand-compare-chain e)
|
302 | 302 | (car (expand-vector-compare e)))
|
303 | 303 |
|
304 |
| -;; last = is this last index? |
| 304 | +;; return the appropriate computation for an `end` symbol for indexing |
| 305 | +;; the array `a` in the `n`th index. |
| 306 | +;; `tuples` are a list of the splatted arguments that precede index `n` |
| 307 | +;; `last` = is this last index? |
| 308 | +;; returns a call to endof(a), trailingsize(a,n), or size(a,n) |
305 | 309 | (define (end-val a n tuples last)
|
306 | 310 | (if (null? tuples)
|
307 | 311 | (if last
|
308 | 312 | (if (= n 1)
|
309 | 313 | `(call (top endof) ,a)
|
310 | 314 | `(call (top trailingsize) ,a ,n))
|
311 |
| - #;`(call (top div) |
312 |
| - (call (top length) ,a) |
313 |
| - (call (top *) |
314 |
| - ,@(map (lambda (d) `(call (top size) ,a ,(1+ d))) |
315 |
| - (iota (- n 1))))) |
316 | 315 | `(call (top size) ,a ,n))
|
317 | 316 | (let ((dimno `(call (top +) ,(- n (length tuples))
|
318 | 317 | ,.(map (lambda (t) `(call (top length) ,t))
|
|
321 | 320 | `(call (top trailingsize) ,a ,dimno)
|
322 | 321 | `(call (top size) ,a ,dimno)))))
|
323 | 322 |
|
324 |
| -; replace end inside ex with (call (top size) a n) |
325 |
| -; affects only the closest ref expression, so doesn't go inside nested refs |
| 323 | +; replace `end` for the closest ref expression, so doesn't go inside nested refs |
326 | 324 | (define (replace-end ex a n tuples last)
|
327 | 325 | (cond ((eq? ex 'end) (end-val a n tuples last))
|
328 | 326 | ((or (atom? ex) (quoted? ex)) ex)
|
|
335 | 333 | (map (lambda (x) (replace-end x a n tuples last))
|
336 | 334 | (cdr ex))))))
|
337 | 335 |
|
338 |
| -; translate index x from colons to ranges |
339 |
| -(define (expand-index-colon x) |
340 |
| - (cond ((eq? x ':) `(call colon 1 end)) |
341 |
| - ((and (pair? x) |
342 |
| - (eq? (car x) ':)) |
343 |
| - (cond ((length= x 3) |
344 |
| - (if (eq? (caddr x) ':) |
345 |
| - ;; (: a :) a: |
346 |
| - `(call colon ,(cadr x) end) |
347 |
| - ;; (: a b) |
348 |
| - `(call colon ,(cadr x) ,(caddr x)))) |
349 |
| - ((length= x 4) |
350 |
| - (if (eq? (cadddr x) ':) |
351 |
| - ;; (: a b :) a:b: |
352 |
| - `(call colon ,(cadr x) ,(caddr x) end) |
353 |
| - ;; (: a b c) |
354 |
| - `(call colon ,@(cdr x)))) |
355 |
| - (else x))) |
356 |
| - (else x))) |
357 |
| - |
358 |
| -;; : inside indexing means 1:end |
359 |
| -;; expand end to size(a,n), |
360 |
| -;; or div(length(a), prod(size(a)[1:(n-1)])) for the last index |
| 336 | +;; go through indices and replace the `end` symbol |
361 | 337 | ;; a = array being indexed, i = list of indexes
|
362 | 338 | ;; returns (values index-list stmts) where stmts are statements that need
|
363 | 339 | ;; to execute first.
|
|
386 | 362 | (cons `(... ,g) ret))))
|
387 | 363 | (loop (cdr lst) (+ n 1)
|
388 | 364 | stmts tuples
|
389 |
| - (cons (replace-end (expand-index-colon idx) a n tuples last) |
390 |
| - ret))))))) |
| 365 | + (cons (replace-end idx a n tuples last) ret))))))) |
391 | 366 |
|
392 | 367 | (define (make-decl n t) `(|::| ,n ,t))
|
393 | 368 |
|
|
0 commit comments