Debian Codegraph @

test/partcont-racket.scm

raw
1 ;;
2 ;; Run partcont test with Racket.
3 ;;
4 ;; plt-r6rs ./partcont-racket
5
6 (import (rename (rnrs base (6)) (error r6rs:error))
7 (rnrs io ports (6))
8 (rnrs io simple (6))
9 (rnrs files (6))
10 (rnrs exceptions (6))
11 (rnrs conditions (6))
12 (rnrs control (6))
13 (srfi :39)
14 (racket include)
15 (racket control))
16
17 ;; Compatibility layer
18
19 (define-syntax push!
20 (syntax-rules ()
21 ((push! loc x) (set! loc (cons x loc)))))
22
23 (define-syntax pop!
24 (syntax-rules ()
25 ((pop! loc) (let ((v (car loc))) (set! loc (cdr loc)) v))))
26
27 (define-syntax values->list
28 (syntax-rules ()
29 ((values->list expr)
30 (call-with-values (lambda () expr) list))))
31
32 (define-syntax while
33 (syntax-rules (=>)
34 ((_ expr guard => var . body)
35 (do ((var expr expr))
36 ((not (guard var)))
37 . body))
38 ((_ expr => var . body)
39 (do ((var expr expr))
40 ((not var))
41 . body))
42 ((_ expr . body)
43 (do ()
44 ((not expr))
45 . body))
46 ((_ . other)
47 (syntax-error "malformed while" (while . other)))))
48
49 (define-syntax temporarily
50 (syntax-rules ()
51 ((temporarily ((state init) ...) expr ...)
52 (let ((tmp init) ...)
53 (dynamic-wind
54 (lambda () (set! tmp (state tmp)) ...)
55 (lambda () expr ...)
56 (lambda () (set! tmp (state tmp)) ...))))))
57
58 (define-syntax gauche-only
59 (syntax-rules ()
60 ((gauche-only x ...) (values))))
61
62 (define *discrepancies* '())
63
64 (define-syntax test*
65 (syntax-rules (test-error)
66 ((test* name expect expr)
67 (begin
68 (display name)
69 (newline)
70 (display "Expect:" )
71 (write expect)
72 (newline)
73 (let-values ((result expr))
74 (display "Result:")
75 (for-each (lambda (r) (write r) (newline)) result)
76 (newline)
77 (when (not (equal? (list expect) result))
78 (set! *discrepancies*
79 (cons (list name expect result) *discrepancies*))))
80 (newline)))))
81
82 (define (with-output-to-string thunk)
83 (with-output-to-file "tmp.log" (lambda () (reset (thunk))))
84 (let ((s (with-input-from-file "tmp.log"
85 (lambda ()
86 (call-with-string-output-port
87 (lambda (out)
88 (let loop ((ch (read-char)))
89 (unless (eof-object? ch)
90 (display ch out)
91 (loop (read-char))))))))))
92 (delete-file "tmp.log")
93 s))
94
95 (define (error msg . args) (apply r6rs:error 'partcont msg args))
96
97 (include "partcont.scm")
98
99 (when (not (null? *discrepancies*))
100 (display (length *discrepancies*))
101 (display " discrepanci(es)")
102 (newline))