Skip to content

Commit f991eb7

Browse files
author
llmII
committed
Add dependency (jumble), remove redef related macros/functions.
jumble provides better names and better implementations of what was previously defined here to create aliases, so change to depending on jumble. FossilOrigin-Name: 4462948c6eb367f091051bf8552e14897743a637dec1b51699ab331a07938a41
1 parent 996fe21 commit f991eb7

File tree

2 files changed

+18
-72
lines changed

2 files changed

+18
-72
lines changed

project.janet

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
:license "ISC"
55
:url "https://github.com/llmII/jsys"
66
:repo "git+https://github.com/llmII/jsys.git"
7-
:description "System level utilities/functions for Janet.")
7+
:description "System level utilities/functions for Janet."
8+
:dependencies ["https://github.com/llmII/jumble"])
89

910
(declare-source
1011
:source ["sys.janet"])

sys.janet

+16-71
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,5 @@
11
(import csys :as sys)
2-
3-
# helpers ********************************************************************
4-
# Definition from:
5-
# https://github.com/janet-lang/spork/blob/master/spork/path.janet
6-
# License: MIT
7-
# Copyright: 2019 Calvin Rose
8-
# Overall Copyright: 2020 Calvin Rose and contributors
9-
(defn- redef
10-
"Redef a value, keeping all metadata."
11-
[from to]
12-
(setdyn (symbol to) (dyn (symbol from))))
13-
14-
(defn- redef-clone
15-
"Redef a value, keeping all metadata."
16-
[from to]
17-
(setdyn (symbol to) (table/clone (dyn (symbol from)))))
18-
19-
(defn- redef-
20-
"Redef a value, then set it private in it's metadata."
21-
[from to]
22-
(redef-clone from to)
23-
(set ((dyn (symbol to)) :private) true))
24-
25-
(defn- redef+
26-
"Redef a value, then set it private in it's metadata."
27-
[from to]
28-
(redef-clone from to)
29-
(set ((dyn (symbol to)) :private) false))
30-
31-
(defmacro- redef-symbol
32-
"Redef, minus the string conversions/usage."
33-
[from to]
34-
~(redef+ ,(string from) ',to))
35-
36-
(defn- redef-multi*
37-
``
38-
Helper for redef-multi, does redefs over an indexed collection. Makes each
39-
new symbol exported.
40-
``
41-
[from to]
42-
(redef+ from (get to 0))
43-
(var idx (- (length to) 1))
44-
(while (> idx 0)
45-
(redef+ (string (get to 0)) (get to idx))
46-
(-- idx)))
47-
48-
(defmacro- redef-multi
49-
"Redef each symbol after the first as the first."
50-
[from & to]
51-
(var i 0)
52-
(let [len (length to)
53-
collecting @[]]
54-
(while (< i len)
55-
(array/push collecting (get to i))
56-
(++ i))
57-
~(redef-multi* ,(string from) ',collecting)))
2+
(use jumble)
583

594
# All the system specific functions exported from C
605
(def- exports '(chown chroot dup2 fileno fork setegid seteuid setgid setuid
@@ -67,57 +12,57 @@
6712
_ 'nix)]
6813
(each binding exports
6914
(do
70-
(redef+ (string "sys/" os "/" binding) (string os "/" binding))
71-
(redef- (string "sys/" os "/" binding) (string "_" binding)))))
15+
(defclone+* (symbol "sys/" os "/" binding) (symbol os "/" binding))
16+
(defclone-* (symbol "sys/" os "/" binding) (symbol "_" binding)))))
7217

7318
# chown - change fs entry ownership ******************************************
7419
# TODO: support chown with username/groupname instead of just uid/gid, support
7520
# optional uid/gid (use keyword args).
76-
(redef-multi _chown chown change-owner)
21+
(defaliases _chown chown change-owner :export true)
7722

7823
# chroot - change what is considered / ***************************************
79-
(redef-multi _chroot chroot change-root)
24+
(defaliases _chroot chroot change-root :export true)
8025

8126
# dup2 - reassign a fd's descriptor ******************************************
8227
# TODO: Easier file redirection supporting the :out and :in keywords for
8328
# stdout and stdin; document flags; Make overall nicer/easier.
84-
(redef-multi _dup2 dup2 redirect-file)
29+
(defaliases _dup2 dup2 redirect-file :export true)
8530

8631
# fork - split off into 2 processes ******************************************
8732
# TODO: may need a different idea on *BSD where kqueue is dead in child forks
88-
(redef-symbol _fork fork)
33+
(defaliases _fork fork :export true)
8934

9035
# setegid - set effective operating group id *********************************
9136
# TODO: Allow for setting of the gid by group name
92-
(redef-multi _setegid setegid set-effective-group)
37+
(defaliases _setegid setegid set-effective-group :export true)
9338

9439
# seteuid - set effective operating group id *********************************
9540
# TODO: Allow for setting of the uid by user name
96-
(redef-multi _seteuid seteuid set-effective-user)
41+
(defaliases _seteuid seteuid set-effective-user :export true)
9742

9843
# setgid - set operating group id ********************************************
9944
# TODO: Allow for setting of the gid by group name
100-
(redef-multi _setgid setgid set-group)
45+
(defaliases _setgid setgid set-group :export true)
10146

10247
# setuid - set operating user id *********************************************
10348
# TODO: Allow for setting of the uid by user name
104-
(redef-multi _setuid setuid set-user)
49+
(defaliases _setuid setuid set-user :export true)
10550

10651
# setsid - create new session ************************************************
107-
(redef-multi _setsid setsid new-session)
52+
(defaliases _setsid setsid new-session :export true)
10853

10954
# fcntl - file settings ******************************************************
11055
# TODO: provide a nicer way to use this, right now we're only supporting
11156
# locks but when we support more would be nice to have a better interface
112-
(redef-multi _fcntl fcntl file-settings)
57+
(defaliases _fcntl fcntl file-settings :export true)
11358

11459
# getpwnam - get user by name or id ******************************************
115-
(redef-multi _getpwnam getpwnam get-user-info)
60+
(defaliases _getpwnam getpwnam get-user-info :export true)
11661

11762
# getgrnam - get group by name or id *****************************************
118-
(redef-multi _getgrnam getgrnam get-group-info)
63+
(defaliases _getgrnam getgrnam get-group-info :export true)
11964

12065
# strftime - get a formatted time string *************************************
121-
(redef-multi _strftime strftime date-string)
66+
(defaliases _strftime strftime date-string :export true)
12267

12368
# TODO: provide easier lockfile interface

0 commit comments

Comments
 (0)