mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 13:37:57 +03:00
29 lines
826 B
Plaintext
29 lines
826 B
Plaintext
(system-include "carp_io.h")
|
|
|
|
(register-type FILE)
|
|
|
|
(defmodule IO
|
|
(register println (Fn [(Ref String)] ()))
|
|
(register print (Fn [(Ref String)] ()))
|
|
(register get-line (Fn [] String))
|
|
(register get-char (Fn [] Char) "getchar")
|
|
(register read-file (Fn [&String] String))
|
|
(register exit (Fn [Int] a))
|
|
(register EOF Char)
|
|
(register fopen (Fn [&String &String] (Ptr FILE)))
|
|
(register fclose (Fn [(Ptr FILE)] ()))
|
|
(register fgetc (Fn [(Ptr FILE)] Char))
|
|
(register fwrite (Fn [a Int Int (Ptr FILE)] ()) "fwrite")
|
|
|
|
(defn read->EOF [filename]
|
|
(let [f (IO.fopen filename "rb")
|
|
c (Char.from-int 0)
|
|
r []]
|
|
(do
|
|
(while (do (set! c (IO.fgetc f))
|
|
(/= c IO.EOF))
|
|
(set! r (Array.push-back r c)))
|
|
(IO.fclose f)
|
|
(String.from-chars &r))))
|
|
)
|