A few extra functions for handling files and char pointers.

This commit is contained in:
Erik Svedäng 2018-03-18 14:40:49 +01:00
parent fc693d9ba8
commit 00105618a4
3 changed files with 18 additions and 0 deletions

View File

@ -27,3 +27,6 @@
(defmodule CharRef
(defn = [a b]
(Char.= @a @b)))
(defmodule PtrChar
(register str (Fn [(Ptr Char)] String)))

View File

@ -1,5 +1,7 @@
(system-include "carp_io.h")
(register-type FILE)
(defmodule IO
(register println (Fn [(Ref String)] ()))
(register print (Fn [(Ref String)] ()))
@ -7,4 +9,6 @@
(register get-char (Fn [] Char) "getchar")
(register read-file (Fn [&String] String))
(register exit (Fn [Int] a))
(register fopen (Fn [String String] (Ptr FILE)) "fopen")
(register fwrite (Fn [a Int Int (Ptr FILE)] ()) "fwrite")
)

View File

@ -15,3 +15,14 @@ char Char_from_MINUS_int(int i) {
char Char_copy(char *c) {
return *c;
}
string PtrChar_str(char *c) {
size_t len = strlen(c) + 1;
string ptr = CARP_MALLOC(len);
if (ptr == NULL) {
return NULL;
}
return (string) memcpy(ptr, c, len);
}