IOPrimitiveUtils

Shared helpers backing every I/O primitive of :io-lib (Open3, Close1, Read1, Write2, ...): argument validation (raising the appropriate ISO error on mismatch), and the read/write/peek "compute, then reply" boilerplate common to most stream predicates.

These are extension members of Solve.Request, so every primitive implementation calls them, e.g. ensuringArgumentIsOutputChannel(0), as if they were request methods; none of this is meant to be used outside of a primitive's compute/computeOne/computeAll body.

Properties

Link copied to clipboard

The input channel implicitly targeted by get_char/1-like unary predicates: the context's current input, or its standard input.

Link copied to clipboard

The output channel implicitly targeted by put_char/1-like unary predicates: the context's current output, or its standard output.

Functions

Link copied to clipboard

Ensures term is one of the stream_property/2 shapes this implementation actually reports for open/4's option list (input, output, alias(_), type(text), eof_action(eof_code), reposition(false)).

Link copied to clipboard

Ensures term is one of the read_term/2,3 info shapes (variables(_), variable_names(_), singletons(_)).

Link copied to clipboard

Ensures term is one of the write_term/2,3 option shapes (quoted(_), ignore_ops(_), numbervars(_)).

Link copied to clipboard

Ensures term is one of the stream_property/2 shapes (input, output, alias(_), type(_), eof_action(_), reposition(_)), whether or not this implementation actually reports it.

Link copied to clipboard

Ensures the argument at index denotes an already-open Channel, resolved either by alias (a bound atom registered in the context's input or output channels) or by $stream(...) term, as required by predicates taking a Stream_or_alias argument (e.g. close/1, stream_property/2's subject).

Link copied to clipboard

Reads the write_term/2,3 option list at index (via ensuringArgumentIsValidOptionList) and turns it into the TermFormatter it describes: quoted(true) selects QUOTED_IF_NECESSARY atom/functor quoting, ignore_ops(true) disables operator notation, and numbervars(true) renders '$VAR'(N) terms as letters. Options not present in the list default to false.

Link copied to clipboard

Same as ensuringArgumentIsChannel, additionally requiring the resolved channel to be an InputChannel, as required by predicates reading from a stream (e.g. get_char/2, read/2).

Link copied to clipboard

Ensures the argument at index is one of the read/write/append atoms, as required by open/3,4's mode argument, and returns the corresponding IOMode.

Link copied to clipboard

Same as ensuringArgumentIsChannel, additionally requiring the resolved channel to be an OutputChannel, as required by predicates writing to a stream (e.g. put_char/2, write/2).

Link copied to clipboard

Ensures the argument at index of stream_property/2 is either unbound, or one of input, output, alias(_) (the only properties this predicate accepts as a query pattern, as opposed to a reported result).

Link copied to clipboard

Ensures the argument at index is an atom parsing (via Url.of) into a valid source/sink Url, as required by open/3,4 and consult/1.

Link copied to clipboard

Ensures the argument at index is either unbound (returning null, meaning "report every info") or a proper list of read_term/2,3 info shapes, validating each element via ensureTermIsValidInfo.

Link copied to clipboard

Ensures the argument at index is a proper list of write_term/2,3 options, validating each element via ensureTermIsValidOption.

Link copied to clipboard

Ensures the argument at index is either unbound, end_of_file, or a one-character atom, as required by the "character" argument of get_char/1,2, peek_char/1,2 and put_char/1,2.

Link copied to clipboard

Ensures the argument at index is either unbound, -1 (end-of-file), or a valid character code, as required by the "code" argument of get_code/1,2 and peek_code/1,2.

Link copied to clipboard

Ensures the argument at index is either unbound (returning null) or a $stream(...) term identifying an already-open channel (returning it), as required by the single argument of current_input/1/current_output/1.

Link copied to clipboard

Implements open/3,4: validates the SourceSink/Mode/Stream/Options arguments (third is the Stream output argument, shared by both arities), opens the corresponding channel via it.unibo.tuprolog.solve.libs.io.openInputChannel/it.unibo.tuprolog.solve.libs.io.openOutputChannel, and registers it (under the alias(_) option, if given, or an auto-generated one) before replying with the new $stream(...) term unified with third.

Link copied to clipboard

Peeks the next character from channel (end_of_file atom at end of stream) and unifies arg with it, or fails on a closed channel.

Link copied to clipboard

Peeks the next character code from channel (-1 at end of stream) and unifies arg with it, or fails on a closed channel.

Link copied to clipboard

The stream_property/2 properties (input/output, plus one alias(_) per alias other than ChannelStore.CURRENT) that hold for channel in this request's context, always terminated by type(text) since only text streams are supported.

Link copied to clipboard

Reads (consuming it) the next character from channel (end_of_file atom at end of stream) and unifies arg with it, or fails on a closed channel.

Link copied to clipboard

Reads (consuming it) the next character code from channel (-1 at end of stream) and unifies arg with it, or fails on a closed channel.

Link copied to clipboard

Implements read/1,2 and read_term/2,3: parses the next it.unibo.tuprolog.core.Term out of channel (via asTermChannel) and unifies it with arg, failing (not erroring) if the channel has no more terms available.

Link copied to clipboard

Writes the character arg to channel, replying success, or failing on a closed channel.

Link copied to clipboard

Writes the character coded by arg to channel, replying success, or failing on a closed channel.

Link copied to clipboard

Formats term via formatter and writes it to channel, replying success, or failing on a closed channel.