From a463bc966fccd658aa406f06ab7a5d984e56ac8a Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Wed, 30 Sep 2026 19:33:57 +0300 Subject: [PATCH 1/4] Implement `cd` and `pwd` These change/retrieve the current working directory. --- PRIMITIVES.md | 4 ++++ stdlib.slisp | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/PRIMITIVES.md b/PRIMITIVES.md index be4a38c..3e4df23 100644 --- a/PRIMITIVES.md +++ b/PRIMITIVES.md @@ -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` @@ -314,6 +316,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` diff --git a/stdlib.slisp b/stdlib.slisp index 58aac0e..e016e55 100644 --- a/stdlib.slisp +++ b/stdlib.slisp @@ -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")) @@ -1276,6 +1283,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) From 03a112e6228f595df2457b815344767ec93c2bdc Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Wed, 30 Sep 2026 19:36:07 +0300 Subject: [PATCH 2/4] Implement `hostname`. --- PRIMITIVES.md | 2 ++ stdlib.slisp | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/PRIMITIVES.md b/PRIMITIVES.md index 3e4df23..aed2789 100644 --- a/PRIMITIVES.md +++ b/PRIMITIVES.md @@ -262,6 +262,8 @@ The implementation of these primitives can be found in the file [stdlib.slisp](s * 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` diff --git a/stdlib.slisp b/stdlib.slisp index e016e55..477cdf9 100644 --- a/stdlib.slisp +++ b/stdlib.slisp @@ -1263,6 +1263,22 @@ Uses (environment) to get all environmental variables, and filters." (getenv-loop name (cdr xs)))) nil)) +(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 () From b084ed023491d9e6b0f0b1404e4c0e4d279467ce Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Wed, 30 Sep 2026 19:38:11 +0300 Subject: [PATCH 3/4] Implement `getpid`. --- PRIMITIVES.md | 2 ++ stdlib.slisp | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/PRIMITIVES.md b/PRIMITIVES.md index aed2789..ea2611e 100644 --- a/PRIMITIVES.md +++ b/PRIMITIVES.md @@ -258,6 +258,8 @@ 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`. +* `getpid` + * Return the current process ID. * `hex?` * Does the given string look like a hex number, with 0x prefix? * `hex` diff --git a/stdlib.slisp b/stdlib.slisp index 477cdf9..4694f14 100644 --- a/stdlib.slisp +++ b/stdlib.slisp @@ -1263,6 +1263,14 @@ Uses (environment) to get all environmental variables, and filters." (getenv-loop name (cdr xs)))) nil)) +(defconst SYS_getpid 39) + +(defun getpid () + "Return the process ID of the current process." + (let ((res (syscall 39))) + (if (< res 0) + nil res ))) + (defconst SYS_uname 63) (defun hostname () From 293f693d032daf13af16f9e07d65ce9408612a35 Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Wed, 30 Sep 2026 19:42:43 +0300 Subject: [PATCH 4/4] Added `getuid` and `getgid`. --- PRIMITIVES.md | 4 ++++ stdlib.slisp | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/PRIMITIVES.md b/PRIMITIVES.md index ea2611e..bef44e3 100644 --- a/PRIMITIVES.md +++ b/PRIMITIVES.md @@ -258,8 +258,12 @@ 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` diff --git a/stdlib.slisp b/stdlib.slisp index 4694f14..6d65768 100644 --- a/stdlib.slisp +++ b/stdlib.slisp @@ -1263,11 +1263,27 @@ 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 39))) + (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 )))