3 (define (castable? from to)
8 (foldl (lambda (x y) (or x (castable? from y)))
10 '(byte int8 int16 int32)))
13 ;; TODO ajouter casts vers byte, int16, etc
16 (define operators '())
18 (define (define-op1 six-id id type-rule constant-fold code-gen)
20 (cons (make-op1 six-id id type-rule constant-fold code-gen)
23 (define (define-op2 six-id id type-rule constant-fold code-gen)
25 (cons (make-op2 six-id id type-rule constant-fold code-gen)
28 (define (type-rule-int-op1 ast)
29 (let ((t1 (expr-type (subast1 ast))))
30 (cond ((castable? t1 'int)
33 (error "int-op1: type error" ast)))))
35 (define (type-rule-int-op2 ast)
36 (let ((t1 (expr-type (subast1 ast)))
37 (t2 (expr-type (subast2 ast))))
38 (cond ((and (castable? t1 'int) (castable? t2 'int))
41 (error "int-op2: type error" ast)))))
43 (define (type-rule-int-assign ast) ;; TODO why the int in the name ?
44 (let ((t1 (expr-type (subast1 ast)))
45 (t2 (expr-type (subast2 ast))))
46 (if (not (castable? t1 t2))
47 (error "int-assign: type error" ast))
50 (define (type-rule-int-comp-op2 ast)
51 (let ((t1 (expr-type (subast1 ast)))
52 (t2 (expr-type (subast2 ast))))
53 (cond ((and (castable? t1 'int) (castable? t2 'int))
56 (error "int-comp-op2: type error" ast)))))
58 (define (type-rule-bool-op2 ast)
59 (let ((t1 (expr-type (subast1 ast)))
60 (t2 (expr-type (subast2 ast))))
61 (cond ((and (castable? t1 bool) (castable? t2 bool))
64 (error "bool-op2: type error" ast)))))
66 (define-op1 'six.!x '!x
68 (lambda (ast) ;; TODO implement these
73 (define-op1 'six.++x '++x
80 (define-op1 'six.x++ 'x++
87 (define-op1 'six.--x '--x
94 (define-op1 'six.x-- 'x--
101 (define-op1 'six.~x '~x
108 (define-op2 'six.x%y 'x%y
115 (define-op2 'six.x*y 'x*y
122 (define-op1 'six.*x '*x
130 (define-op2 'six.x/y 'x/y
137 (define-op2 'six.x+y 'x+y
144 (define-op1 'six.+x '+x
151 (define-op2 'six.x-y 'x-y
158 (define-op1 'six.-x '-x
165 (define-op2 'six.x<<y 'x<<y
172 (define-op2 'six.x>>y 'x>>y
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
201 type-rule-int-comp-op2
207 (define-op2 'six.x!=y 'x!=y
208 type-rule-int-comp-op2
214 (define-op2 'six.x==y 'x==y
215 type-rule-int-comp-op2
221 (define-op2 'six.x&y 'x&y
228 (define-op1 'six.&x '&x
236 (define-op2 'six.x^y 'x^y
243 (define-op2 '|six.x\|y| '|x\|y|
250 (define-op2 'six.x&&y 'x&&y
257 (define-op2 '|six.x\|\|y| '|x\|\|y|
264 (define-op2 'six.x?y:z 'x?y:z
272 (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
343 (define-op2 'six.x^=y 'x^=y
350 (define-op2 '|six.x\|=y| '|x\|=y|
357 (define-op2 'six.x:=y 'x:=y
365 (define-op2 '|six.x,y| '|x,y|
373 (define-op2 'six.x:-y 'x:-y
381 (define (operation? source)
383 (let ((x (car source)))
384 (let loop ((lst operators))
387 ((eq? (op-six-id (car lst)) x)
390 (loop (cdr lst))))))))