File tree Expand file tree Collapse file tree 5 files changed +31
-1
lines changed
Expand file tree Collapse file tree 5 files changed +31
-1
lines changed Original file line number Diff line number Diff line change 153153 (pad-stack)
154154 (Call 'is_char_whitespace )
155155 (unpad-stack))]
156+ ['write-char
157+ (seq (assert-char rax)
158+ (Mov rdi rax)
159+ (pad-stack)
160+ (Call 'print_codepoint_out )
161+ (unpad-stack))]
156162
157163 ;; Op2
158164 ['+
Original file line number Diff line number Diff line change 8080 string->uninterned-symbol
8181 open-input-file
8282 write-char error integer?
83- eq-hash-code char-alphabetic? char-whitespace?
83+ eq-hash-code char-alphabetic? char-whitespace? displayln
8484 ;; Op2
8585 + - < = cons eq? make-vector vector-ref
8686 make-string string-ref string-append
104104 peek_byte_port
105105 is_char_alphabetic
106106 is_char_whitespace
107+ print_codepoint_out
107108 system_type)))
108109
109110(define cons-function
Original file line number Diff line number Diff line change 99#define port_buffer_bytes 8
1010
1111void utf8_encode_string (val_str_t * , char * );
12+ int utf8_encode_char (val_char_t , char * );
1213
1314val_t read_byte (void )
1415{
@@ -30,6 +31,14 @@ val_t write_byte(val_t c)
3031 return val_wrap_void ();
3132}
3233
34+ val_t print_codepoint_out (val_t c )
35+ {
36+ char buffer [5 ] = {0 };
37+ utf8_encode_char (val_unwrap_char (c ), buffer );
38+ fprintf (out , "%s" , buffer );
39+ return val_wrap_void ();
40+ }
41+
3342val_t open_input_file (val_t in ) {
3443 FILE * f ;
3544 char * buf ;
Original file line number Diff line number Diff line change 1414 findf
1515 read-line
1616 char-alphabetic? char-whitespace?
17+ displayln ; only works for strings
1718 ; unimplemented
1819 exact->inexact / expt string->keyword
1920 ;; Op0
6566(define (zero? n) (%zero? n))
6667(define (char? n) (%char? n))
6768(define (write-byte b) (%write-byte b)) ; IMPROVE: add port
69+ (define (write-char c) (%write-char c))
6870(define (eof-object? x) (%eof-object? x))
6971(define (integer->char i) (%integer->char i))
7072(define (char->integer c) (%char->integer c))
555557(define (char-alphabetic? x) (%char-alphabetic? x))
556558(define (char-whitespace? x) (%char-whitespace? x))
557559
560+ (define (displayln s)
561+ (if (string? s)
562+ (begin (map write-char (string->list s))
563+ (write-char #\newline ))
564+ (error "unimplemented displayln for non-strings " )))
565+
558566(define (exact->inexact x)
559567 (error "exact->inexact not implemented " ))
560568
Original file line number Diff line number Diff line change 674674 (cons #\a "" ))
675675 (check-equal? (run "ab " '(cons (read-char) (read-char)))
676676 (cons '(#\a . #\b ) "" ))
677+ (check-equal? (run "" '(write-char #\a ))
678+ (cons (void) "a " ))
679+ (check-equal? (run "" '(write-char #\newline ))
680+ (cons (void) "\n " ))
681+ (check-equal? (run "" '(displayln "hello world " ))
682+ (cons (void) "hello world\n " ))
677683 )
You can’t perform that action at this time.
0 commit comments