File tree Expand file tree Collapse file tree 9 files changed +121
-11
lines changed
Expand file tree Collapse file tree 9 files changed +121
-11
lines changed Original file line number Diff line number Diff line change 346346 (list
347347 (seq (Mov rax (Offset rax (* 8 i)))
348348 i1
349- (Mov rax (Offset rsp (* 8 (sub1 (length cm1)))))
349+ (Mov rax (Offset rsp (* 8 (- (length cm1) (length cm )))))
350350 is)
351351 (seq f1 fs)
352352 cmn)])])]))
Original file line number Diff line number Diff line change 382382 '() ))
383383 666 )
384384
385- ;; Outlaw examples
385+ ;; Neerdowell examples
386386 (check-equal? (run '(struct foo ())
387387 '(foo? (foo)))
388388 #t )
434434 '(match (bar 5 )
435435 [(foo x) #f ]
436436 [(bar x) x]))
437- 5 ))
437+ 5 )
438+ (check-equal? (run '(struct nil ())
439+ '(struct pair (x y))
440+ '(define (len x)
441+ (match x
442+ [(nil) 0 ]
443+ [(pair _ x) (add1 (len x))]))
444+ '(len (pair 1 (pair 2 (pair 3 (nil))))))
445+ 3 )
446+ (check-equal? (run '(match (cons (cons 1 2 ) '() )
447+ [(cons (cons x y) '() ) y]))
448+ 2 )
449+ (check-equal? (run '(struct foo (p q))
450+ '(match (cons (foo 1 2 ) '() )
451+ [(cons (foo x y) _ ) y]))
452+ 2 )
453+ (check-equal? (run '(struct foo (p q))
454+ '(match (cons (foo 1 2 ) '() )
455+ [(cons (foo x 3 ) _ ) x]
456+ [_ 9 ]))
457+ 9 )
458+ (check-equal? (run '(struct foo (x q))
459+ '(define (get z)
460+ (match z
461+ ['() #f ]
462+ [(cons (foo x q) y) x]))
463+ '(get (cons (foo 7 2 ) '() )))
464+ 7 )
465+ (check-equal? (run '(struct posn (x y))
466+ '(define (posn-xs ps)
467+ (match ps
468+ ['() '() ]
469+ [(cons (posn x y) ps)
470+ (cons x (posn-xs ps))]))
471+ '(posn-xs (cons (posn 3 4 ) (cons (posn 5 6 ) (cons (posn 7 8 ) '() )))))
472+ '(3 5 7 )))
473+
438474
439475(define (test-runner-io run)
440476 ;; Evildoer examples
Original file line number Diff line number Diff line change 11#lang racket
2- (provide asm-string current-shared?)
2+ (provide asm-string current-shared? asm-display )
33(require "ast.rkt " )
44
55(define current-shared?
216216 (instrs->string a)
217217 #;
218218 (error "program does not have an initial label " )])))
219+
220+ (define (asm-display a)
221+ (begin
222+ (set-box! external-labels '() )
223+ ;; entry point will be first label
224+ (match (findf Label? a)
225+ [(Label g)
226+ (begin
227+ (write-string
228+ (string-append
229+ tab "global " (label-symbol->string g) "\n "
230+ tab "default rel\n "
231+ tab "section .text\n " ))
232+ (asm-display-instrs a))]
233+ [_
234+ (asm-display-instrs a)])))
235+
236+ (define (asm-display-instrs a)
237+ (match a
238+ ['() (void)]
239+ [(cons i a)
240+ (begin (write-string (instr->string i))
241+ (write-string "\n " )
242+ (asm-display-instrs a))]))
Original file line number Diff line number Diff line change 400400 (list
401401 (seq (Mov rax (Offset rax (*8 i)))
402402 i1
403- (Mov rax (Offset rsp (*8 (sub1 (length cm1)))))
403+ (Mov rax (Offset rsp (*8 (- (length cm1) (length cm )))))
404404 is)
405405 (seq f1 fs)
406406 cmn)])])]))
Original file line number Diff line number Diff line change 88 (begin
99 (read-line) ; ignore #lang racket line
1010 (current-shared? #t )
11- (displayln ( asm-string (compile-library (parse-library (read-all) ))))))
11+ (asm-display (compile-library (parse-library (read-all))))))
Original file line number Diff line number Diff line change 99 (begin
1010 (read-line) ; ignore #lang racket line
1111 (current-shared? #t )
12- (displayln ( asm-string (compile (parse (read-all) ))))))
12+ (asm-display (compile (parse (read-all))))))
Original file line number Diff line number Diff line change 8181 string->uninterned-symbol
8282 open-input-file
8383 write-char error integer?
84- eq-hash-code char-alphabetic? char-whitespace? displayln
84+ eq-hash-code char-alphabetic? char-whitespace? displayln write-string
8585 ;; Op2
8686 + - < = cons eq? make-vector vector-ref
8787 make-string string-ref string-append
Original file line number Diff line number Diff line change 1515 read-line
1616 char-alphabetic? char-whitespace?
1717 displayln ; only works for strings
18+ write-string
1819 ; unimplemented
1920 exact->inexact / expt string->keyword
2021 ;; Op0
305306 ;; the primitive system type returns 1 for mac, 0 otherwise;
306307 ;; the fall through case is for when %system-type is implemented in Racket
307308 (match (%system-type)
308- [1 'macosx ]
309- [0 'unix ]
309+ ;; the use of string->symbol here is to avoid subtle issues about symbol interning
310+ ;; in separately compiled libraries
311+ [1 (string->symbol "macosx " )]
312+ [0 (string->symbol "unix " )]
310313 [x x]))
311314
312315(define (not x)
559562
560563(define (displayln s)
561564 (if (string? s)
562- (begin (map write-char ( string->list s) )
565+ (begin (write-string s )
563566 (write-char #\newline ))
564567 (error "unimplemented displayln for non-strings " )))
565568
569+ (define (write-string s)
570+ (begin (map write-char (string->list s))
571+ (string-length s)))
572+
566573(define (exact->inexact x)
567574 (error "exact->inexact not implemented " ))
568575
Original file line number Diff line number Diff line change 428428 (check-equal? (run '(struct foo (x))
429429 '(foo-x #t ))
430430 'err )
431+ (check-equal? (run '(struct foo (x))
432+ '(struct bar (y))
433+ '(match (bar 5 )
434+ [(foo x) #f ]
435+ [(bar x) x]))
436+ 5 )
437+ (check-equal? (run '(struct nil ())
438+ '(struct pair (x y))
439+ '(define (len x)
440+ (match x
441+ [(nil) 0 ]
442+ [(pair _ x) (add1 (len x))]))
443+ '(len (pair 1 (pair 2 (pair 3 (nil))))))
444+ 3 )
445+ (check-equal? (run '(match (cons (cons 1 2 ) '() )
446+ [(cons (cons x y) '() ) y]))
447+ 2 )
448+ (check-equal? (run '(struct foo (p q))
449+ '(match (cons (foo 1 2 ) '() )
450+ [(cons (foo x y) _ ) y]))
451+ 2 )
452+ (check-equal? (run '(struct foo (p q))
453+ '(match (cons (foo 1 2 ) '() )
454+ [(cons (foo x 3 ) _ ) x]
455+ [_ 9 ]))
456+ 9 )
457+ (check-equal? (run '(struct foo (x q))
458+ '(define (get z)
459+ (match z
460+ ['() #f ]
461+ [(cons (foo x q) y) x]))
462+ '(get (cons (foo 7 2 ) '() )))
463+ 7 )
464+ (check-equal? (run '(struct posn (x y))
465+ '(define (posn-xs ps)
466+ (match ps
467+ ['() '() ]
468+ [(cons (posn x y) ps)
469+ (cons x (posn-xs ps))]))
470+ '(posn-xs (cons (posn 3 4 ) (cons (posn 5 6 ) (cons (posn 7 8 ) '() )))))
471+ '(3 5 7 ))
431472
432473 ;; Outlaw examples
433474 (check-equal? (run '(+)) 0 )
684725 (cons (void) "a " ))
685726 (check-equal? (run "" '(write-char #\newline ))
686727 (cons (void) "\n " ))
728+ (check-equal? (run "" '(write-string "hello world " ))
729+ (cons 11 "hello world " ))
687730 (check-equal? (run "" '(displayln "hello world " ))
688731 (cons (void) "hello world\n " ))
689732 )
You can’t perform that action at this time.
0 commit comments