prefix-gambit.scm 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. ;INSERTCODE
  2. ;------------------------------------------------------------------------------
  3. (define (run-bench name count ok? run)
  4. (let loop ((i count) (result '(undefined)))
  5. (if (< 0 i)
  6. (loop (- i 1) (run))
  7. result)))
  8. (define (run-benchmark name count ok? run-maker . args)
  9. (newline)
  10. (let* ((run (apply run-maker args))
  11. (result (time (run-bench name count ok? run))))
  12. (if (not (ok? result))
  13. (begin
  14. (display "*** wrong result ***")
  15. (newline)
  16. (display "*** got: ")
  17. (write result)
  18. (newline))))
  19. (exit 0))
  20. (define (fatal-error . args)
  21. (for-each display args)
  22. (newline)
  23. (exit 1))
  24. (define (call-with-output-file/truncate filename proc)
  25. (call-with-output-file filename proc))
  26. ;------------------------------------------------------------------------------
  27. ; Macros...
  28. (##define-macro (def-macro form . body)
  29. `(##define-macro ,form (let () ,@body)))
  30. (if-fixflo
  31. (begin
  32. ; Specialize fixnum and flonum arithmetic.
  33. ;; This code should be used when f64vectors are available.
  34. ;(def-macro (FLOATvector-const . lst) `',(list->f64vector lst))
  35. ;(def-macro (FLOATvector? x) `(f64vector? ,x))
  36. ;(def-macro (FLOATvector . lst) `(f64vector ,@lst))
  37. ;(def-macro (FLOATmake-vector n . init) `(make-f64vector ,n ,@init))
  38. ;(def-macro (FLOATvector-ref v i) `(f64vector-ref ,v ,i))
  39. ;(def-macro (FLOATvector-set! v i x) `(f64vector-set! ,v ,i ,x))
  40. ;(def-macro (FLOATvector-length v) `(f64vector-length ,v))
  41. ;
  42. ;(def-macro (nuc-const . lst)
  43. ; `',(list->vector
  44. ; (map (lambda (x)
  45. ; (if (vector? x)
  46. ; (list->f64vector (vector->list x))
  47. ; x))
  48. ; lst)))
  49. (def-macro (FLOATvector-const . lst) `',(list->vector lst))
  50. (def-macro (FLOATvector? x) `(vector? ,x))
  51. (def-macro (FLOATvector . lst) `(vector ,@lst))
  52. (def-macro (FLOATmake-vector n . init) `(make-vector ,n ,@init))
  53. (def-macro (FLOATvector-ref v i) `(vector-ref ,v ,i))
  54. (def-macro (FLOATvector-set! v i x) `(vector-set! ,v ,i ,x))
  55. (def-macro (FLOATvector-length v) `(vector-length ,v))
  56. (def-macro (nuc-const . lst)
  57. `',(list->vector lst))
  58. (def-macro (FLOAT+ . lst) `(fl+ ,@lst))
  59. (def-macro (FLOAT- . lst) `(fl- ,@lst))
  60. (def-macro (FLOAT* . lst) `(fl* ,@lst))
  61. (def-macro (FLOAT/ . lst) `(fl/ ,@lst))
  62. (def-macro (FLOAT= . lst) `(fl= ,@lst))
  63. (def-macro (FLOAT< . lst) `(fl< ,@lst))
  64. (def-macro (FLOAT<= . lst) `(fl<= ,@lst))
  65. (def-macro (FLOAT> . lst) `(fl> ,@lst))
  66. (def-macro (FLOAT>= . lst) `(fl>= ,@lst))
  67. (def-macro (FLOATnegative? . lst) `(flnegative? ,@lst))
  68. (def-macro (FLOATpositive? . lst) `(flpositive? ,@lst))
  69. (def-macro (FLOATzero? . lst) `(flzero? ,@lst))
  70. (def-macro (FLOATabs . lst) `(flabs ,@lst))
  71. (def-macro (FLOATsin . lst) `(flsin ,@lst))
  72. (def-macro (FLOATcos . lst) `(flcos ,@lst))
  73. (def-macro (FLOATatan . lst) `(flatan ,@lst))
  74. (def-macro (FLOATsqrt . lst) `(flsqrt ,@lst))
  75. (def-macro (FLOATmin . lst) `(flmin ,@lst))
  76. (def-macro (FLOATmax . lst) `(flmax ,@lst))
  77. (def-macro (FLOATround . lst) `(flround ,@lst))
  78. (def-macro (FLOATinexact->exact . lst) `(inexact->exact ,@lst))
  79. (define (GENERIC+ x y) (+ x y))
  80. (define (GENERIC- x y) (- x y))
  81. (define (GENERIC* x y) (* x y))
  82. (define (GENERIC/ x y) (/ x y))
  83. (define (GENERICquotient x y) (quotient x y))
  84. (define (GENERICremainder x y) (remainder x y))
  85. (define (GENERICmodulo x y) (modulo x y))
  86. (define (GENERIC= x y) (= x y))
  87. (define (GENERIC< x y) (< x y))
  88. (define (GENERIC<= x y) (<= x y))
  89. (define (GENERIC> x y) (> x y))
  90. (define (GENERIC>= x y) (>= x y))
  91. (define (GENERICexpt x y) (expt x y))
  92. (def-macro (+ . lst) `(fxwrap+ ,@lst))
  93. (def-macro (- . lst) `(fxwrap- ,@lst))
  94. (def-macro (* . lst) `(fxwrap* ,@lst))
  95. (def-macro (quotient . lst) `(fxwrapquotient ,@lst))
  96. (def-macro (modulo . lst) `(fxmodulo ,@lst))
  97. (def-macro (remainder . lst) `(fxremainder ,@lst))
  98. (def-macro (= . lst) `(fx= ,@lst))
  99. (def-macro (< . lst) `(fx< ,@lst))
  100. (def-macro (<= . lst) `(fx<= ,@lst))
  101. (def-macro (> . lst) `(fx> ,@lst))
  102. (def-macro (>= . lst) `(fx>= ,@lst))
  103. (def-macro (negative? . lst) `(fxnegative? ,@lst))
  104. (def-macro (positive? . lst) `(fxpositive? ,@lst))
  105. (def-macro (zero? . lst) `(fxzero? ,@lst))
  106. (def-macro (odd? . lst) `(fxodd? ,@lst))
  107. (def-macro (even? . lst) `(fxeven? ,@lst))
  108. (def-macro (bitwise-or . lst) `(fxior ,@lst))
  109. (def-macro (bitwise-and . lst) `(fxand ,@lst))
  110. (def-macro (bitwise-not . lst) `(fxnot ,@lst))
  111. )
  112. (begin
  113. ; Don't specialize fixnum and flonum arithmetic.
  114. (def-macro (FLOATvector-const . lst) `',(list->vector lst))
  115. (def-macro (FLOATvector? x) `(vector? ,x))
  116. (def-macro (FLOATvector . lst) `(vector ,@lst))
  117. (def-macro (FLOATmake-vector n . init) `(make-vector ,n ,@init))
  118. (def-macro (FLOATvector-ref v i) `(vector-ref ,v ,i))
  119. (def-macro (FLOATvector-set! v i x) `(vector-set! ,v ,i ,x))
  120. (def-macro (FLOATvector-length v) `(vector-length ,v))
  121. (def-macro (nuc-const . lst)
  122. `',(list->vector lst))
  123. (def-macro (FLOAT+ . lst) `(+ ,@lst))
  124. (def-macro (FLOAT- . lst) `(- ,@lst))
  125. (def-macro (FLOAT* . lst) `(* ,@lst))
  126. (def-macro (FLOAT/ . lst) `(/ ,@lst))
  127. (def-macro (FLOAT= . lst) `(= ,@lst))
  128. (def-macro (FLOAT< . lst) `(< ,@lst))
  129. (def-macro (FLOAT<= . lst) `(<= ,@lst))
  130. (def-macro (FLOAT> . lst) `(> ,@lst))
  131. (def-macro (FLOAT>= . lst) `(>= ,@lst))
  132. (def-macro (FLOATnegative? . lst) `(negative? ,@lst))
  133. (def-macro (FLOATpositive? . lst) `(positive? ,@lst))
  134. (def-macro (FLOATzero? . lst) `(zero? ,@lst))
  135. (def-macro (FLOATabs . lst) `(abs ,@lst))
  136. (def-macro (FLOATsin . lst) `(sin ,@lst))
  137. (def-macro (FLOATcos . lst) `(cos ,@lst))
  138. (def-macro (FLOATatan . lst) `(atan ,@lst))
  139. (def-macro (FLOATsqrt . lst) `(sqrt ,@lst))
  140. (def-macro (FLOATmin . lst) `(min ,@lst))
  141. (def-macro (FLOATmax . lst) `(max ,@lst))
  142. (def-macro (FLOATround . lst) `(round ,@lst))
  143. (def-macro (FLOATinexact->exact . lst) `(inexact->exact ,@lst))
  144. (def-macro (GENERIC+ . lst) `(+ ,@lst))
  145. (def-macro (GENERIC- . lst) `(- ,@lst))
  146. (def-macro (GENERIC* . lst) `(* ,@lst))
  147. (def-macro (GENERIC/ . lst) `(/ ,@lst))
  148. (def-macro (GENERICquotient . lst) `(quotient ,@lst))
  149. (def-macro (GENERICremainder . lst) `(remainder ,@lst))
  150. (def-macro (GENERICmodulo . lst) `(modulo ,@lst))
  151. (def-macro (GENERIC= . lst) `(= ,@lst))
  152. (def-macro (GENERIC< . lst) `(< ,@lst))
  153. (def-macro (GENERIC<= . lst) `(<= ,@lst))
  154. (def-macro (GENERIC> . lst) `(> ,@lst))
  155. (def-macro (GENERIC>= . lst) `(>= ,@lst))
  156. (def-macro (GENERICexpt . lst) `(expt ,@lst))
  157. )
  158. )
  159. ;------------------------------------------------------------------------------