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
The input channel implicitly targeted by get_char/1-like unary predicates: the context's current input, or its standard input.
The output channel implicitly targeted by put_char/1-like unary predicates: the context's current output, or its standard output.
Functions
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)).
Ensures term is one of the read_term/2,3 info shapes (variables(_), variable_names(_), singletons(_)).
Ensures term is one of the write_term/2,3 option shapes (quoted(_), ignore_ops(_), numbervars(_)).
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.
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.
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).
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).
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).
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.
Ensures the argument at index is a proper list of write_term/2,3 options, validating each element via ensureTermIsValidOption.
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.
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.
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.
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.
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.
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.