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 array-ref
131 (define (new-array-ref id index)
132 (make-array-ref #f '() 'byte id index)) ;; TODO the manual memory zone is byte indexed
134 (define-type-of-expr oper
136 (define (new-oper subasts type op)
139 (make-oper #f subasts type op)))
141 (define-type-of-expr call
143 (define (new-call subasts type proc-def)
146 (make-call #f subasts type proc-def)))
148 (define-type-of-ast block
149 name) ; blocks that begin with a label have a name, the other have #f
150 (define (new-block subasts)
153 (make-block #f subasts #f)))
154 (define (new-named-block name subasts)
157 (make-block #f subasts name)))
159 (define-type-of-ast if)
160 (define (new-if subasts)
163 (make-if #f subasts)))
165 (define-type-of-ast switch)
166 (define (new-switch subasts)
169 (make-switch #f subasts)))
171 (define-type-of-ast while)
172 (define (new-while subasts)
175 (make-while #f subasts)))
177 (define-type-of-ast do-while)
178 (define (new-do-while subasts)
181 (make-do-while #f subasts)))
183 (define-type-of-ast for)
184 (define (new-for subasts)
187 (make-for #f subasts)))
189 (define-type-of-ast return)
190 (define (new-return subasts)
193 (make-return #f subasts)))
195 (define-type-of-ast break)
199 (define-type-of-ast continue)
200 (define (new-continue)
201 (make-continue #f '()))
203 (define-type-of-ast goto)
204 (define (new-goto label)
205 (make-goto #f (list label)))
207 (define-type-of-ast program)
208 (define (new-program subasts) ;; TODO add suport for main
211 (make-program #f subasts)))
214 extender: define-type-of-op
215 (six-id unprintable:)
222 (define-type-of-op op1)
223 (define-type-of-op op2)