Skip to content

Commit c999d10

Browse files
committed
removed 'send this'
1 parent 4761352 commit c999d10

6 files changed

+149
-134
lines changed

conditionals.rkt

+73-71
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
(class compile-reg-R0
1111
(super-new)
1212

13+
(inherit liveness-ss first-offset variable-size on-stack?)
14+
1315
(define/override (primitives)
1416
(set-union (super primitives)
1517
(set 'eq? 'and 'or 'not)))
@@ -54,7 +56,7 @@
5456
(unless (equal? T1 T2)
5557
(error "checking equality between different-typed values"))
5658
(values `(has-type (eq? ,e1^ ,e2^) Boolean) 'Boolean)]
57-
[`(,op ,es ...) #:when (set-member? (send this primitives) op)
59+
[`(,op ,es ...) #:when (set-member? (primitives) op)
5860
(define-values (new-es ts)
5961
(for/lists (exprs types) ([e es]) ((type-check env) e)))
6062
(define binary-ops
@@ -93,12 +95,12 @@
9395
[`(has-type ,e ,t) `(has-type ,((uniquify env) e) ,t)]
9496
[(? boolean? b) b]
9597
[`(if ,cnd ,thn ,els)
96-
(let ([cnd ((send this uniquify env) cnd)]
97-
[thn ((send this uniquify env) thn)]
98-
[els ((send this uniquify env) els)])
98+
(let ([cnd ((uniquify env) cnd)]
99+
[thn ((uniquify env) thn)]
100+
[els ((uniquify env) els)])
99101
`(if ,cnd ,thn ,els))]
100102
[`(program (type ,ty) ,e)
101-
`(program (type ,ty) ,((send this uniquify env) e))]
103+
`(program (type ,ty) ,((uniquify env) e))]
102104
[else ((super uniquify env) e)])))
103105

104106
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -108,8 +110,8 @@
108110
(lambda (ast)
109111
(match ast
110112
[`(if ,cnd ,thn ,els)
111-
(append (append* (map (send this collect-locals) thn))
112-
(append* (map (send this collect-locals) els)))]
113+
(append (append* (map (collect-locals) thn))
114+
(append* (map (collect-locals) els)))]
113115
[else ((super collect-locals) ast)])))
114116

115117
(define optimize-if #t)
@@ -125,18 +127,18 @@
125127
[#f #:when optimize-if
126128
(values new-els els-ss)]
127129
[`(let ([,x ,e]) ,body) #:when optimize-if
128-
(define-values (new-e e-ss) ((send this flatten #f) e))
130+
(define-values (new-e e-ss) ((flatten #f) e))
129131
(define-values (new-body body-ss)
130-
((send this flatten-if new-thn thn-ss new-els els-ss) body))
132+
((flatten-if new-thn thn-ss new-els els-ss) body))
131133
(values new-body
132134
(append e-ss
133135
`((assign ,x ,new-e))
134136
body-ss))]
135137
[`(not ,cnd) #:when optimize-if
136-
((send this flatten-if new-els els-ss new-thn thn-ss) cnd)]
138+
((flatten-if new-els els-ss new-thn thn-ss) cnd)]
137139
[`(eq? ,e1 ,e2) #:when optimize-if
138-
(define-values (new-e1 e1-ss) ((send this flatten #t) e1))
139-
(define-values (new-e2 e2-ss) ((send this flatten #t) e2))
140+
(define-values (new-e1 e1-ss) ((flatten #t) e1))
141+
(define-values (new-e2 e2-ss) ((flatten #t) e2))
140142
(define tmp (gensym 'if))
141143
(define thn-ret `(assign ,tmp ,new-thn))
142144
(define els-ret `(assign ,tmp ,new-els))
@@ -146,7 +148,7 @@
146148
,(append thn-ss (list thn-ret))
147149
,(append els-ss (list els-ret))))))]
148150
[else
149-
(let-values ([(new-cnd cnd-ss) ((send this flatten #t) `(has-type ,cnd ,t))])
151+
(let-values ([(new-cnd cnd-ss) ((flatten #t) `(has-type ,cnd ,t))])
150152
(define tmp (gensym 'if))
151153
(define thn-ret `(assign ,tmp ,new-thn))
152154
(define els-ret `(assign ,tmp ,new-els))
@@ -168,8 +170,8 @@
168170
;; We override 'and' to place has-type's around the #t and #f
169171
;; in the generated code. -Jeremy
170172
[`(has-type (and ,e1 ,e2) ,t)
171-
(define-values (new-e1 e1-ss) ((send this flatten #t) e1))
172-
(define-values (new-e2 e2-ss) ((send this flatten #f) e2))
173+
(define-values (new-e1 e1-ss) ((flatten #t) e1))
174+
(define-values (new-e2 e2-ss) ((flatten #f) e2))
173175
(define tmp (gensym 'and))
174176
(values `(has-type ,tmp ,t)
175177
(append e1-ss
@@ -180,8 +182,8 @@
180182
;; We override flattening for op's because we
181183
;; need to put a has-type on the LHS of the assign. -Jeremy
182184
[`(has-type (,op ,es ...) ,t)
183-
#:when (set-member? (send this primitives) op)
184-
(define-values (new-es sss) (map2 (send this flatten #t) es))
185+
#:when (set-member? (primitives) op)
186+
(define-values (new-es sss) (map2 (flatten #t) es))
185187
(define ss (append* sss))
186188
(define prim-apply `(,op ,@new-es))
187189
(cond
@@ -193,20 +195,20 @@
193195

194196
;; For 'let' we just need to strip the enclosing has-type. -Jeremy
195197
[`(has-type (let ([,x ,e]) ,body) ,t)
196-
((send this flatten need-atomic) `(let ([,x ,e]) ,body))]
198+
((flatten need-atomic) `(let ([,x ,e]) ,body))]
197199

198200
[`(has-type (if ,cnd ,thn ,els) ,t)
199-
(define-values (new-thn thn-ss) ((send this flatten #t) thn))
200-
(define-values (new-els els-ss) ((send this flatten #t) els))
201+
(define-values (new-thn thn-ss) ((flatten #t) thn))
202+
(define-values (new-els els-ss) ((flatten #t) els))
201203
((flatten-if new-thn thn-ss new-els els-ss) cnd)]
202204

203205
[`(program ,e)
204-
(define-values (new-e ss) ((send this flatten #t) e))
205-
(define xs (append* (map (send this collect-locals) ss)))
206+
(define-values (new-e ss) ((flatten #t) e))
207+
(define xs (append* (map (collect-locals) ss)))
206208
`(program ,(remove-duplicates xs) ,@(append ss `((return ,new-e))))]
207209
[`(program (type ,ty) ,e)
208-
(define-values (new-e ss) ((send this flatten #t) e))
209-
(define xs (append* (map (send this collect-locals) ss)))
210+
(define-values (new-e ss) ((flatten #t) e))
211+
(define xs (append* (map (collect-locals) ss)))
210212
`(program ,(remove-duplicates xs) (type ,ty) ,@(append ss `((return ,new-e))))]
211213
[else ((super flatten need-atomic) e)])))
212214

@@ -238,20 +240,20 @@
238240
[`(assign ,lhs (has-type ,rhs ,t))
239241
((select-instructions) `(assign ,lhs ,rhs))]
240242
[`(assign ,lhs ,b) #:when (boolean? b)
241-
(let ([lhs ((send this select-instructions) lhs)]
242-
[b ((send this select-instructions) b)])
243+
(let ([lhs ((select-instructions) lhs)]
244+
[b ((select-instructions) b)])
243245
`((movq ,b ,lhs)))]
244246
[`(assign ,lhs (not ,e))
245-
(define new-lhs ((send this select-instructions) lhs))
246-
(define new-e ((send this select-instructions) e))
247+
(define new-lhs ((select-instructions) lhs))
248+
(define new-e ((select-instructions) e))
247249
(cond [(equal? new-e new-lhs)
248250
`((xorq (int 1) ,new-lhs))]
249251
[else `((movq ,new-e ,new-lhs)
250252
(xorq (int 1) ,new-lhs))])]
251253
[`(assign ,lhs (eq? ,e1 ,e2))
252-
(define new-lhs ((send this select-instructions) lhs))
253-
(define new-e1 ((send this select-instructions) e1))
254-
(define new-e2 ((send this select-instructions) e2))
254+
(define new-lhs ((select-instructions) lhs))
255+
(define new-e1 ((select-instructions) e1))
256+
(define new-e2 ((select-instructions) e2))
255257
;; second operand of cmpq can't be an immediate
256258
(define comparison
257259
(cond [(and (immediate? new-e1) (immediate? new-e2))
@@ -268,17 +270,17 @@
268270
)]
269271
;; Keep the if statement to simplify register allocation
270272
[`(if ,cnd ,thn-ss ,els-ss)
271-
(let ([cnd ((send this select-instructions) cnd)]
272-
[thn-ss (append* (map (send this select-instructions)
273+
(let ([cnd ((select-instructions) cnd)]
274+
[thn-ss (append* (map (select-instructions)
273275
thn-ss))]
274-
[els-ss (append* (map (send this select-instructions)
276+
[els-ss (append* (map (select-instructions)
275277
els-ss))])
276278
`((if ,cnd ,thn-ss ,els-ss)))]
277279
[`(eq? ,a1 ,a2)
278-
`(eq? ,((send this select-instructions) a1)
279-
,((send this select-instructions) a2))]
280+
`(eq? ,((select-instructions) a1)
281+
,((select-instructions) a2))]
280282
[`(program ,locals (type ,ty) ,ss ...)
281-
(let ([new-ss (map (send this select-instructions) ss)])
283+
(let ([new-ss (map (select-instructions) ss)])
282284
`(program ,locals (type ,ty) ,@(append* new-ss)))]
283285
[else ((super select-instructions) e)]
284286
)))
@@ -289,48 +291,48 @@
289291
(define/override (free-vars a)
290292
(match a
291293
[`(byte-reg ,r) (set (byte-reg->full-reg r))]
292-
[`(eq? ,e1 ,e2) (set-union (send this free-vars e1)
293-
(send this free-vars e2))]
294+
[`(eq? ,e1 ,e2) (set-union (free-vars e1)
295+
(free-vars e2))]
294296
[else (super free-vars a)]
295297
))
296298

297299
(define/override (read-vars instr)
298300
(match instr
299-
[`(movzbq ,s ,d) (send this free-vars s)]
300-
[`(cmpq ,s1 ,s2) (set-union (send this free-vars s1)
301-
(send this free-vars s2))]
301+
[`(movzbq ,s ,d) (free-vars s)]
302+
[`(cmpq ,s1 ,s2) (set-union (free-vars s1)
303+
(free-vars s2))]
302304
[(or `(andq ,s ,d) `(orq ,s ,d) `(xorq ,s ,d))
303-
(set-union (send this free-vars s) (send this free-vars d))]
304-
[`(notq ,d) (send this free-vars d)]
305+
(set-union (free-vars s) (free-vars d))]
306+
[`(notq ,d) (free-vars d)]
305307
[`(sete ,d) (set)]
306308
[else (super read-vars instr)]))
307309

308310
(define/override (write-vars instr)
309311
(match instr
310-
[`(movzbq ,s ,d) (send this free-vars d)]
312+
[`(movzbq ,s ,d) (free-vars d)]
311313
[`(cmpq ,s1 ,s2) (set '__flag)]
312314
[(or `(andq ,s ,d) `(orq ,s ,d) `(xorq ,s ,d))
313-
(send this free-vars d)]
314-
[`(notq ,d) (send this free-vars d)]
315-
[`(sete ,d) (send this free-vars d)]
315+
(free-vars d)]
316+
[`(notq ,d) (free-vars d)]
317+
[`(sete ,d) (free-vars d)]
316318
[else (super write-vars instr)]))
317319

318320
(define/override (uncover-live live-after)
319321
(lambda (ast)
320322
(match ast
321323
[`(if ,cnd ,thn-ss ,els-ss)
322324
(define-values (new-thn-ss thn-lives)
323-
((send this liveness-ss live-after) thn-ss))
325+
((liveness-ss live-after) thn-ss))
324326
(define-values (new-els-ss els-lives)
325-
((send this liveness-ss live-after) els-ss))
327+
((liveness-ss live-after) els-ss))
326328
;; I doubt that thn-lives can be null -Jeremy
327329
(define live-after-thn (cond [(null? thn-lives) live-after]
328330
[else (car thn-lives)]))
329331
(define live-after-els (cond [(null? els-lives) live-after]
330332
[else (car els-lives)]))
331333
(values `(if ,cnd ,new-thn-ss ,(cdr thn-lives) ,new-els-ss ,(cdr els-lives))
332334
(set-union live-after-thn live-after-els
333-
(send this free-vars cnd)))]
335+
(free-vars cnd)))]
334336
[else ((super uncover-live live-after) ast)]
335337
)))
336338

@@ -349,7 +351,7 @@
349351
ast]
350352
[`(if ,cnd ,thn-ss ,thn-lives ,els-ss ,els-lives)
351353
(define (build-inter inst live-after)
352-
((send this build-interference live-after G) inst))
354+
((build-interference live-after G) inst))
353355
(define new-thn (map build-inter thn-ss thn-lives))
354356
(define new-els (map build-inter els-ss els-lives))
355357
`(if ,cnd ,new-thn ,new-els)]
@@ -362,28 +364,28 @@
362364
(lambda (e)
363365
(match e
364366
[`(byte-reg ,r) `(byte-reg ,r)]
365-
[`(eq? ,e1 ,e2) `(eq? ,((send this assign-homes homes) e1)
366-
,((send this assign-homes homes) e2))]
367+
[`(eq? ,e1 ,e2) `(eq? ,((assign-homes homes) e1)
368+
,((assign-homes homes) e2))]
367369
[`(if ,cnd ,thn-ss ,els-ss)
368-
(let ([cnd ((send this assign-homes homes) cnd)]
369-
[thn-ss (map (send this assign-homes homes) thn-ss)]
370-
[els-ss (map (send this assign-homes homes) els-ss)])
370+
(let ([cnd ((assign-homes homes) cnd)]
371+
[thn-ss (map (assign-homes homes) thn-ss)]
372+
[els-ss (map (assign-homes homes) els-ss)])
371373
`(if ,cnd ,thn-ss ,els-ss))]
372374
[`(program (,xs ...) (type ,ty) ,ss ...)
373375
;; create mapping of variables to stack locations
374376
(define (make-stack-loc n)
375-
`(stack ,(+ (send this first-offset)
376-
(* (send this variable-size) n))))
377+
`(stack ,(+ (first-offset)
378+
(* (variable-size) n))))
377379
(define new-homes
378380
(make-hash (map cons xs
379381
(map make-stack-loc
380382
(stream->list (in-range 0 (length xs)))))))
381383
(define stack-space (align
382384
(* (length xs)
383-
(send this variable-size))
385+
(variable-size))
384386
16))
385387
`(program ,stack-space (type ,ty)
386-
,@(map (send this assign-homes new-homes) ss))]
388+
,@(map (assign-homes new-homes) ss))]
387389
[else ((super assign-homes homes) e)]
388390
)))
389391

@@ -397,8 +399,8 @@
397399
[`(int ,n) `(int ,n)]
398400
[`(reg ,r) `(reg ,r)]
399401
[`(if (eq? ,a1 ,a2) ,thn-ss ,els-ss)
400-
(let ([thn-ss (append* (map (send this lower-conditionals) thn-ss))]
401-
[els-ss (append* (map (send this lower-conditionals) els-ss))]
402+
(let ([thn-ss (append* (map (lower-conditionals) thn-ss))]
403+
[els-ss (append* (map (lower-conditionals) els-ss))]
402404
[thn-label (gensym 'then)]
403405
[end-label (gensym 'if_end)])
404406
(append `((cmpq ,a1 ,a2))
@@ -407,7 +409,7 @@
407409
))]
408410
[`(callq ,f) `((callq ,f))]
409411
[`(program ,stack-space (type ,ty) ,ss ...)
410-
(let ([new-ss (append* (map (send this lower-conditionals) ss))])
412+
(let ([new-ss (append* (map (lower-conditionals) ss))])
411413
`(program ,stack-space (type ,ty) ,@new-ss))]
412414
[`(,instr ,args ...)
413415
`((,instr ,@args))]
@@ -417,7 +419,7 @@
417419

418420
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
419421
(define/override (patch-instructions)
420-
(define (mem? x) (send this on-stack? x))
422+
(define (mem? x) (on-stack? x))
421423
(lambda (e)
422424
(match e
423425
[`(je ,label) `((je ,label))]
@@ -441,7 +443,7 @@
441443
(movq (reg rax) ,d))]
442444
[`(program ,stack-space (type ,ty) ,ss ...)
443445
`(program ,stack-space (type ,ty)
444-
,@(append* (map (send this patch-instructions) ss)))]
446+
,@(append* (map (patch-instructions) ss)))]
445447
[else ((super patch-instructions) e)]
446448
)))
447449

@@ -451,10 +453,10 @@
451453
(lambda (e)
452454
(match e
453455
[`(byte-reg ,r) (format "%~a" r)]
454-
[`(sete ,d) (format "\tsete\t~a\n" ((send this print-x86) d))]
456+
[`(sete ,d) (format "\tsete\t~a\n" ((print-x86) d))]
455457
[`(cmpq ,s1 ,s2)
456-
(format "\tcmpq\t~a, ~a\n" ((send this print-x86) s1)
457-
((send this print-x86) s2))]
458+
(format "\tcmpq\t~a, ~a\n" ((print-x86) s1)
459+
((print-x86) s2))]
458460
[`(je ,label) (format "\tje ~a\n" label)]
459461
[`(jmp ,label) (format "\tjmp ~a\n" label)]
460462
[`(label ,l) (format "~a:\n" l)]
@@ -467,7 +469,7 @@
467469
(for/list ([r (reverse callee-reg)])
468470
(format "\tpopq\t%~a\n" r)))
469471
(define callee-space (* (length (set->list callee-save))
470-
(send this variable-size)))
472+
(variable-size)))
471473
(define stack-adj (- (align (+ callee-space spill-space) 16)
472474
callee-space))
473475
(string-append
@@ -478,7 +480,7 @@
478480
(string-append* save-callee-reg)
479481
(format "\tsubq\t$~a, %rsp\n" stack-adj)
480482
"\n"
481-
(string-append* (map (send this print-x86) ss))
483+
(string-append* (map (print-x86) ss))
482484
"\n"
483485
(print-by-type ty)
484486
(format "\tmovq\t$0, %rax\n")

exams/copy-collect-soln.graffle

25 Bytes
Binary file not shown.

exams/copy-collect-soln.pdf

58 Bytes
Binary file not shown.

exams/copy-collect.graffle

40 Bytes
Binary file not shown.

exams/copy-collect.pdf

74 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)