[functional-tests/regex] remove match from the loop
This commit is contained in:
parent
ca6a036697
commit
2fb7eb265f
@ -201,35 +201,47 @@
|
|||||||
(set! y tmp)))))
|
(set! y tmp)))))
|
||||||
|
|
||||||
(define (match-rx code txt)
|
(define (match-rx code txt)
|
||||||
(fmt #t (dsp "running ") (pretty code) nl)
|
; (fmt #t (dsp "running ") (pretty code) nl)
|
||||||
(call/cc
|
(call/cc
|
||||||
(lambda (k)
|
(lambda (k)
|
||||||
(let ((code-len (vector-length code)))
|
(let ((code-len (vector-length code)))
|
||||||
(let ((threads (mk-thread-set code-len))
|
(let ((threads (mk-thread-set code-len))
|
||||||
(next-threads (mk-thread-set code-len)))
|
(next-threads (mk-thread-set code-len)))
|
||||||
|
|
||||||
(add-thread! threads 0)
|
(define (compile-instr instr)
|
||||||
(string-iter (in-c txt)
|
(match instr
|
||||||
(fmt #t (dsp "processing: ") (wrt in-c) nl)
|
(('match)
|
||||||
(while (i (pop-thread! threads))
|
(lambda (_ pc) (k #t)))
|
||||||
(match (vector-ref code i)
|
|
||||||
(('match) (k #t))
|
|
||||||
|
|
||||||
(('char c)
|
(('char c)
|
||||||
(when (char=? c in-c)
|
(lambda (in-c pc)
|
||||||
(add-thread! next-threads (+ 1 i))))
|
(when (char=? c in-c)
|
||||||
|
(add-thread! next-threads (+ 1 pc)))))
|
||||||
|
|
||||||
(('jmp l) (add-thread! threads l))
|
(('jmp l)
|
||||||
|
(lambda (in-c pc)
|
||||||
|
(add-thread! threads l)))
|
||||||
|
|
||||||
(('split l1 l2)
|
(('split l1 l2)
|
||||||
(begin
|
(lambda (in-c pc)
|
||||||
(add-thread! threads l1)
|
(add-thread! threads l1)
|
||||||
(add-thread! threads l2)))))
|
(add-thread! threads l2)))))
|
||||||
(if (no-threads? next-threads)
|
|
||||||
(k #f)
|
;; compile to thunks to avoid calling match in the loop.
|
||||||
(begin
|
(let ((code (vector-copy code)))
|
||||||
(swap threads next-threads)
|
(upto (n code-len)
|
||||||
(clear-thread-set! next-threads))))
|
(vector-set! code n (compile-instr (vector-ref code n))))
|
||||||
|
|
||||||
|
(add-thread! threads 0)
|
||||||
|
(string-iter (in-c txt)
|
||||||
|
; (fmt #t (dsp "processing: ") (wrt in-c) nl)
|
||||||
|
(while (pc (pop-thread! threads))
|
||||||
|
((vector-ref code pc) in-c pc))
|
||||||
|
(if (no-threads? next-threads)
|
||||||
|
(k #f)
|
||||||
|
(begin
|
||||||
|
(swap threads next-threads)
|
||||||
|
(clear-thread-set! next-threads)))))
|
||||||
(any-matches? threads code))))))
|
(any-matches? threads code))))))
|
||||||
|
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user