changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > core / lisp/std/sys.lisp

changeset 651: af486e0a40c9
parent: 7ce855f76e1d
child: 295ea43ceb2d
author: Richard Westhaver <ellis@rwest.io>
date: Sat, 14 Sep 2024 22:13:06 -0400
permissions: -rw-r--r--
description: multi-binaries, working on removing x.lisp
1 ;;; std/sys.lisp --- Lisp System Utilities
2 
3 ;;
4 
5 ;;; Code:
6 (in-package :std/sys)
7 
8 ;;; Introspection
9 ;; (reexport-from :sb-introspect
10 ;; :include '(:function-lambda-list :lambda-list-keywords :lambda-parameters-limit
11 ;; :method-combination-lambda-list :deftype-lambda-list
12 ;; :primitive-object-size :allocation-information
13 ;; :function-type
14 ;; :who-specializes-directly :who-specializes-generally
15 ;; :find-function-callees :find-function-callers))
16 
17 ;; sys
18 ;; sb-sys:*linkage-info* *machine-version* *runtime-dlhandle* *periodic-polling-function*
19 ;; *periodic-polling-period* io-timeout nlx-protect serve-event os-deinit os-exit with-deadline dlopen-or-lose deallocate-system-memory
20 
21 (defun current-lisp-implementation ()
22  "Return the current lisp implemenation as a list: (TYPE VERSION FEATURES)"
23  (list
24  (lisp-implementation-type)
25  (lisp-implementation-version)
26  *features*))
27 
28 (defun current-machine ()
29  "Return the current machine spec as a list: (HOST TYPE VERSION)"
30  (list
31  (machine-instance)
32  (machine-type)
33  (machine-version)))
34 
35 (defun list-package-symbols (&optional (pkg *package*))
36  (loop for s being the external-symbol of pkg
37  collect s))
38 
39 (defun package-symbols (&optional (package *package*) test)
40  (let ((symbols))
41  (do-external-symbols (symbol package)
42  (if test
43  (when (funcall test symbol)
44  (push symbol symbols))
45  (push symbol symbols)))
46  symbols))
47 
48 (defun package-symbol-names (&optional (package *package*) test)
49  (sort (mapcar (lambda (x) (string-downcase (symbol-name x)))
50  (package-symbols package test))
51  #'string<))
52 
53 (defun standard-symbol-names (test)
54  (package-symbol-names :common-lisp test))
55 
56 (defun append-logical-hosts (&rest hosts)
57  "Reinitialize SB-IMPL::*LOGICAL-HOSTS* with a freshly allocated vector
58 consisting of the old contents appended to the new."
59  (setq *logical-hosts*
60  (concatenate 'vector hosts *logical-hosts*)))
61 
62 ;; TODO
63 (defun save-lisp-tree-shake-and-die (path &rest args)
64  "A naive tree-shaker for lisp."
65  (sb-ext:gc :full t)
66  (apply #'sb-ext:save-lisp-and-die path args))
67 
68 (defun save-lisp-and-live (filename completion-function restart &rest args)
69  (flet ((restart-sbcl ()
70  (sb-debug::enable-debugger)
71  (setf sb-impl::*descriptor-handlers* nil)
72  (funcall restart)))
73  ;; fork it - assumes only one thread is running
74  (multiple-value-bind (pipe-in pipe-out) (sb-posix:pipe)
75  (let ((pid (sb-posix:fork)))
76  (cond ((= pid 0) ;; make simple-restart core
77  (sb-posix:close pipe-in)
78  (sb-debug::disable-debugger)
79  (apply #'sb-ext:save-lisp-and-die filename
80  (append
81  (list :toplevel #'restart-sbcl)
82  args)))
83  (t
84  (sb-posix:close pipe-out)
85  (sb-sys:add-fd-handler
86  pipe-in :input
87  (lambda (fd)
88  (sb-sys:invalidate-descriptor fd)
89  (sb-posix:close fd)
90  (multiple-value-bind (rpid status) (sb-posix:waitpid pid 0) ;; wait for master
91  (assert (= pid rpid))
92  (assert (sb-posix:wifexited status))
93  (funcall completion-function
94  (zerop (sb-posix:wexitstatus status))))))))))))
95 
96 (defparameter *gc-logfile* #P"gc.log")
97 
98 (defun enable-gc-logfile (&optional (file *gc-logfile*))
99  (setf (sb-ext:gc-logfile) file))
100 
101 (defun forget-shared-object (name)
102  (setf (sb-alien::shared-object-dont-save
103  (find name sb-sys:*shared-objects*
104  :key 'sb-alien::shared-object-namestring
105  :test 'string-equal))
106  t))
107 
108 (defun forget-shared-objects (&optional (objects sb-sys:*shared-objects*))
109  "Set the DONT-SAVE slot of all objects in SB-SYS:*SHARED-OBJECTS* to T."
110  (mapcar (lambda (obj) (setf (sb-alien::shared-object-dont-save obj) t)) objects))
111 
112 (defun compile-lisp (name &key force save make package compression verbose version callable-exports executable (toplevel #'sb-impl::toplevel-init) forget save-runtime-options root-structures (purify t))
113  (pkg:with-package (or package *package*)
114  (asdf:compile-system name :force force :verbose verbose :version version)
115  (when make
116  (apply 'asdf:make name (unless (eq t make) make)))
117  (when forget
118  (forget-shared-objects (unless (eq t forget) forget)))
119  (when save
120  (when (probe-file save)
121  (delete-file save))
122  (sb-ext:save-lisp-and-die save :executable executable
123  :toplevel toplevel
124  :callable-exports callable-exports
125  :save-runtime-options save-runtime-options
126  :root-structures root-structures
127  :purify purify
128  :compression compression))))