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
38 ;; TODO not sure it's true anymore
41 ;; the standard says it should be int
42 (define (type-rule-int-comp-op2 ast)
45 (define (type-rule-bool-op2 ast)
48 (define-op1 'six.!x '!x
50 (lambda (ast) ;; TODO implement these ?
56 (define-op1 'six.++x '++x
63 (define-op1 'six.x++ 'x++
70 (define-op1 'six.--x '--x
77 (define-op1 'six.x-- 'x--
84 (define-op1 'six.~x '~x
91 (define-op2 'six.x%y 'x%y
98 (define-op2 'six.x*y 'x*y
105 (define-op1 'six.*x '*x
107 'byte) ; we only have byte arrays
113 (define-op2 'six.index 'index
115 'byte) ; we only have byte arrays
121 (define-op2 'six.x/y 'x/y
128 (define-op2 'six.x+y 'x+y
135 (define-op1 'six.+x '+x
142 (define-op2 'six.x-y 'x-y
149 (define-op1 'six.-x '-x
156 ;; TODO check with the C standard for the next 2
157 (define-op2 'six.x<<y 'x<<y
164 (define-op2 'six.x>>y 'x>>y
171 (define-op2 'six.x<y 'x<y
172 type-rule-int-comp-op2
178 (define-op2 'six.x<=y 'x<=y
179 type-rule-int-comp-op2
185 (define-op2 'six.x>y 'x>y
186 type-rule-int-comp-op2
192 (define-op2 'six.x>=y 'x>=y
193 type-rule-int-comp-op2
199 (define-op2 'six.x!=y 'x!=y
200 type-rule-int-comp-op2
206 (define-op2 'six.x==y 'x==y
207 type-rule-int-comp-op2
213 (define-op2 'six.x&y 'x&y
220 (define-op1 'six.&x '&x
228 (define-op2 'six.x^y 'x^y
235 (define-op2 '|six.x\|y| '|x\|y|
242 (define-op2 'six.x&&y 'x&&y
249 (define-op2 '|six.x\|\|y| '|x\|\|y|
256 (define-op3 'six.x?y:z 'x?y:z
258 ;; largest of the 2 branches
259 (let ((t1 (expr-type (subast2 ast)))
260 (t2 (expr-type (subast3 ast))))
267 (define-op2 'six.x:y 'x:y
275 (define-op2 'six.x%=y 'x%=y ;; TODO these don't work
282 (define-op2 'six.x&=y 'x&=y
289 (define-op2 'six.x*=y 'x*=y
296 (define-op2 'six.x+=y 'x+=y
303 (define-op2 'six.x-=y 'x-=y
310 (define-op2 'six.x/=y 'x/=y
317 (define-op2 'six.x<<=y 'x<<=y
324 (define-op2 'six.x=y 'x=y
331 (define-op2 'six.x>>=y 'x>>=y
338 (define-op2 'six.x^=y 'x^=y
345 (define-op2 '|six.x\|=y| '|x\|=y|
352 (define-op2 'six.x:=y 'x:=y
360 (define-op2 '|six.x,y| '|x,y|
368 (define-op2 'six.x:-y 'x:-y
376 (define (operation? source)
378 (let ((x (car source)))
379 (let loop ((lst operators))
382 ((eq? (op-six-id (car lst)) x)
385 (loop (cdr lst))))))))