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 (define-type byte-cell
47 (interferes-with unprintable:)
48 (coalesceable-with unprintable:))
49 (define (new-byte-cell)
50 (make-byte-cell #f '() '()))
54 (define (new-byte-lit x)
57 (define (nb-bytes type)
60 ((int) 1) ;; TODO have more types
61 (else (error "wrong number of bytes ?"))))
63 (define (int->value n type)
64 (let ((len (nb-bytes type)))
65 (let loop ((len len) (n n) (rev-bytes '()))
67 (new-value (reverse rev-bytes))
69 (arithmetic-shift n -8)
70 (cons (new-byte-lit (modulo n 256))
73 (define (extend value type)
74 value);;;;;;;;;;;;;;;;;;;;;
76 (define (alloc-value type)
77 (let ((len (nb-bytes type)))
78 (let loop ((len len) (rev-bytes '()))
80 (new-value (reverse rev-bytes)) ;; TODO why reverse, everything is empty
85 (define-type-of-def def-variable
90 (define (new-def-variable subasts id refs type value sets)
93 (make-def-variable #f subasts id refs type value sets)))
95 (define-type-of-def def-procedure
101 (define (new-def-procedure subasts id refs type value params)
104 (make-def-procedure #f subasts id refs type value params #f '())))
107 (define-type-of-ast expr
108 extender: define-type-of-expr
111 (define-type-of-expr literal
113 (define (new-literal type val)
114 (make-literal #f '() type val))
116 (define-type-of-expr ref
118 (define (new-ref type def)
119 (make-ref #f '() type def))
121 (define-type-of-expr oper
123 (define (new-oper subasts type op)
126 (make-oper #f subasts type op)))
128 (define-type-of-expr call
130 (define (new-call subasts type proc-def)
133 (make-call #f subasts type proc-def)))
135 (define-type-of-ast block
136 name) ; blocks that begin with a label have a name, the other have #f
137 (define (new-block subasts)
140 (make-block #f subasts #f)))
141 (define (new-named-block name subasts)
144 (make-block #f subasts name)))
146 (define-type-of-ast if)
147 (define (new-if subasts)
150 (make-if #f subasts)))
152 (define-type-of-ast switch)
153 (define (new-switch subasts)
156 (make-switch #f subasts)))
158 (define-type-of-ast while)
159 (define (new-while subasts)
162 (make-while #f subasts)))
164 (define-type-of-ast do-while)
165 (define (new-do-while subasts)
168 (make-do-while #f subasts)))
170 (define-type-of-ast for)
171 (define (new-for subasts)
174 (make-for #f subasts)))
176 (define-type-of-ast return)
177 (define (new-return subasts)
180 (make-return #f subasts)))
182 (define-type-of-ast break)
186 (define-type-of-ast continue)
187 (define (new-continue)
188 (make-continue #f '()))
190 (define-type-of-ast goto)
191 (define (new-goto label)
192 (make-goto #f (list label)))
194 (define-type-of-ast program)
195 (define (new-program subasts) ;; TODO add suport for main
198 (make-program #f subasts)))
201 extender: define-type-of-op
202 (six-id unprintable:)
209 (define-type-of-op op1)
210 (define-type-of-op op2)