5 (define (define-op constructor six-id id type-rule constant-fold code-gen)
7 (cons (constructor six-id id type-rule constant-fold code-gen)
9 (define (define-op1 six-id id type-rule constant-fold code-gen)
10 (define-op make-op1 six-id id type-rule constant-fold code-gen))
11 (define (define-op2 six-id id type-rule constant-fold code-gen)
12 (define-op make-op2 six-id id type-rule constant-fold code-gen))
13 (define (define-op3 six-id id type-rule constant-fold code-gen)
14 (define-op make-op3 six-id id type-rule constant-fold code-gen))
16 ;; no need for type checks, every type sixpic supports can be casted to / from
17 ;; ints (except void, but this is a non-issue) and promotion (by padding) and
18 ;; truncation is done at the cfg level
19 (define (type-rule-int-op1 ast)
20 (expr-type (subast1 ast)))
22 (define (largest t1 t2)
23 (if (> (type->bytes t1) (type->bytes t2))
27 (define (type-rule-int-op2 ast)
28 ;; used for any binary operation involving two integers where the result is
29 ;; of the size of the biggest operand (subtraction, bitwise operations, ...)
30 (let ((t1 (expr-type (subast1 ast)))
31 (t2 (expr-type (subast2 ast))))
34 (define (type-rule-assign ast)
35 (let ((t1 (expr-type (subast1 ast))))
36 ;; the type of the rhs is irrelevant, since it will be promoted
37 ;; or truncated at the cfg level
40 (define (type-rule-int-comp-op2 ast)
43 (define (type-rule-bool-op2 ast)
46 (define-op1 'six.!x '!x
48 (lambda (ast) ;; TODO implement these ?
54 (define-op1 'six.++x '++x
61 (define-op1 'six.x++ 'x++
68 (define-op1 'six.--x '--x
75 (define-op1 'six.x-- 'x--
82 (define-op1 'six.~x '~x
89 (define-op2 'six.x%y 'x%y
96 (define-op2 'six.x*y 'x*y
103 (define-op1 'six.*x '*x
105 'byte) ; we only have byte arrays
111 (define-op2 'six.index 'index
113 'byte) ; we only have byte arrays
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 ;; TODO check with the C standard for the next 2
155 (define-op2 'six.x<<y 'x<<y
162 (define-op2 'six.x>>y 'x>>y
169 (define-op2 'six.x<y 'x<y
170 type-rule-int-comp-op2
176 (define-op2 'six.x<=y 'x<=y
177 type-rule-int-comp-op2
183 (define-op2 'six.x>y 'x>y
184 type-rule-int-comp-op2
190 (define-op2 'six.x>=y 'x>=y
191 type-rule-int-comp-op2
197 (define-op2 'six.x!=y 'x!=y
198 type-rule-int-comp-op2
204 (define-op2 'six.x==y 'x==y
205 type-rule-int-comp-op2
211 (define-op2 'six.x&y 'x&y
218 (define-op1 'six.&x '&x
226 (define-op2 'six.x^y 'x^y
233 (define-op2 '|six.x\|y| '|x\|y|
240 (define-op2 'six.x&&y 'x&&y
247 (define-op2 '|six.x\|\|y| '|x\|\|y|
254 (define-op3 'six.x?y:z 'x?y:z
256 ;; largest of the 2 branches
257 (let ((t1 (expr-type (subast2 ast)))
258 (t2 (expr-type (subast3 ast))))
265 (define-op2 'six.x:y 'x:y
273 (define-op2 'six.x%=y 'x%=y ;; TODO these don't work
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
358 (define-op2 '|six.x,y| '|x,y|
366 (define-op2 'six.x:-y 'x:-y
374 (define (operation? source)
376 (let ((x (car source)))
377 (let loop ((lst operators))
380 ((eq? (op-six-id (car lst)) x)
383 (loop (cdr lst))))))))