Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions PRIMITIVES.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ The implementation of these primitives can be found in the file [stdlib.slisp](s
* Does the given string look like a binary number, with 0b-prefix?
* `binary`
* Parse the given string, with 0b-prefix, as a binary number and return the integer value.
* `cd`
* Change the present working directory. (Lookup the value with `pwd`.)
* `dec2binary`
* Convert an integer to a string containing the binary version of that number (e.g. 7 -> 0b111)
* `dec2hex`
Expand Down Expand Up @@ -256,10 +258,18 @@ The implementation of these primitives can be found in the file [stdlib.slisp](s
* `getenv`
* Return the value of the given environmental variable, nor NIL if not found.
* Uses `environment`.
* `getgid`
* Return the group ID of the current user.
* `getpid`
* Return the current process ID.
* `getuid`
* Return the ID of the current user.
* `hex?`
* Does the given string look like a hex number, with 0x prefix?
* `hex`
* Parse the given string, with 0x-prefix, as a hex number and return the integer value.
* `hostname`
* Return the system hostname.
* `join`
* Join all (string) items of a list into a single string.
* `join-by`
Expand Down Expand Up @@ -314,6 +324,8 @@ The implementation of these primitives can be found in the file [stdlib.slisp](s
* Print "anything" by invoking `print`, then outputting a newline.
* `putc`
* Print the given character.
* `pwd`
* Return the present working directory. (Change with `cd`.)
* `random`
* Return a random integer between zero and N-1.
* `random_string`
Expand Down
57 changes: 57 additions & 0 deletions stdlib.slisp
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,13 @@ Incrementing by the given step each time."
(u64! m (* i 8) 0)
m))

(defconst SYS_chdir 80)

(defun cd (path)
"Change to the given working directory"
(if (< (syscall SYS_chdir path) 0)
nil 1))

(defun getc ()
"Read a single character from STDIN, and return it."
(let ((str "s"))
Expand All @@ -1256,6 +1263,46 @@ Uses (environment) to get all environmental variables, and filters."
(getenv-loop name (cdr xs))))
nil))

(defconst SYS_getgid 104)

(defun getgid ()
"Return the group ID of the current user."
(let ((res (syscall SYS_getgid)))
(if (< res 0)
nil res )))

(defconst SYS_getpid 39)

(defun getpid ()
"Return the process ID of the current process."
(let ((res (syscall SYS_getpid)))
(if (< res 0)
nil res )))

(defconst SYS_getuid 102)

(defun getuid ()
"Return the ID of the current user."
(let ((res (syscall SYS_getuid)))
(if (< res 0)
nil res )))

(defconst SYS_uname 63)

(defun hostname ()
"Return the system hostname, via the uname syscall."
(let ((len 1024)
(hst "")
(i 0)
(buf (alloc len)))
(if (< (syscall SYS_uname buf len) 0)
nil
(do
(while (!= (strat buf (+ i 65)) 0)
(set! hst (strcat hst (string (chr (strat buf (+ i 65))))))
(set! i (+ i 1)))
hst))))

(defconst SYS_clock_gettime 228)

(defun now ()
Expand All @@ -1276,6 +1323,16 @@ Uses (environment) to get all environmental variables, and filters."
((int? c) (syscall 1 1 (string (chr (& 255 c))) 1))
(t (do (println "putc called with bogus arg") (exit 1)))))

(defconst SYS_getcwd 79)

(defun pwd ()
"Return the current working directory"
(let ((len 1024)
(buf (alloc len)))
(if (>= (syscall SYS_getcwd buf len) 0)
buf nil)))


(defconst SYS_getrandom 318)

(defun random (n)
Expand Down
Loading