Skip to content

Commit 1c6866a

Browse files
committed
improved code gen for project
1 parent db3a247 commit 1c6866a

File tree

3 files changed

+45
-14
lines changed

3 files changed

+45
-14
lines changed

dynamic-typing.rkt

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,23 +205,44 @@
205205
[else
206206
`((movq ,new-e ,new-lhs)
207207
(orq (int ,(any-tag ty)) ,new-lhs))])]
208+
;; Old inefficient version of project. -Jeremy
209+
;; [`(assign ,lhs (project ,e ,ty))
210+
;; (define new-lhs (recur lhs))
211+
;; (define new-e (recur e))
212+
;; `((movq ,new-e ,new-lhs)
213+
;; (andq (int ,any-mask) ,new-lhs)
214+
;; (if (eq? ,new-lhs (int ,(any-tag ty)))
215+
;; ((andq (int ,pointer-mask) ,new-lhs)
216+
;; (if (eq? ,new-lhs (int ,pointer-mask))
217+
;; ;; vectors and procedures.
218+
;; ;; To do: check length of vector, arity of procedure. -Jeremy
219+
;; ((movq (int ,any-mask) ,new-lhs)
220+
;; (notq ,new-lhs)
221+
;; (andq ,new-e ,new-lhs))
222+
;; ;; booleans and integers
223+
;; ((movq ,new-e ,new-lhs)
224+
;; (sarq (int ,tag-len) ,new-lhs))
225+
;; ))
226+
;; ;; shouldn't we push the status code? -Jeremy
227+
;; ((callq ,(string->symbol (label-name 'exit))))))]
208228
[`(assign ,lhs (project ,e ,ty))
209229
(define new-lhs (recur lhs))
210230
(define new-e (recur e))
211231
`((movq ,new-e ,new-lhs)
212232
(andq (int ,any-mask) ,new-lhs)
213233
(if (eq? ,new-lhs (int ,(any-tag ty)))
214-
((andq (int ,pointer-mask) ,new-lhs)
215-
(if (eq? ,new-lhs (int ,pointer-mask))
216-
;; vectors and procedures.
217-
;; To do: check length of vector, arity of procedure. -Jeremy
218-
((movq (int ,any-mask) ,new-lhs)
234+
,(match ty
235+
[(or 'Integer 'Boolean)
236+
;; booleans and integers
237+
`((movq ,new-e ,new-lhs)
238+
(sarq (int ,tag-len) ,new-lhs))]
239+
[else ;; vectors and procedures (pointers)
240+
;; vectors and procedures.
241+
;; To do: check length of vector, arity of procedure. -Jeremy
242+
`((movq (int ,any-mask) ,new-lhs)
219243
(notq ,new-lhs)
220244
(andq ,new-e ,new-lhs))
221-
;; booleans and integers
222-
((movq ,new-e ,new-lhs)
223-
(sarq (int ,tag-len) ,new-lhs))
224-
))
245+
])
225246
;; shouldn't we push the status code? -Jeremy
226247
((callq ,(string->symbol (label-name 'exit))))))]
227248
[`(assign ,lhs (,pred ,e)) #:when (set-member? type-predicates pred)

tests/s7_5.rkt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
(define (hello) 24)
22
(define (world) 24)
33
(let ([x (vector 0 0)])
4-
(let ([voidx (vector-set! x 0 (hello))])
4+
(let ([y (hello)])
5+
(let ([voidx (vector-set! x 0 y)])
56
(let ([voidy (vector-set! x 1 (world))])
67
(+ (- 6) (+ (vector-ref x 0) (vector-ref x 1)))
7-
)))
8+
))))
89

utilities.rkt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,15 @@
213213
;; raises an error using the (error) function when it encounters a
214214
;; type error, or returns #f when it encounters a type error.
215215

216+
(define (strip-has-type e)
217+
(match e
218+
[`(has-type ,e ,T)
219+
(strip-has-type e)]
220+
[`(,(app strip-has-type e*) ...)
221+
`(,@e*)]
222+
[else
223+
e]))
224+
216225
(define (check-passes name typechecker passes initial-interp)
217226
(lambda (test-name)
218227
(debug "** compiler " name)
@@ -247,12 +256,12 @@
247256
(let ([input p])
248257
(debug (string-append "running pass: " pass-name
249258
" on test: " test-name)
250-
input))
259+
(strip-has-type input)))
251260
(define new-p (pass p))
252261
(let ([output new-p])
253262
(trace (string-append "running pass: " pass-name
254263
" on test: " test-name)
255-
output))
264+
(strip-has-type output)))
256265
(cond [interp
257266
(let ([new-result
258267
;; if there is an input file with the same name
@@ -313,7 +322,7 @@
313322
(let ([new-p (pass p)])
314323
(trace (string-append "running pass: "
315324
name)
316-
new-p)
325+
(strip-has-type new-p))
317326
(loop (cdr passes) new-p)
318327
)])]))])
319328
(cond [(string? x86)

0 commit comments

Comments
 (0)