From 42bf3fda396fee95cb6dbc55bee760cb475ce08e Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Tue, 14 Feb 2017 20:16:49 -0800 Subject: [PATCH] Change make-signal-combiner to be iterative. --- src/runtime/chrset.scm | 78 ++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/src/runtime/chrset.scm b/src/runtime/chrset.scm index f98bb11f5..bea5185a7 100644 --- a/src/runtime/chrset.scm +++ b/src/runtime/chrset.scm @@ -208,52 +208,56 @@ USA. (define (make-signal-combiner combine) - (define (loop v start sig1 sig2) - (cond ((not (pair? sig1)) (tail v 2 start sig2)) - ((not (pair? sig2)) (tail v 1 start sig1)) + (define (loop v start sig1 sig2 result) + (cond ((not (pair? sig1)) (tail v 2 start sig2 result)) + ((not (pair? sig2)) (tail v 1 start sig1 result)) (else (let ((end (fix:min (car sig1) (car sig2)))) - (process v start end - (cond ((fix:> (car sig2) end) - (loop (fix:xor v 1) - end - (cdr sig1) - sig2)) - ((fix:> (car sig1) end) - (loop (fix:xor v 2) - end - sig1 - (cdr sig2))) - (else - (loop (fix:xor v 3) - end - (cdr sig1) - (cdr sig2))))))))) - - (define (tail v vi start signal) + (let ((result* (process v start end result))) + (cond ((fix:> (car sig2) end) + (loop (fix:xor v 1) + end + (cdr sig1) + sig2 + result*)) + ((fix:> (car sig1) end) + (loop (fix:xor v 2) + end + sig1 + (cdr sig2) + result*)) + (else + (loop (fix:xor v 3) + end + (cdr sig1) + (cdr sig2) + result*)))))))) + + (define (tail v vi start signal result) (if (pair? signal) (let ((end (car signal))) - (process v start end - (tail (fix:xor v vi) - vi - end - (cdr signal)))) - (if (fix:< start #x110000) - (process v start #x110000 '()) - '()))) - - (define (process v start end signal) + (tail (fix:xor v vi) + vi + end + (cdr signal) + (process v start end result))) + (reverse! + (if (fix:< start #x110000) + (process v start #x110000 result) + result)))) + + (define (process v start end result) (if (and (fix:< start end) (combine (fix:= 1 (fix:and v 1)) (fix:= 2 (fix:and v 2)))) - (if (and (pair? signal) - (fix:= end (car signal))) - (scons start (cadr signal) (cddr signal)) - (scons start end signal)) - signal)) + (if (and (pair? result) + (fix:= start (car result))) + (rcons (cadr result) end (cddr result)) + (rcons start end result)) + result)) (lambda (sig1 sig2) - (loop 0 0 sig1 sig2))) + (loop 0 0 sig1 sig2 '()))) ;;;; Constructors -- 2.25.1