aboutsummaryrefslogtreecommitdiffstats
path: root/csc/ir2.csc
blob: 708d7b140e7d691d4a51443802504134aabbdc0d (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
50
51
52
53
54
55
56
57
58
59
(define-library (csc ir2)
  (export
    atom-continuation
    atom-expression
    atom?
    ir2=?
    make-atom
    make-tail
    tail?

    ; Re-exports from IR1.
    constant-expression
    constant?
    make-constant)
  (import (scheme base)
          (only (csc ir1)
            constant?
            ir1=?
            make-constant))
  (begin
    ; This library defines the intermediate representation IR2.
    ; It's CPS time bitch.


    ; CPS expressions.


    ; An atom consists of an ir1 expression and a continuation.
    (define-record-type <atom>
      (make-atom expression continuation)
      atom?
      (expression atom-expression)
      (continuation atom-continuation))


    ; CPS continuations.


    ; tail is the tail continuation.
    (define-record-type <tail>
      (make-tail)
      tail?)


    (define (ir2=?-sametype x y)
      (cond
        ((and (atom? x) (atom? y))
          (and (ir1=? (atom-expression x) (atom-expression y))
               (ir2=? (atom-continuation x) (atom-continuation y))))
        ((and (tail? x) (tail? y)) #t)
        (else #f)))


    (define (ir2=? x y)
      (cond
        ((ir2=?-sametype x y) #t)
        ((and (ir2=?-sametype x x) (ir2=?-sametype y y))
          #f)
        (else (error "One or more arguments has a type unknown to ir2=?" x y))))))