| 1 |
;; |
| 2 |
;; Common auxiliary procedures to run test |
| 3 |
;; |
| 4 |
;; This file consists of excepts from Oleg Kiselyov's myenv.scm and |
| 5 |
;; SSAX.scm. They are macros and procedures only required for testing. |
| 6 |
;; |
| 7 |
|
| 8 |
;; Excerpt from myenv.scm -------------------------------------- |
| 9 |
|
| 10 |
(define-macro (assure exp error-msg) `(assert ,exp report: ,error-msg)) |
| 11 |
|
| 12 |
|
| 13 |
(define (cout . args) |
| 14 |
(for-each (lambda (x) |
| 15 |
(if (procedure? x) (x) (display x))) |
| 16 |
args)) |
| 17 |
|
| 18 |
(define (cerr . args) |
| 19 |
(for-each (lambda (x) |
| 20 |
(if (procedure? x) |
| 21 |
(x (standard-error-port)) |
| 22 |
(display x (standard-error-port)))) |
| 23 |
args)) |
| 24 |
|
| 25 |
;(##define-macro (nl) '(newline)) |
| 26 |
(define nl "\n") |
| 27 |
|
| 28 |
;; Dummy |
| 29 |
(define (pp arg) (write* arg) (newline)) |
| 30 |
|
| 31 |
; Some useful increment/decrement operators |
| 32 |
|
| 33 |
; Mutable increment |
| 34 |
(define-macro (++! x) `(inc! ,x)) |
| 35 |
|
| 36 |
; Read-only increment |
| 37 |
(define-macro (++ x) `(+ 1 ,x)) |
| 38 |
|
| 39 |
; Mutable decrement |
| 40 |
(define-macro (--! x) `(dec! ,x)) |
| 41 |
|
| 42 |
; Read-only decrement |
| 43 |
(define-macro (-- x) `(- ,x 1)) |
| 44 |
|
| 45 |
;; Excerpt from util.scm -------------------------------------- |
| 46 |
|
| 47 |
(define (list-intersperse src-l elem) |
| 48 |
(if (null? src-l) src-l |
| 49 |
(let loop ((l (cdr src-l)) (dest (cons (car src-l) '()))) |
| 50 |
(if (null? l) (reverse dest) |
| 51 |
(loop (cdr l) (cons (car l) (cons elem dest))))))) |
| 52 |
|
| 53 |
;; Excerpt from SSAX.scm -------------------------------------- |
| 54 |
|
| 55 |
;; Kludge - trans.scm removes run-test definition. We use different |
| 56 |
;; name to prevent this from removed. |
| 57 |
(define-macro %run-test |
| 58 |
(lambda body |
| 59 |
(define (re-write body) |
| 60 |
(cond |
| 61 |
((vector? body) |
| 62 |
(list->vector (re-write (vector->list body)))) |
| 63 |
((not (pair? body)) body) |
| 64 |
((and (eq? 'quote (car body)) (pair? (cdr body)) |
| 65 |
(string? (cadr body))) |
| 66 |
(string->symbol (cadr body))) |
| 67 |
(else (cons (re-write (car body)) (re-write (cdr body)))))) |
| 68 |
(cons 'begin (re-write body)))) |
| 69 |
|
| 70 |
;; Other stuff ----------------------------------------------- |
| 71 |
|
| 72 |
(define-syntax declare |
| 73 |
(syntax-rules () ((_ . foo) #f))) |
| 74 |
|
| 75 |
(define-macro (include file) |
| 76 |
(cond ((member file '("myenv.scm" "catch-error.scm")) #f) |
| 77 |
(else `(load ,(string-append "sxml/" file))))) |
| 78 |
|
| 79 |
(define-syntax failed? |
| 80 |
(syntax-rules () |
| 81 |
((_ . body) |
| 82 |
(with-error-handler |
| 83 |
(lambda (e) #t) |
| 84 |
(lambda () . body))))) |