5 (define (define-op1 six-id id type-rule constant-fold code-gen)
7 (cons (make-op1 six-id id type-rule constant-fold code-gen)
10 (define (define-op2 six-id id type-rule constant-fold code-gen)
12 (cons (make-op2 six-id id type-rule constant-fold code-gen)
15 (define (type-rule-int-op1 ast)
16 (let ((t1 (expr-type (subast1 ast))))
18 'int) ; TODO add support for other types
20 (error "int-op1: type error" ast)))))
22 (define (type-rule-int-op2 ast)
23 (let ((t1 (expr-type (subast1 ast)))
24 (t2 (expr-type (subast2 ast))))
25 (cond ((and (eq? t1 'int) (eq? t2 'int)) ; TODO are there any operations that do otherwise ? add cast support also
28 (error "int-op2: type error" ast)))))
30 (define (type-rule-int-assign ast) ;; TODO add cast support, and why the int in the name ?
31 (let ((t1 (expr-type (subast1 ast)))
32 (t2 (expr-type (subast2 ast))))
34 (error "int-assign: type error" ast))
37 (define (type-rule-int-comp-op2 ast)
38 (let ((t1 (expr-type (subast1 ast)))
39 (t2 (expr-type (subast2 ast))))
40 (cond ((and (eq? t1 'int) (eq? t2 'int))
43 (error "int-comp-op2: type error" ast)))))
45 (define (type-rule-bool-op2 ast)
46 (let ((t1 (expr-type (subast1 ast)))
47 (t2 (expr-type (subast2 ast))))
48 (cond ((or (and (eq? t1 'bool) (eq? t2 'bool))
49 (and (eq? t1 'bool) (eq? t2 'int)) ; ints can be cast to bools
50 (and (eq? t1 'int) (eq? t2 'bool)))
53 (error "bool-op2: type error" ast)))))
55 (define-op1 'six.!x '!x
57 (lambda (ast) ;; TODO implement these
62 (define-op1 'six.++x '++x
69 (define-op1 'six.x++ 'x++
76 (define-op1 'six.--x '--x
83 (define-op1 'six.x-- 'x--
90 (define-op1 'six.~x '~x
97 (define-op2 'six.x%y 'x%y
104 (define-op2 'six.x*y 'x*y
111 (define-op1 'six.*x '*x
119 (define-op2 'six.x/y 'x/y
126 (define-op2 'six.x+y 'x+y
133 (define-op1 'six.+x '+x
140 (define-op2 'six.x-y 'x-y
147 (define-op1 'six.-x '-x
154 (define-op2 'six.x<<y 'x<<y
161 (define-op2 'six.x>>y 'x>>y
168 (define-op2 'six.x<y 'x<y
169 type-rule-int-comp-op2
175 (define-op2 'six.x<=y 'x<=y
176 type-rule-int-comp-op2
182 (define-op2 'six.x>y 'x>y
183 type-rule-int-comp-op2
189 (define-op2 'six.x>=y 'x>=y
190 type-rule-int-comp-op2
196 (define-op2 'six.x!=y 'x!=y
197 type-rule-int-comp-op2
203 (define-op2 'six.x==y 'x==y
204 type-rule-int-comp-op2
210 (define-op2 'six.x&y 'x&y
217 (define-op1 'six.&x '&x
225 (define-op2 'six.x^y 'x^y
232 (define-op2 '|six.x\|y| '|x\|y|
239 (define-op2 'six.x&&y 'x&&y
246 (define-op2 '|six.x\|\|y| '|x\|\|y|
253 (define-op2 'six.x?y:z 'x?y:z
261 (define-op2 'six.x:y 'x:y
269 (define-op2 'six.x%=y 'x%=y
276 (define-op2 'six.x&=y 'x&=y
283 (define-op2 'six.x*=y 'x*=y
290 (define-op2 'six.x+=y 'x+=y
297 (define-op2 'six.x-=y 'x-=y
304 (define-op2 'six.x/=y 'x/=y
311 (define-op2 'six.x<<=y 'x<<=y
318 (define-op2 'six.x=y 'x=y
325 (define-op2 'six.x>>=y 'x>>=y
332 (define-op2 'six.x^=y 'x^=y
339 (define-op2 '|six.x\|=y| '|x\|=y|
346 (define-op2 'six.x:=y 'x:=y
354 (define-op2 '|six.x,y| '|x,y|
362 (define-op2 'six.x:-y 'x:-y
370 (define (operation? source)
372 (let ((x (car source)))
373 (let loop ((lst operators))
376 ((eq? (op-six-id (car lst)) x)
379 (loop (cdr lst))))))))