diff --git a/bin/ikarus b/bin/ikarus index 0d7cd41..9cbe757 100755 Binary files a/bin/ikarus and b/bin/ikarus differ diff --git a/bin/ikarus-runtime.c b/bin/ikarus-runtime.c index 216d410..1bdeda7 100644 --- a/bin/ikarus-runtime.c +++ b/bin/ikarus-runtime.c @@ -480,6 +480,7 @@ ikp ik_uuid(ikp str){ } +#if 0 ikp ik_read(ikp fdptr, ikp bufptr, ikp lenptr){ int fd = unfix(fdptr); int len = unfix(lenptr); @@ -491,7 +492,7 @@ ikp ik_read(ikp fdptr, ikp bufptr, ikp lenptr){ } return fix(bytes); } - +#endif ikp ik_write(ikp fdptr, ikp idx, ikp str){ fprintf(stderr, "IK_WRITE\n"); @@ -782,8 +783,8 @@ ikrt_close_file(ikp fd, ikpcb* pcb){ } } -ikp -ikrt_read(ikp fd, ikp buff, ikpcb* pcb){ +static ikp +ikrt_read_to_string(ikp fd, ikp buff, ikpcb* pcb){ int bytes = read(unfix(fd), string_data(buff), unfix(ref(buff, off_string_length))); ikp fbytes = fix(bytes); @@ -795,6 +796,30 @@ ikrt_read(ikp fd, ikp buff, ikpcb* pcb){ } } +static ikp +ikrt_read_to_bytevector(ikp fd, ikp buff, ikpcb* pcb){ + int bytes = + read(unfix(fd), buff+off_bytevector_data, unfix(ref(buff, off_bytevector_length))); + ikp fbytes = fix(bytes); + if (bytes == unfix(fbytes)){ + return fbytes; + } else { + fprintf(stderr, "ERR: ikrt_read: too big\n"); + exit(-1); + } +} + +ikp ikrt_read(ikp fd, ikp buff, ikpcb* pcb){ + if(tagof(buff) == string_tag){ + return ikrt_read_to_string(fd,buff,pcb); + } else { + return ikrt_read_to_bytevector(fd,buff,pcb); + } +} + + + + #if 0 if(bytes == -1){ fprintf(stderr, "ERR=%s (%d)\n", strerror(errno), errno); diff --git a/src/ikarus.boot b/src/ikarus.boot index c418edb..9720221 100644 Binary files a/src/ikarus.boot and b/src/ikarus.boot differ diff --git a/src/ikarus.collect.ss b/src/ikarus.collect.ss index 54e19d3..bf8ffe9 100644 --- a/src/ikarus.collect.ss +++ b/src/ikarus.collect.ss @@ -3,7 +3,7 @@ (export do-overflow do-overflow-words do-vararg-overflow collect do-stack-overflow) (import - (ikarus) + (except (ikarus) collect) (ikarus system $fx)) (define do-overflow diff --git a/src/ikarus.io-ports.ss b/src/ikarus.io-ports.ss index 824ef55..ad29203 100644 --- a/src/ikarus.io-ports.ss +++ b/src/ikarus.io-ports.ss @@ -52,7 +52,7 @@ ;;; (define $make-input-port (lambda (handler buffer) - ($make-port/input handler buffer 0 ($string-length buffer) #f 0 0))) + ($make-port/input handler buffer 0 (string-length buffer) #f 0 0))) ;;; (define make-input-port (lambda (handler buffer) @@ -64,7 +64,7 @@ ;;; (define $make-output-port (lambda (handler buffer) - ($make-port/output handler #f 0 0 buffer 0 ($string-length buffer)))) + ($make-port/output handler #f 0 0 buffer 0 (string-length buffer)))) ;;; (define make-output-port (lambda (handler buffer) @@ -77,8 +77,8 @@ (define $make-input/output-port (lambda (handler input-buffer output-buffer) ($make-port/both handler - input-buffer 0 ($string-length input-buffer) - output-buffer 0 ($string-length output-buffer)))) + input-buffer 0 (string-length input-buffer) + output-buffer 0 (string-length output-buffer)))) ;;; (define make-input/output-port (lambda (handler input-buffer output-buffer) @@ -151,7 +151,7 @@ (if (input-port? p) (if (fixnum? i) (if ($fx>= i 0) - (if ($fx<= i ($string-length ($port-input-buffer p))) + (if ($fx<= i (string-length ($port-input-buffer p))) (begin ($set-port-input-index! p 0) ($set-port-input-size! p i)) @@ -177,7 +177,7 @@ (if (output-port? p) (if (fixnum? i) (if ($fx>= i 0) - (if ($fx<= i ($string-length ($port-output-buffer p))) + (if ($fx<= i (string-length ($port-output-buffer p))) (begin ($set-port-output-index! p 0) ($set-port-output-size! p i)) diff --git a/src/ikarus.io-primitives.unsafe.ss b/src/ikarus.io-primitives.unsafe.ss index b395847..fcd81c9 100644 --- a/src/ikarus.io-primitives.unsafe.ss +++ b/src/ikarus.io-primitives.unsafe.ss @@ -14,7 +14,7 @@ (let ([idx (port-output-index p)]) (if ($fx< idx ($port-output-size p)) (begin - ($string-set! ($port-output-buffer p) idx c) + (string-set! ($port-output-buffer p) idx c) ($set-port-output-index! p ($fxadd1 idx))) (($port-handler p) 'write-char c p))))) @@ -24,7 +24,7 @@ (if ($fx< idx ($port-input-size p)) (begin ($set-port-input-index! p ($fxadd1 idx)) - ($string-ref ($port-input-buffer p) idx)) + (string-ref ($port-input-buffer p) idx)) (begin (($port-handler p) 'read-char p)))))) @@ -32,7 +32,7 @@ (lambda (p) (let ([idx ($port-input-index p)]) (if ($fx< idx ($port-input-size p)) - ($string-ref ($port-input-buffer p) idx) + (string-ref ($port-input-buffer p) idx) (($port-handler p) 'peek-char p))))) (define $unread-char @@ -42,7 +42,7 @@ ($fx< idx ($port-input-size p))) (begin ($set-port-input-index! p idx) - ($string-set! ($port-input-buffer p) idx c)) + (string-set! ($port-input-buffer p) idx c)) (($port-handler p) 'unread-char c p))))) (define $reset-input-port! diff --git a/src/ikarus.io.input-files.ss b/src/ikarus.io.input-files.ss index 69bf2ca..e59fbf4 100644 --- a/src/ikarus.io.input-files.ss +++ b/src/ikarus.io.input-files.ss @@ -57,7 +57,7 @@ (if ($fx< idx ($port-input-size p)) (begin ($set-port-input-index! p ($fxadd1 idx)) - ($string-ref ($port-input-buffer p) idx)) + (string-ref ($port-input-buffer p) idx)) (if open? (let ([bytes (foreign-call "ikrt_read" @@ -78,7 +78,7 @@ (error 'peek-char "~s is not an input port" p)) (let ([idx ($port-input-index p)]) (if ($fx< idx ($port-input-size p)) - ($string-ref ($port-input-buffer p) idx) + (string-ref ($port-input-buffer p) idx) (if open? (let ([bytes (foreign-call "ikrt_read" fd @@ -101,7 +101,7 @@ ($fx< idx ($port-input-size p))) (begin ($set-port-input-index! p idx) - ($string-set! ($port-input-buffer p) idx c)) + (string-set! ($port-input-buffer p) idx c)) (if open? (error 'unread-char "port ~s is closed" p) (error 'unread-char "too many unread-chars"))))] diff --git a/src/ikarus.io.input-strings.ss b/src/ikarus.io.input-strings.ss index 4e9bf76..df9fe5e 100644 --- a/src/ikarus.io.input-strings.ss +++ b/src/ikarus.io.input-strings.ss @@ -41,7 +41,7 @@ (if ($fx< idx ($port-input-size p)) (begin ($set-port-input-index! p ($fxadd1 idx)) - ($string-ref ($port-input-buffer p) idx)) + (string-ref ($port-input-buffer p) idx)) (if open? (eof-object) (error 'read-char "port ~s is closed" p))))] @@ -50,7 +50,7 @@ (error 'peek-char "~s is not an input port" p)) (let ([idx ($port-input-index p)]) (if ($fx< idx ($port-input-size p)) - ($string-ref ($port-input-buffer p) idx) + (string-ref ($port-input-buffer p) idx) (if open? (eof-object) (error 'peek-char "port ~s is closed" p))))] @@ -62,7 +62,7 @@ ($fx< idx ($port-input-size p))) (begin ($set-port-input-index! p idx) - ($string-set! ($port-input-buffer p) idx c)) + (string-set! ($port-input-buffer p) idx c)) (if open? (error 'unread-char "port ~s is closed" p) (error 'unread-char "too many unread-chars"))))] diff --git a/src/ikarus.io.output-files.ss b/src/ikarus.io.output-files.ss index 4ebad95..1e43c47 100644 --- a/src/ikarus.io.output-files.ss +++ b/src/ikarus.io.output-files.ss @@ -70,7 +70,7 @@ (let ([idx ($port-output-index p)]) (if ($fx< idx ($port-output-size p)) (begin - ($string-set! ($port-output-buffer p) idx c) + (string-set! ($port-output-buffer p) idx c) ($set-port-output-index! p ($fxadd1 idx))) (if open? (begin diff --git a/src/ikarus.io.output-strings.ss b/src/ikarus.io.output-strings.ss index d68bee3..16b1fa8 100644 --- a/src/ikarus.io.output-strings.ss +++ b/src/ikarus.io.output-strings.ss @@ -38,18 +38,18 @@ (define concat (lambda (str i ls) (let ([n (sum i ls)]) - (let ([outstr ($make-string n)]) + (let ([outstr (make-string n)]) (let f ([n (copy outstr str i n)] [ls ls]) (if (null? ls) outstr (let ([a ($car ls)]) - (f (copy outstr a ($string-length a) n) ($cdr ls))))))))) + (f (copy outstr a (string-length a) n) ($cdr ls))))))))) (define sum (lambda (ac ls) (cond [(null? ls) ac] - [else (sum ($fx+ ac ($string-length ($car ls))) ($cdr ls))]))) + [else (sum ($fx+ ac (string-length ($car ls))) ($cdr ls))]))) (define copy (lambda (dst src n end) @@ -59,7 +59,7 @@ [($fx= si 0) di] [else (let ([di ($fxsub1 di)] [si ($fxsub1 si)]) - ($string-set! dst di ($string-ref src si)) + (string-set! dst di (string-ref src si)) (f di si))])))) (define make-output-string-handler @@ -75,7 +75,7 @@ (let ([idx ($port-output-index p)]) (if ($fx< idx ($port-output-size p)) (begin - ($string-set! ($port-output-buffer p) idx c) + (string-set! ($port-output-buffer p) idx c) ($set-port-output-index! p ($fxadd1 idx))) (if open? (begin @@ -83,7 +83,7 @@ (cons (string-copy (port-output-buffer p)) buffer-list)) ($set-port-output-size! p - ($string-length ($port-output-buffer p))) + (string-length ($port-output-buffer p))) ($write-char c p)) (error 'write-char "port ~s is closed" p)))) (error 'write-char "~s is not an output-port" p))