mescc: Cache text generation.

* module/mes/elf-util.mes (functions->text): Add cache.
This commit is contained in:
Jan Nieuwenhuizen 2017-03-18 23:00:04 +01:00
parent 2397e0c8e2
commit a010203f0d
1 changed files with 10 additions and 5 deletions

View File

@ -55,11 +55,16 @@
(define (text->list o)
(append-map (lambda/label->list '() '() 0 0 0) o))
(define (functions->text functions globals ta t d)
(let loop ((lambdas/labels (functions->lambdas functions)) (text '()))
(if (null? lambdas/labels) text
(loop (cdr lambdas/labels)
(append text ((lambda/label->list functions globals ta (- (length text)) d) (car lambdas/labels)))))))
(define functions->text
(let ((cache '()))
(lambda (functions globals ta t d)
(or (assoc-ref cache (cons ta (map car functions)))
(let ((text (let loop ((lambdas/labels (functions->lambdas functions)) (text '()))
(if (null? lambdas/labels) text
(loop (cdr lambdas/labels)
(append text ((lambda/label->list functions globals ta (- (length text)) d) (car lambdas/labels))))))))
(set! cache (assoc-set! cache (cons ta (map car functions)) text))
text)))))
(define (function-prefix name functions)
;; FIXME