Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ports #19

Open
dvanhorn opened this issue Feb 9, 2021 · 2 comments
Open

Ports #19

dvanhorn opened this issue Feb 9, 2021 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@dvanhorn
Copy link
Member

dvanhorn commented Feb 9, 2021

IO is currently restricted to work only on stdin and stdout, but ports are first-class values in Racket. Add port values as a new, disjoint data type in our language. A port can be represented as a tagged pointer to a fixed-size array that contains a buffer and a pointer to a file handle. This will require some run-time support for opening and closing files. The enhancement should provide support for open-input-file, close-input-port, port? at least (and maybe some other operations).

@dvanhorn dvanhorn added the enhancement New feature or request label Feb 9, 2021
@john-h-kastner john-h-kastner self-assigned this Feb 10, 2021
@john-h-kastner
Copy link
Contributor

How should this enhancement interact with the existing IO operations? Presumably reading from the port will need to be supported. The minimal set of functions to support only touches on input ports, so is it reasonable to start by supporting input only?

@dvanhorn
Copy link
Member Author

You'll need to add variants of read-byte etc. that take a port value as an argument, so there's both (Prim0 'read-byte) and (Prim1 'read-byte e) where e is expected to evaluate to a port. The compilation of (Prim0 'read-byte) can stay as is, I believe.

I would start with input, but it might be good to do the output primitives too.

dvanhorn added a commit that referenced this issue Feb 23, 2021
* Initial implementation of input ports (#19)

* Pack port structure into fewer bytes

* Cleanup C code for ports

* Reduce code duplicated from char.c

* remove TODO

* Fix bug in utf8 encoding for of strings

The high bits of packed characters in a string were not zeroed before
encoding the character.

Co-authored-by: David Van Horn <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants