Debian Codegraph @

test/compiler-alt.scm

raw
1 ;;
2 ;; Test alternative compiler backend
3 ;;
4 ;; The modules tested here is not yet in the production
5
6 (use gauche.test)
7 (test-start "alternative compiler backend")
8
9 (test-section "modules")
10 (use gauche.vm.bbb)
11 (test-module 'gauche.vm.bbb)
12
13 (use gauche.vm.register-machine)
14 (test-module 'gauche.vm.register-machine)
15
16 (use gauche.cgen.cbe)
17 (test-module 'gauche.cgen.cbe)
18
19
20 (test-section "simple code")
21
22 (define (t msg module expect program)
23 (test* msg expect
24 (if module
25 (run-on-register-machine program module)
26 (run-on-register-machine program))))
27
28
29 (t "simple expression" #f "abcxyz"
30 '(string-append (list->string '(#\a #\b #\c))
31 "xyz"))
32
33 (t "calling inlined numerics" #f 5
34 '(+ (* 2 3) (/ (- 4 5 6) 7)))
35
36 (let ((mod (make-module #f)))
37 (t "simple expression, definition 1" mod 'add-one
38 '(define (add-one n) (+ 1 n)))
39 (t "simple expression, definition 2" mod 'add-two
40 '(define (add-two n) (+ 2 n)))
41 (t "simple expression, calling defined ones" mod 20402
42 '(* (add-one 100) (add-two 200)))
43
44 (t "local bindings" mod '(-3 -6)
45 '(let ((a (add-one 4)) (b (add-two 5)))
46 (list (add-two (- a)) (add-one (- b)))))
47 )
48
49 (t "$IT node handling" #f '(2 1 #f)
50 '(begin
51 (define (foo a b c) (and a (or b c)))
52 (list (foo #t #f 2)
53 (foo #t 1 2)
54 (foo #f 3 4))))
55
56 (t "letrec and loop" #f
57 '(1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17
58 Fizz 19 Buzz)
59 '(let loop ((n 1) (r '()))
60 (cond [(> n 20) (reverse r)]
61 [(zero? (modulo n 15)) (loop (+ n 1) (cons 'FizzBuzz r))]
62 [(zero? (modulo n 3)) (loop (+ n 1) (cons 'Fizz r))]
63 [(zero? (modulo n 5)) (loop (+ n 1) (cons 'Buzz r))]
64 [else (loop (+ n 1) (cons n r))])))
65
66 (t "letrec and recursive call" #f 21
67 '(let fib ((n 7))
68 (if (< n 2) 1 (+ (fib (- n 1)) (fib (- n 2))))))
69
70 (t "bulitin ops" #f '(A (1 2) 1 1 2 Z)
71 '(let ((x (list 1 2)))
72 `(A ,x ,(car x) ,@x Z)))
73
74 (t "case-lambda" #f '(a (b . 1) 2 (c 1 2 3) 4)
75 '(begin
76 (define f (case-lambda
77 [() 'a]
78 [(x) (cons 'b x)]
79 [(x y z) (list 'c x y z)]
80 [xs (length xs)]))
81 (list (f) (f 1) (f 1 2) (f 1 2 3) (f 1 2 3 4))))
82
83 (test-end)