Optimization
Match a rule
Section titled “Match a rule”Given a file named “main.scm” with:
(import (scheme base) (stak base))
(define-optimizer foo (syntax-rules () ((foo) (write-u8 65))))
(foo)When I successfully run stak main.scm
Then the stdout should contain exactly “A”.
Match a variable pattern
Section titled “Match a variable pattern”Given a file named “main.scm” with:
(import (scheme base) (stak base))
(define-optimizer foo (syntax-rules () ((foo x) (write-u8 x))))
(foo 65)When I successfully run stak main.scm
Then the stdout should contain exactly “A”.
Match an ellipsis pattern
Section titled “Match an ellipsis pattern”Given a file named “main.scm” with:
(import (scheme base) (stak base))
(define-optimizer foo (syntax-rules () ((foo x ...) (for-each write-u8 (list x ...)))))
(foo 65 66 67)When I successfully run stak main.scm
Then the stdout should contain exactly “ABC”.
Expand a template calling another optimizer
Section titled “Expand a template calling another optimizer”Given a file named “main.scm” with:
(import (scheme base) (stak base))
(define-optimizer foo (syntax-rules () ((foo x) (write-u8 x))))
(define-optimizer bar (syntax-rules () ((bar x) (foo x))))
(bar 65)When I successfully run stak main.scm
Then the stdout should contain exactly “A”.
Expand an ellipsis template calling a variadic optimizer
Section titled “Expand an ellipsis template calling a variadic optimizer”Given a file named “main.scm” with:
(import (scheme base) (stak base))
(define-optimizer foo (syntax-rules () ((foo x) (write-u8 x))
((foo x y ...) (begin (write-u8 x) (foo y ...)))))
(define-optimizer bar (syntax-rules () ((bar x ...) (foo x ...))))
(bar 65 66 67)When I successfully run stak main.scm
Then the stdout should contain exactly “ABC”.