Debian Codegraph @

benchmarks.larceny/prefix/prefix-chicken.scm

raw symbols SCIP
1 ;INSERTCODE
2 ;------------------------------------------------------------------------------
3
4 (define (time* thunk)
5 (let* ((start (receive (u s) (cpu-time) (+ u s)))
6 (start-real (current-milliseconds)))
7 (let ((result (thunk)))
8 (let* ((end (receive (u s) (cpu-time) (+ u s)))
9 (end-real (current-milliseconds)))
10 (let ((cpu (- end start))
11 (real (- end-real start-real)))
12 (display "cpu time: ")
13 (display cpu)
14 (display " real time: ")
15 (display real)
16 (newline)
17 result)))))
18
19 (define (run-bench name count ok? run)
20 (let loop ((i count) (result '(undefined)))
21 (if (< 0 i)
22 (loop (- i 1) (run))
23 result)))
24
25 (define (run-benchmark name count ok? run-maker . args)
26 (newline)
27 (let* ((run (apply run-maker args))
28 (result (time* (lambda () (run-bench name count ok? run)))))
29 (if (not (ok? result))
30 (begin
31 (display "*** wrong result ***")
32 (newline)
33 (display "*** got: ")
34 (write result)
35 (newline))))
36 (exit 0))
37
38 (define (fatal-error . args)
39 (for-each display args)
40 (newline)
41 (exit 1))
42
43 (define (call-with-output-file/truncate filename proc)
44 (call-with-output-file filename proc))
45
46 ;------------------------------------------------------------------------------
47
48 ; Macros...
49
50 (define-macro (def-macro form . body)
51 `(define-macro ,form (let () ,@body)))
52
53 (if-fixflo
54
55 (begin
56
57 ; Specialize fixnum and flonum arithmetic.
58
59 ;; This code should be used when f64vectors are available.
60 ;(def-macro (FLOATvector-const . lst) `',(list->f64vector lst))
61 ;(def-macro (FLOATvector? x) `(f64vector? ,x))
62 ;(def-macro (FLOATvector . lst) `(f64vector ,@lst))
63 ;(def-macro (FLOATmake-vector n . init) `(make-f64vector ,n ,@init))
64 ;(def-macro (FLOATvector-ref v i) `(f64vector-ref ,v ,i))
65 ;(def-macro (FLOATvector-set! v i x) `(f64vector-set! ,v ,i ,x))
66 ;(def-macro (FLOATvector-length v) `(f64vector-length ,v))
67 ;
68 ;(def-macro (nuc-const . lst)
69 ; `',(list->vector
70 ; (map (lambda (x)
71 ; (if (vector? x)
72 ; (list->f64vector (vector->list x))
73 ; x))
74 ; lst)))
75
76 (def-macro (FLOATvector-const . lst) `',(list->vector lst))
77 (def-macro (FLOATvector? x) `(vector? ,x))
78 (def-macro (FLOATvector . lst) `(vector ,@lst))
79 (def-macro (FLOATmake-vector n . init) `(make-vector ,n ,@init))
80 (def-macro (FLOATvector-ref v i) `(vector-ref ,v ,i))
81 (def-macro (FLOATvector-set! v i x) `(vector-set! ,v ,i ,x))
82 (def-macro (FLOATvector-length v) `(vector-length ,v))
83
84 (def-macro (nuc-const . lst)
85 `',(list->vector lst))
86
87 (def-macro (FLOAT+ . lst) `(fp+ ,@lst))
88 (def-macro (FLOAT- . lst) (if (= (length lst) 1) `(fpneg ,@lst) `(fp- ,@lst)))
89 (def-macro (FLOAT* . lst) `(fp* ,@lst))
90 (def-macro (FLOAT/ . lst) (if (= (length lst) 1) `(fp/ 1.0 ,@lst) `(fp/ ,@lst)))
91 (def-macro (FLOAT= . lst) `(fp= ,@lst))
92 (def-macro (FLOAT< . lst) `(fp< ,@lst))
93 (def-macro (FLOAT<= . lst) `(fp<= ,@lst))
94 (def-macro (FLOAT> . lst) `(fp> ,@lst))
95 (def-macro (FLOAT>= . lst) `(fp>= ,@lst))
96 (def-macro (FLOATnegative? . lst) `(fp< ,@lst 0.0))
97 (def-macro (FLOATpositive? . lst) `(fp> ,@lst 0.0))
98 (def-macro (FLOATzero? . lst) `(fp= ,@lst 0.0))
99 (def-macro (FLOATabs . lst) `(abs ,@lst))
100 (def-macro (FLOATsin . lst) `(sin ,@lst))
101 (def-macro (FLOATcos . lst) `(cos ,@lst))
102 (def-macro (FLOATatan . lst) `(atan ,@lst))
103 (def-macro (FLOATsqrt . lst) `(sqrt ,@lst))
104 (def-macro (FLOATmin . lst) `(fpmin ,@lst))
105 (def-macro (FLOATmax . lst) `(fpmax ,@lst))
106 (def-macro (FLOATround . lst) `(round ,@lst))
107 (def-macro (FLOATinexact->exact . lst) `(inexact->exact ,@lst))
108
109 (define (GENERIC+ x y) (+ x y))
110 (define (GENERIC- x y) (- x y))
111 (define (GENERIC* x y) (* x y))
112 (define (GENERIC/ x y) (/ x y))
113 (define (GENERICquotient x y) (quotient x y))
114 (define (GENERICremainder x y) (remainder x y))
115 (define (GENERICmodulo x y) (modulo x y))
116 (define (GENERIC= x y) (= x y))
117 (define (GENERIC< x y) (< x y))
118 (define (GENERIC<= x y) (<= x y))
119 (define (GENERIC> x y) (> x y))
120 (define (GENERIC>= x y) (>= x y))
121 (define (GENERICexpt x y) (expt x y))
122
123 (def-macro (+ . lst) `(fx+ ,@lst))
124 (def-macro (- . lst) (if (= (length lst) 1) `(fxneg ,@lst) `(fx- ,@lst)))
125 (def-macro (* . lst) `(fx* ,@lst))
126 (def-macro (quotient . lst) `(fx/ ,@lst))
127 (def-macro (modulo . lst) `(fxmod ,@lst))
128 ;(def-macro (remainder . lst) `(remainder ,@lst))
129 (def-macro (= . lst) `(fx= ,@lst))
130 (def-macro (< . lst) `(fx< ,@lst))
131 (def-macro (<= . lst) `(fx<= ,@lst))
132 (def-macro (> . lst) `(fx> ,@lst))
133 (def-macro (>= . lst) `(fx>= ,@lst))
134 (def-macro (negative? . lst) `(fx< ,@lst 0))
135 (def-macro (positive? . lst) `(fx> ,@lst 0))
136 (def-macro (zero? . lst) `(fx= ,@lst 0))
137 (def-macro (odd? . lst) `(fx= (fxmod ,@lst 2) 1))
138 (def-macro (even? . lst) `(fx= (fxmod ,@lst 2) 0))
139 (def-macro (bitwise-or . lst) `(bitwise-ior ,@lst))
140 ;(def-macro (bitwise-and . lst) `(bitwise-and ,@lst))
141 ;(def-macro (bitwise-not . lst) `(bitwise-not ,@lst))
142 )
143
144 (begin
145
146 ; Don't specialize fixnum and flonum arithmetic.
147
148 (def-macro (FLOATvector-const . lst) `',(list->vector lst))
149 (def-macro (FLOATvector? x) `(vector? ,x))
150 (def-macro (FLOATvector . lst) `(vector ,@lst))
151 (def-macro (FLOATmake-vector n . init) `(make-vector ,n ,@init))
152 (def-macro (FLOATvector-ref v i) `(vector-ref ,v ,i))
153 (def-macro (FLOATvector-set! v i x) `(vector-set! ,v ,i ,x))
154 (def-macro (FLOATvector-length v) `(vector-length ,v))
155
156 (def-macro (nuc-const . lst)
157 `',(list->vector lst))
158
159 (def-macro (FLOAT+ . lst) `(+ ,@lst))
160 (def-macro (FLOAT- . lst) `(- ,@lst))
161 (def-macro (FLOAT* . lst) `(* ,@lst))
162 (def-macro (FLOAT/ . lst) `(/ ,@lst))
163 (def-macro (FLOAT= . lst) `(= ,@lst))
164 (def-macro (FLOAT< . lst) `(< ,@lst))
165 (def-macro (FLOAT<= . lst) `(<= ,@lst))
166 (def-macro (FLOAT> . lst) `(> ,@lst))
167 (def-macro (FLOAT>= . lst) `(>= ,@lst))
168 (def-macro (FLOATnegative? . lst) `(negative? ,@lst))
169 (def-macro (FLOATpositive? . lst) `(positive? ,@lst))
170 (def-macro (FLOATzero? . lst) `(zero? ,@lst))
171 (def-macro (FLOATabs . lst) `(abs ,@lst))
172 (def-macro (FLOATsin . lst) `(sin ,@lst))
173 (def-macro (FLOATcos . lst) `(cos ,@lst))
174 (def-macro (FLOATatan . lst) `(atan ,@lst))
175 (def-macro (FLOATsqrt . lst) `(sqrt ,@lst))
176 (def-macro (FLOATmin . lst) `(min ,@lst))
177 (def-macro (FLOATmax . lst) `(max ,@lst))
178 (def-macro (FLOATround . lst) `(round ,@lst))
179 (def-macro (FLOATinexact->exact . lst) `(inexact->exact ,@lst))
180
181 (def-macro (GENERIC+ . lst) `(+ ,@lst))
182 (def-macro (GENERIC- . lst) `(- ,@lst))
183 (def-macro (GENERIC* . lst) `(* ,@lst))
184 (def-macro (GENERIC/ . lst) `(/ ,@lst))
185 (def-macro (GENERICquotient . lst) `(quotient ,@lst))
186 (def-macro (GENERICremainder . lst) `(remainder ,@lst))
187 (def-macro (GENERICmodulo . lst) `(modulo ,@lst))
188 (def-macro (GENERIC= . lst) `(= ,@lst))
189 (def-macro (GENERIC< . lst) `(< ,@lst))
190 (def-macro (GENERIC<= . lst) `(<= ,@lst))
191 (def-macro (GENERIC> . lst) `(> ,@lst))
192 (def-macro (GENERIC>= . lst) `(>= ,@lst))
193 (def-macro (GENERICexpt . lst) `(expt ,@lst))
194 )
195 )
196
197 ;------------------------------------------------------------------------------