1 ;;; definition of ast types
4 extender: define-type-of-ast
8 (define (link-parent! subast parent)
9 (ast-parent-set! subast parent)
12 (define (multi-link-parent! subasts parent)
13 (for-each (lambda (subast) (link-parent! subast parent))
17 (define (unlink-parent! subast)
18 (let ((parent (ast-parent subast)))
19 (if (and (def-variable? subast) (def-procedure? parent))
20 (def-procedure-params-set!
22 (remove subast (def-procedure-params parent)))
25 (remove subast (ast-subasts parent))))
26 (ast-parent-set! subast #f)
29 (define (subast1 ast) (car (ast-subasts ast)))
30 (define (subast2 ast) (cadr (ast-subasts ast)))
31 (define (subast3 ast) (caddr (ast-subasts ast)))
32 (define (subast4 ast) (cadddr (ast-subasts ast)))
34 (define-type-of-ast def
35 extender: define-type-of-def
42 (define (new-value bytes)
45 ;; TODO really in ast ?
46 (define-type byte-cell
48 (interferes-with unprintable:)
49 (coalesceable-with unprintable:))
50 (define (new-byte-cell)
51 (make-byte-cell #f '() '()))
52 (define (get-register n)
53 (make-byte-cell n '() '()))
57 (define (new-byte-lit x)
60 (define (nb-bytes type)
62 ((void) 0) ;; TODO have more types
67 ((int) 4) ;; TODO should the default int be 32 bits ?
68 (else (error "wrong number of bytes ?"))))
70 (define (int->value n type)
71 (let ((len (nb-bytes type)))
72 (let loop ((len len) (n n) (rev-bytes '()))
74 (new-value (reverse rev-bytes))
76 (arithmetic-shift n -8)
77 (cons (new-byte-lit (modulo n 256))
80 (define (extend value type)
81 value);;;;;;;;;;;;;;;;;;;;;
83 (define (alloc-value type)
84 (let ((len (nb-bytes type)))
85 (let loop ((len len) (rev-bytes '()))
87 (new-value (reverse rev-bytes)) ;; TODO why reverse, everything is empty
92 (define-type-of-def def-variable
97 (define (new-def-variable subasts id refs type value sets)
100 (make-def-variable #f subasts id refs type value sets)))
102 (define-type-of-def def-procedure
108 (define (new-def-procedure subasts id refs type value params)
111 (make-def-procedure #f subasts id refs type value params #f '())))
114 (define-type-of-ast expr
115 extender: define-type-of-expr
118 (define-type-of-expr literal
120 (define (new-literal type val)
121 (make-literal #f '() type val))
123 (define-type-of-expr ref
125 (define (new-ref type def)
126 (make-ref #f '() type def))
128 (define-type-of-expr oper
130 (define (new-oper subasts type op)
133 (make-oper #f subasts type op)))
135 (define-type-of-expr call
137 (define (new-call subasts type proc-def)
140 (make-call #f subasts type proc-def)))
142 (define-type-of-ast block
143 name) ; blocks that begin with a label have a name, the other have #f
144 (define (new-block subasts)
147 (make-block #f subasts #f)))
148 (define (new-named-block name subasts)
151 (make-block #f subasts name)))
153 (define-type-of-ast if)
154 (define (new-if subasts)
157 (make-if #f subasts)))
159 (define-type-of-ast switch)
160 (define (new-switch subasts)
163 (make-switch #f subasts)))
165 (define-type-of-ast while)
166 (define (new-while subasts)
169 (make-while #f subasts)))
171 (define-type-of-ast do-while)
172 (define (new-do-while subasts)
175 (make-do-while #f subasts)))
177 (define-type-of-ast for)
178 (define (new-for subasts)
181 (make-for #f subasts)))
183 (define-type-of-ast return)
184 (define (new-return subasts)
187 (make-return #f subasts)))
189 (define-type-of-ast break)
193 (define-type-of-ast continue)
194 (define (new-continue)
195 (make-continue #f '()))
197 (define-type-of-ast goto)
198 (define (new-goto label)
199 (make-goto #f (list label)))
201 (define-type-of-ast program)
202 (define (new-program subasts) ;; TODO add suport for main
205 (make-program #f subasts)))
208 extender: define-type-of-op
209 (six-id unprintable:)
216 (define-type-of-op op1)
217 (define-type-of-op op2)