Hi,
I've been experimenting lately with an inline match construct, very much like
using compiled regexps. That is I created a tiny VM that was targeted to
do matching. to show it consider
guile> (def f ((x y 'a 'b) (+ x y)))
then
guile> ,x f
0 (assert-nargs-ee 0 1)
3 (reserve-locals 0 4)
6 (object-ref 1) ;; #(1 9 0 1 2 3 4 1 2 2 4 1 3 a 4 1 3
b 4 3 () 0)
8 (fast-match)
9 (br-if-not :L195) ;; -> 19
13 (local-ref 3) ;; `x'
15 (local-ref 2) ;; `y'
17 (add) at standard input:1:20
18 (return)
19 (toplevel-ref 2) ;; `error'
21 (object-ref 3) ;; "no match in f"
23 (tail-call 1)
large patterns yield a speedup of 15 times acording to my tests compared
with (ice-9 match).
I used guile-1.9.10. Does this release have a lot of checks compiled in so
that the comparison is unfair?
Anyway, I will try to tweak the code even further somthing along
(object-ref 1)
(fast-match)
(br L1)
(br L2)
(br L3)
....
(br Ln)
Here the fast-match routine can FETCH the br commands and issue them directly
and hence one can have one compiled pattern in stead of one for each row in
the matcher.
/Stefan