aboutsummaryrefslogtreecommitdiffstats
path: root/csc/linker-test.csc
blob: 3c24e90a021a67d7fdca07b34ea7a2e1377dde96 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
(define-library (csc linker-test)
  (import (scheme base)
          (only (csc format)
            sprintf)
          (only (csc hash-map)
            alist->map
            hash-bytevector
            make-comparer
            make-map)
          (only (csc list)
            all)
          (only (csc testing)
            assert-equal
            test)
          (csc linker))
  (begin


    (test link-labels
      (assert-equal
        '((alloc (local 0) (const 0))
          (jmp (const 1))
          (jmp (const 0)))
        (link
          '(((label 0)
             (jmp (label 1))
             (label 1)
             (jmp (label 0)))))))


    (test link-labels-are-unique-per-program
      (assert-equal
        '((alloc (local 0) (const 0))
          (jmp (const 0))
          (jmp (const 1)))
        (link
          '(((label 0)
             (jmp (label 0)))
            ((label 0)
             (jmp (label 0)))))))


    (test link-globals
      (assert-equal
        '((alloc (local 0) (const 11))
          (peek (local 1) (local 0) (const 10)))
        (link
          '(((peek (local 1) (local 0) (global cons (csc based)))))
          (alist->map compare-globals '(((global cons (csc based)) . 10))))))))