justinethier / cyclone

:cyclone: A brand-new compiler that allows practical application development using R7RS Scheme. We provide modern features and a stable system capable of generating fast native binaries.
http://justinethier.github.io/cyclone/
MIT License
823 stars 42 forks source link

Reading end-of-file exits interpreter #453

Closed arthurmaciel closed 3 years ago

arthurmaciel commented 3 years ago

Hi, @justinethier!

I have found this strange behaviour when experimenting with reading ports:

cyclone> (define str-as-port (open-input-string "1"))
ok
cyclone> (peek-char str-as-port)
#\1
cyclone> (read-char str-as-port)
#\1
cyclone> (peek-char str-as-port)
(exits interpreter)

On CHICKEN:

#;1> (define str-as-port (open-input-string "1"))
#;2> (peek-char str-as-port)
#\1
#;3> (read-char str-as-port)
#\1
#;4> (peek-char str-as-port)
#!eof
#;5> (read-char str-as-port)
#!eof
#;6> (read-char str-as-port)
#!eof
#;7> (peek-char str-as-port)
#!eof
#;8> 

On Gambit:

> (define str-as-port (open-input-string "1"))
> (peek-char str-as-port)
#\1
> (read-char str-as-port)
#\1
> (peek-char str-as-port)                       
#!eof
> (read-char str-as-port)
#!eof
> (read-char str-as-port)
#!eof
> (peek-char str-as-port)
#!eof
> 
justinethier commented 3 years ago

Good catch @arthurmaciel !

This has never been handled properly but the fix is simple enough. This will work much better now if you can pull down the latest code from master.

arthurmaciel commented 3 years ago

Thanks, @justinethier!