;; -*-theme-d-*-

;; Copyright (C) 2008-2013 Tommi Höynälänmaa
;; Distributed under GNU Lesser General Public License version 3,
;; see file doc/LGPL-3.

(define-interface (standard-library text-file-io)

  (import (standard-library core))


  (define-prim-class <input-port>
    #f #f #t ()
    input-port? eqv? eqv? eqv?)


  (define-prim-class <output-port>
    #f #f #t ()
    output-port? eqv? eqv? eqv?)


  (declare open-output-file (:procedure (<string>) <output-port> nonpure))

  (declare open-input-file (:procedure (<string>) <input-port> nonpure))

  (declare close-output-port (:procedure (<output-port>) <none> nonpure))

  (declare close-input-port (:procedure (<input-port>) <none> nonpure))

  (declare display-string (:procedure (<output-port> <string>) <none> nonpure))

  (declare display-character
	   (:procedure (<output-port> <character>) <none> nonpure))

  (declare write-string (:procedure (<output-port> <string>) <none> nonpure))

  (declare write-character
	   (:procedure (<output-port> <character>) <none> nonpure))

  (declare newline (:procedure (<output-port>) <none> nonpure))

  (declare read-character
	   (:procedure (<input-port>) (:union <character> <eof>) nonpure))

  (declare peek-character
	   (:procedure (<input-port>) (:union <character> <eof>) nonpure))

  (declare read
	   (:procedure (<input-port>) <object> nonpure))

  (declare read-all
	   (:procedure (<input-port>) <list> nonpure))

  (declare read-string
	   (:procedure (<input-port>) <string> nonpure))

  (declare read-line
	   (:procedure (<input-port>) <string> nonpure))

  (declare character-ready? (:procedure (<input-port>) <boolean> pure))

  (define-generic-proc write)
  
  (define-generic-proc display)

  (declare-method write
		  (:simple-proc (<output-port> <object>) <none> nonpure))

  (declare-method write
		  (:simple-proc (<output-port> <integer>) <none> nonpure))

  (declare-method write
		  (:simple-proc (<output-port> <real>) <none> nonpure))

  (declare-method write
		  (:simple-proc (<output-port> <symbol>) <none> nonpure))

  (declare-method write
		  (:simple-proc (<output-port> <string>) <none> nonpure))

  (declare-method write
		  (:simple-proc (<output-port> <character>) <none> nonpure))

  (declare-method write
		  (:simple-proc (<output-port> <boolean>) <none> nonpure))

  (declare-method write
		  (:simple-proc (<output-port> <null>) <none> nonpure))

  (declare write-line
	   (:procedure (<output-port> <object>) <none> nonpure))

  (declare-method display
		  (:simple-proc (<output-port> <object>) <none> nonpure))

  (declare-method display
		  (:simple-proc (<output-port> <integer>) <none> nonpure))

  (declare-method display
		  (:simple-proc (<output-port> <real>) <none> nonpure))

  (declare-method display
		  (:simple-proc (<output-port> <symbol>) <none> nonpure))

  (declare-method display
		  (:simple-proc (<output-port> <string>) <none> nonpure))

  (declare-method display
		  (:simple-proc (<output-port> <character>) <none> nonpure))

  (declare-method display
		  (:simple-proc (<output-port> <boolean>) <none> nonpure))

  (declare-method display
		  (:simple-proc (<output-port> <null>) <none> nonpure))

  (declare display-line
	   (:procedure (<output-port> <object>) <none> nonpure))

  ;; Not sure if either of the following two primitive procedures
  ;; can raise exceptions.

  (declare current-output-port (:procedure () <output-port> pure))

  (declare current-error-port (:procedure () <output-port> pure))

  (declare current-input-port (:procedure () <input-port> pure))

  (declare standard-output-port (:procedure () <output-port> pure))

  (declare standard-error-port (:procedure () <output-port> pure))

  (declare standard-input-port (:procedure () <input-port> pure))

  (declare call-with-input-string
	   (:procedure (<string> (:procedure (<input-port>) <object> nonpure))
		       <object> nonpure))

  (declare call-with-output-string
	   (:procedure ((:procedure (<output-port>) <none> nonpure))
		       <string> nonpure))

  (declare write-general-object
	   (:procedure (<output-port> <object> <boolean> <list>)
		       <none> nonpure))

  (declare-method write
		  (:simple-proc (<output-port> <pair>) <none> nonpure))

  (declare-method display
		  (:simple-proc (<output-port> <pair>) <none> nonpure)))
