File tree Expand file tree Collapse file tree 6 files changed +36
-5
lines changed
Expand file tree Collapse file tree 6 files changed +36
-5
lines changed 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 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
559560
560561(define (displayln s)
561562 (if (string? s)
562- (begin (map write-char ( string->list s) )
563+ (begin (write-string s )
563564 (write-char #\newline ))
564565 (error "unimplemented displayln for non-strings " )))
565566
567+ (define (write-string s)
568+ (begin (map write-char (string->list s))
569+ (string-length s)))
570+
566571(define (exact->inexact x)
567572 (error "exact->inexact not implemented " ))
568573
Original file line number Diff line number Diff line change 725725 (cons (void) "a " ))
726726 (check-equal? (run "" '(write-char #\newline ))
727727 (cons (void) "\n " ))
728+ (check-equal? (run "" '(write-string "hello world " ))
729+ (cons (void) "hello world " ))
728730 (check-equal? (run "" '(displayln "hello world " ))
729731 (cons (void) "hello world\n " ))
730732 )
You can’t perform that action at this time.
0 commit comments