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 "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 "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 "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 "type error" ast)))))
45 (define-op1 'six.!x '!x
47 (lambda (ast) ;; TODO implement these
52 (define-op1 'six.++x '++x
59 (define-op1 'six.x++ 'x++
66 (define-op1 'six.--x '--x
73 (define-op1 'six.x-- 'x--
80 (define-op1 'six.~x '~x
87 (define-op2 'six.x%y 'x%y
94 (define-op2 'six.x*y 'x*y
101 (define-op1 'six.*x '*x
109 (define-op2 'six.x/y 'x/y
116 (define-op2 'six.x+y 'x+y
123 (define-op1 'six.+x '+x
130 (define-op2 'six.x-y 'x-y
137 (define-op1 'six.-x '-x
144 (define-op2 'six.x<<y 'x<<y
151 (define-op2 'six.x>>y 'x>>y
158 (define-op2 'six.x<y 'x<y
159 type-rule-int-comp-op2
165 (define-op2 'six.x<=y 'x<=y
166 type-rule-int-comp-op2
172 (define-op2 'six.x>y 'x>y
173 type-rule-int-comp-op2
179 (define-op2 'six.x>=y 'x>=y
180 type-rule-int-comp-op2
186 (define-op2 'six.x!=y 'x!=y
187 type-rule-int-comp-op2
193 (define-op2 'six.x==y 'x==y
194 type-rule-int-comp-op2
200 (define-op2 'six.x&y 'x&y
207 (define-op1 'six.&x '&x
215 (define-op2 'six.x^y 'x^y
222 (define-op2 '|six.x\|y| '|x\|y|
229 (define-op2 'six.x&&y 'x&&y
236 (define-op2 '|six.x\|\|y| '|x\|\|y|
243 (define-op2 'six.x?y:z 'x?y:z
251 (define-op2 'six.x:y 'x:y
259 (define-op2 'six.x%=y 'x%=y
266 (define-op2 'six.x&=y 'x&=y
273 (define-op2 'six.x*=y 'x*=y
280 (define-op2 'six.x+=y 'x+=y
287 (define-op2 'six.x-=y 'x-=y
294 (define-op2 'six.x/=y 'x/=y
301 (define-op2 'six.x<<=y 'x<<=y
308 (define-op2 'six.x=y 'x=y
315 (define-op2 'six.x>>=y 'x>>=y
322 (define-op2 'six.x^=y 'x^=y
329 (define-op2 '|six.x\|=y| '|x\|=y|
336 (define-op2 'six.x:=y 'x:=y
344 (define-op2 '|six.x,y| '|x,y|
352 (define-op2 'six.x:-y 'x:-y
360 (define (operation? source)
362 (let ((x (car source)))
363 (let loop ((lst operators))
366 ((eq? (op-six-id (car lst)) x)
369 (loop (cdr lst))))))))