spec: string ports (open-input-string/open-output-string/read-char/etc)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
Phase 14: port type + eof-object. Input ports track _pos cursor; output ports accumulate _buffer. All 15 port primitives in spec/primitives.sx (stdlib.ports module), platform.py (JS), and 39/39 tests in spec/tests/test-ports.sx. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -856,4 +856,96 @@
|
||||
:returns "number"
|
||||
:doc "Number of bits needed to represent integer a (excluding sign).")
|
||||
|
||||
(define-module :stdlib.ports)
|
||||
|
||||
(define-primitive
|
||||
"eof-object"
|
||||
:params ()
|
||||
:returns "eof-object"
|
||||
:doc "The EOF sentinel value.")
|
||||
|
||||
(define-primitive
|
||||
"eof-object?"
|
||||
:params (v)
|
||||
:returns "boolean"
|
||||
:doc "True if v is the EOF sentinel.")
|
||||
|
||||
(define-primitive
|
||||
"open-input-string"
|
||||
:params ((s :as string))
|
||||
:returns "input-port"
|
||||
:doc "Open a string as an input port.")
|
||||
|
||||
(define-primitive
|
||||
"open-output-string"
|
||||
:params ()
|
||||
:returns "output-port"
|
||||
:doc "Open a fresh output string port.")
|
||||
|
||||
(define-primitive
|
||||
"get-output-string"
|
||||
:params ((p :as output-port))
|
||||
:returns "string"
|
||||
:doc "Flush output port contents to a string.")
|
||||
|
||||
(define-primitive
|
||||
"port?"
|
||||
:params (v)
|
||||
:returns "boolean"
|
||||
:doc "True if v is any port.")
|
||||
|
||||
(define-primitive
|
||||
"input-port?"
|
||||
:params (v)
|
||||
:returns "boolean"
|
||||
:doc "True if v is an input port.")
|
||||
|
||||
(define-primitive
|
||||
"output-port?"
|
||||
:params (v)
|
||||
:returns "boolean"
|
||||
:doc "True if v is an output port.")
|
||||
|
||||
(define-primitive
|
||||
"close-port"
|
||||
:params ((p :as port))
|
||||
:returns "nil"
|
||||
:doc "Close a port.")
|
||||
|
||||
(define-primitive
|
||||
"read-char"
|
||||
:params (&rest (p :as input-port))
|
||||
:returns "any"
|
||||
:doc "Read next char from port; returns eof-object at end.")
|
||||
|
||||
(define-primitive
|
||||
"peek-char"
|
||||
:params (&rest (p :as input-port))
|
||||
:returns "any"
|
||||
:doc "Peek next char without consuming; returns eof-object at end.")
|
||||
|
||||
(define-primitive
|
||||
"read-line"
|
||||
:params (&rest (p :as input-port))
|
||||
:returns "any"
|
||||
:doc "Read a line from port; returns eof-object at end.")
|
||||
|
||||
(define-primitive
|
||||
"write-char"
|
||||
:params ((c :as char) &rest (p :as output-port))
|
||||
:returns "nil"
|
||||
:doc "Write a char to output port.")
|
||||
|
||||
(define-primitive
|
||||
"write-string"
|
||||
:params ((s :as string) &rest (p :as output-port))
|
||||
:returns "nil"
|
||||
:doc "Write a string to output port.")
|
||||
|
||||
(define-primitive
|
||||
"char-ready?"
|
||||
:params (&rest (p :as input-port))
|
||||
:returns "boolean"
|
||||
:doc "True if a char is immediately available on the port.")
|
||||
|
||||
(define-module :stdlib.hash-table)
|
||||
|
||||
Reference in New Issue
Block a user