1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* Cem Runtime - Async I/O Operations
*
* This module provides non-blocking I/O operations that cooperate with
* the scheduler. When I/O would block, these functions yield the strand
* to the scheduler and resume when I/O is ready.
*
* All I/O operations are non-blocking and async:
* - write_line() - Write a line to stdout (yields on EWOULDBLOCK)
* - read_line() - Read a line from stdin (yields on EWOULDBLOCK)
*/
/**
* Write a string to stdout, followed by a newline
*
* This function performs non-blocking I/O. If stdout is not ready for writing,
* the current strand will block until stdout becomes writable, then resume.
*
* Stack effect: ( str -- )
* - Pops a string from the stack
* - Writes it to stdout with a newline
* - Yields if write would block, resumes when ready
*
* Error handling:
* - runtime_error if not in a strand context
* - runtime_error on I/O errors (other than EAGAIN/EWOULDBLOCK)
*/
StackCell *;
/**
* Read a line from stdin
*
* This function performs non-blocking I/O. If stdin has no data available,
* the current strand will block until stdin becomes readable, then resume.
*
* Stack effect: ( -- str )
* - Reads a line from stdin (up to newline or EOF)
* - Pushes the string onto the stack (without the newline)
* - Yields if read would block, resumes when ready
*
* Error handling:
* - runtime_error if not in a strand context
* - runtime_error on I/O errors (other than EAGAIN/EWOULDBLOCK)
* - Pushes empty string on EOF
*/
StackCell *;
// CEM_RUNTIME_IO_H