summaryrefslogtreecommitdiff
path: root/cfn/main.scm
blob: 3853b03f0f5eb5be68ffde981ce90362fd57ca92 (about) (plain)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
;;; main.scm -- main entry point for CFN pass
;;;
;;; author :  Sandra Loosemore
;;; date   :  27 Feb 1992
;;;


;;;===================================================================
;;; Basic support
;;;===================================================================


;;; Define the basic walker and some helper functions.

(define-walker cfn ast-td-cfn-walker)

(define (cfn-ast-1 x)
  (call-walker cfn x))

(define (cfn-ast/list l)
  (map (lambda (x) (cfn-ast-1 x)) l))


;;; This is the main entry point.  It is called by the driver on
;;; each top-level decl in the module.

(define (cfn-ast x)
  (let ((result  (cfn-ast-1 x)))
;    (pprint result)  ;*** debug
    result))



;;;===================================================================
;;; Default traversal methods
;;;===================================================================


(define-local-syntax (make-cfn-code slot type)
  (let ((stype  (sd-type slot))
        (sname  (sd-name slot)))
    (cond ((and (symbol? stype)
                (or (eq? stype 'exp)
                    (subtype? stype 'exp)))
           `(setf (struct-slot ',type ',sname object)
                  (cfn-ast-1 (struct-slot ',type ',sname object))))
          ((and (pair? stype)
                (eq? (car stype) 'list)
                (symbol? (cadr stype))
                (or (eq? (cadr stype) 'exp)
                    (subtype? (cadr stype) 'exp)))
           `(setf (struct-slot ',type ',sname object)
                  (cfn-ast/list (struct-slot ',type ',sname object))))
          ((and (pair? stype)
                (eq? (car stype) 'list)
                (eq? (cadr stype) 'decl))
           `(setf (struct-slot ',type ',sname object)
                  (cfn-valdef-list (struct-slot ',type ',sname object))))
          (else
;          (format '#t "Cfn: skipping slot ~A in ~A~%"
;                  (sd-name slot)
;                  type)
           '#f))))

(define-modify-walker-methods cfn
  (let if
   exp-sign
   app
   var-ref con-ref
   integer-const float-const char-const string-const
   con-number sel is-constructor
   void
   case-block return-from and-exp
   )
  (object)
  make-cfn-code)


;;; These have specialized walkers:
;;; lambda, case, valdef, list-comp  (pattern.scm)
;;; list-exp, list-comp, section-l, section-r, dict-placeholder,
;;; recursive-placeholder, save-old-exp (misc.scm)