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 ;; no need for type checks, every type sixpic supports can be casted to / from
16 ;; ints (except void, but this is a non-issue) and promotion (by padding) and
17 ;; truncation is done at the cfg level
18 ;; TODO really ignore the void issue ? assigning the "result" of a void function to an int variable should be an error
19 (define (type-rule-int-op1 ast)
20 (expr-type (subast1 ast)))
22 (define (largest t1 t2)
23 (let loop ((l '(int int32 int16 int8 byte))) ;; TODO FOO, use the functions type->bytes and bytes->type instead
25 (error "largest: unknown type")
32 (define (type-rule-int-op2 ast)
33 (let ((t1 (expr-type (subast1 ast)))
34 (t2 (expr-type (subast2 ast))))
37 (define (type-rule-int-assign ast) ;; TODO why the int in the name ?
38 (let ((t1 (expr-type (subast1 ast))))
39 ;; the type of the rhs is irrelevant, since it will be promoted
40 ;; or truncated at the cfg level
43 (define (type-rule-int-comp-op2 ast)
44 'bool) ;; TODO why even bother ? anything can be casted to int to be used as argument here, old version is in garbage (and in version control) if needed
46 (define (type-rule-bool-op2 ast)
47 'bool) ;; TODO same here
49 (define-op1 'six.!x '!x
51 (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
99 ;; products can be as wide as the sum of the widths of the operands
101 (let ((l1 (type->bytes (expr-type (subast1 ast))))
102 (l2 (type->bytes (expr-type (subast2 ast)))))
103 (bytes->type (+ l1 l2))))
109 (define-op1 'six.*x '*x
111 'byte) ; we only have byte arrays
117 (define-op2 'six.index 'index
119 'byte) ; we only have byte arrays
125 (define-op2 'six.x/y 'x/y
126 type-rule-int-op2 ;; TODO really ?
132 (define-op2 'six.x+y 'x+y
139 (define-op1 'six.+x '+x
146 (define-op2 'six.x-y 'x-y
153 (define-op1 'six.-x '-x
160 (define-op2 'six.x<<y 'x<<y
167 (define-op2 'six.x>>y 'x>>y
174 (define-op2 'six.x<y 'x<y
175 type-rule-int-comp-op2
181 (define-op2 'six.x<=y 'x<=y
182 type-rule-int-comp-op2
188 (define-op2 'six.x>y 'x>y
189 type-rule-int-comp-op2
195 (define-op2 'six.x>=y 'x>=y
196 type-rule-int-comp-op2
202 (define-op2 'six.x!=y 'x!=y
203 type-rule-int-comp-op2
209 (define-op2 'six.x==y 'x==y
210 type-rule-int-comp-op2
216 (define-op2 'six.x&y 'x&y
223 (define-op1 'six.&x '&x
231 (define-op2 'six.x^y 'x^y
238 (define-op2 '|six.x\|y| '|x\|y|
245 (define-op2 'six.x&&y 'x&&y
252 (define-op2 '|six.x\|\|y| '|x\|\|y|
259 (define-op2 'six.x?y:z 'x?y:z
267 (define-op2 'six.x:y 'x:y
275 (define-op2 'six.x%=y 'x%=y
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))))))))