SBCL
1. SBCL
ID: a7f9b428-9323-492f-aaa5-94669bfbc55b–
1.1. Extensions
1.1.1. ed functions
ID: 11329fdb-2923-4ccf-953c-037e78433b1a CREATED: <2025-03-03 Mon 14:53>
- State "NOTE" from
Although SBCL does not provide a resident editor, the ed function can be customized to hook into user-provided editing mechanisms as follows: Function: ed [cl] &optional x Starts the editor (on a file or a function if named). Functions from the list *ed-functions* are called in order with x as an argument until one of them returns non-NIL; these functions are responsible for signalling a file-error to indicate failure to perform an operation on the file system. Variable: *ed-functions* [sb-ext] See function documentation for ed.
1.1.2. Concurrency
ID: e99f0d2a-546a-479e-9014-3acdbcccd5ab CREATED: <2025-03-06 Thu 14:14>
(defvar *buffer-queue* (make-waitqueue)) (defvar *buffer-lock* (make-mutex :name "buffer lock")) (defvar *buffer* (list nil)) (defun reader () (with-mutex (*buffer-lock*) (loop (condition-wait *buffer-queue* *buffer-lock*) (loop (unless *buffer* (return)) (let ((head (car *buffer*))) (setf *buffer* (cdr *buffer*)) (format t "reader ~A woke, read ~A~%" *current-thread* head)))))) (defun writer () (loop (sleep (random 5)) (with-mutex (*buffer-lock*) (let ((el (intern (string (code-char (+ (char-code #\A) (random 26))))))) (setf *buffer* (cons el *buffer*))) (condition-notify *buffer-queue*)))) (make-thread #'writer) (make-thread #'reader) (make-thread #'reader)
#<THREAD tid=0 RUNNING {100C873E73}>
(defvar *data* nil) (defvar *queue* (make-waitqueue)) (defvar *lock* (make-mutex)) ;; Consumer (defun pop-data (&optional timeout) (with-mutex (*lock*) (loop until *data* do (or (condition-wait *queue* *lock* :timeout timeout) ;; Lock not held, must unwind without touching *data*. (return-from pop-data nil))) (pop *data*))) ;; Producer (defun push-data (data) (with-mutex (*lock*) (push data *data*) (condition-notify *queue*)))
PUSH-DATA
- Barriers
ID: dc91fb4a-adee-44ec-9bd8-cbfa10db8dca CREATED: <2025-03-06 Thu 14:19>
These are based on the Linux kernel barrier design, which is in turn based on the Alpha CPU memory model. They are presently implemented for x86, x86-64, PPC, ARM64, and RISC-V systems, and behave as compiler barriers on all other CPUs.
In addition to explicit use of the sb-thread:barrier macro, the following functions and macros also serve as :memory barriers:
- sb-ext:atomic-decf, sb-ext:atomic-incf, sb-ext:atomic-push, and sb-ext:atomic-pop.
- sb-ext:compare-and-swap.
- sb-thread:grab-mutex, sb-thread:release-mutex, sb-thread:with-mutex and sb-thread:with-recursive-lock.
- sb-thread:signal-semaphore, sb-thread:try-semaphore and sb-thread:wait-on-semaphore.
- sb-thread:condition-wait, sb-thread:condition-notify and sb-thread:condition-broadcast.
- Timers
ID: 6ff7096f-a666-4103-8f32-1dc62c04cb35 CREATED: <2025-03-06 Thu 14:19>
– - sb-thread
ID: 7bf0993f-6212-4635-a071-bf2e7d9ba7f9 CREATED: <2025-03-06 Thu 14:06>
->(make-thread (lambda () (write-line "Hello, world")))
#<THREAD tid=0 RUNNING {100933AD93}>
- Atomics
ID: bb27d9c3-513a-4ac6-8780-580c09257040 CREATED: <2025-03-06 Thu 14:11>
–
1.1.3. global vars
ID: c33d77c8-188c-4ba0-90ff-f49fac6468c2 CREATED: <2025-04-28 Mon 18:11>
(describe 'sb-ext:defglobal)
SB-EXT:DEFGLOBAL [symbol] DEFGLOBAL names a macro: Lambda-list: (NAME VALUE &OPTIONAL (DOC NIL)) Documentation: Defines NAME as a global variable that is always bound. VALUE is evaluated and assigned to NAME both at compile- and load-time, but only if NAME is not already bound. Global variables share their values between all threads, and cannot be locally bound, declared special, defined as constants, and neither bound nor defined as symbol macros. See also the declarations SB-EXT:GLOBAL and SB-EXT:ALWAYS-BOUND. Source file: SYS:SRC;CODE;MACROS.LISP
(describe 'sb-ext:define-load-time-global)
SB-EXT:DEFINE-LOAD-TIME-GLOBAL [symbol] DEFINE-LOAD-TIME-GLOBAL names a macro: Lambda-list: (NAME VALUE &OPTIONAL (DOC NIL)) Documentation: Defines NAME as a global variable that is always bound. VALUE is evaluated and assigned to NAME at load-time, but only if NAME is not already bound. Attempts to read NAME at compile-time will signal an UNBOUND-VARIABLE error unless it has otherwise been assigned a value. See also DEFGLOBAL which assigns the VALUE at compile-time too. Source file: SYS:SRC;CODE;MACROS.LISP
1.2. Internals
ID: 9aac997a-5d9c-43dd-b2ca-8b8b02d9f2dd
An exploration of SBCL internals - simonsafar.com – guicho271828/sbcl-wiki
–1.2.1. Low Tags
CREATED: <2025-01-17 Fri 15:50> ID: fd50e430-8a51-406a-96bd-ae6a1cf73bdd
#define SBCL_GENESIS_CONSTANTS #define FIXNUM_TAG_MASK 1 /* 0x1 */ #define N_FIXNUM_TAG_BITS 1 /* 0x1 */ #define N_LOWTAG_BITS 4 /* 0x4 */ #define N_WIDETAG_BITS 8 /* 0x8 */ #define N_WORD_BYTES 8 /* 0x8 */ #define LOWTAG_MASK 15 /* 0xF */ #define N_WORD_BITS 64 /* 0x40 */ #define WIDETAG_MASK 255 /* 0xFF */ #define SHORT_HEADER_MAX_WORDS 32767 /* 0x7FFF */ #define EVEN_FIXNUM_LOWTAG 0 /* 0x0 */ #define OTHER_IMMEDIATE_0_LOWTAG 1 /* 0x1 */ #define PAD0_LOWTAG 2 /* 0x2 */ #define INSTANCE_POINTER_LOWTAG 3 /* 0x3 */ #define PAD1_LOWTAG 4 /* 0x4 */ #define OTHER_IMMEDIATE_1_LOWTAG 5 /* 0x5 */ #define PAD2_LOWTAG 6 /* 0x6 */ #define LIST_POINTER_LOWTAG 7 /* 0x7 */ #define ODD_FIXNUM_LOWTAG 8 /* 0x8 */ #define OTHER_IMMEDIATE_2_LOWTAG 9 /* 0x9 */ #define PAD3_LOWTAG 10 /* 0xA */ #define FUN_POINTER_LOWTAG 11 /* 0xB */ #define PAD4_LOWTAG 12 /* 0xC */ #define OTHER_IMMEDIATE_3_LOWTAG 13 /* 0xD */ #define PAD5_LOWTAG 14 /* 0xE */ #define OTHER_POINTER_LOWTAG 15 /* 0xF */
1.2.2. Bindings
ID: a4d05da6-b90d-4a9f-8237-67a10c8c4588 CREATED: <2025-02-09 Sun 14:21>–
1.2.3. Symbols of Interest
ID: a8ee911d-6d19-452b-b03a-249a446c1b20 CREATED: <2025-01-17 Fri 19:11>
sb-sys:*runtime-dlhandle* sb-fasl:+fasl-file-version+ sb-fasl:+backend-fasl-file-implementation+ sb-debug:print-backtrace sb-debug:map-backtrace sb-pretty:pprint-dispatch-table sb-lockless: sb-ext:simd-pack sb-walker:define-walker-template sb-walker:macroexpand-all sb-walker:walk-form sb-kernel:empty-type sb-kernel:*eval-calls* sb-kernel:*gc-pin-code-pages* sb-kernel:*restart-clusters* sb-kernel:*save-lisp-clobbered-globals* sb-kernel:*top-level-form-p* sb-kernel:*universal-fun-type* sb-kernel:*universal-type* sb-kernel:*wild-type* sb-kernel:+simd-pack-element-types+ (sb-vm:memory-usage) (sb-vm:boxed-context-register) (sb-vm:c-find-heap->arena) (sb-vm:copy-number-to-heap) (sb-vm:dump-arena-objects) (sb-vm:fixnumize) (sb-vm:rewind-arena) (sb-vm:show-heap->arena) (sb-vm:with/without-arena) (sb-cltl2:{augment-environment,compiler-let,define-declaration,parse-macro}) (sb-cltl2:{declaration-information, variable-information, function-information}) sb-di: sb-assem: sb-md5: sb-regalloc: sb-disassem:
1.2.4. Core Format
ID: db473315-0c74-40cb-ab07-9259b2113043 CREATED: <2025-02-24 Mon 21:36>
sbcl/src/runtime/coreparse.c at master · sbcl/sbcl · GitHub sbcl/src/runtime/core.h at master · sbcl/sbcl · GitHub
1.2.5. VOP
ID: f9bcac71-99b9-4375-9c23-8b650d21d86c CREATED: <2025-02-28 Fri 19:08>
SBCL: the ultimate assembly code breadboard - Paul Khuong: some Lisp – How to define new intrinsics in SBCL - Paul Khuong: some Lisp – 001-sbcl-vops.txt
–Virtual Operations
1.2.6. Aliens ffi
ID: 93e1ed13-dc82-4a9b-8b9e-f60f06b01a4f CREATED: <2025-02-28 Fri 19:09>
Lazy Alien Resolution - SBCL Internals – Callbacks - SBCL Internals – Linkage-table - SBCL Internals
–1.2.7. SB-ASSEM asm
ID: 86674fe2-4105-4246-9682-f6e3fb84f7de CREATED: <2025-03-08 Sat 20:24>->
- sb-assem, sb-vm, sb-c
gen-label
(describe (sb-assem:gen-label "this is a label comment"))
#<SB-ASSEM:LABEL {1012471C13}> [structure-object] Slots with :INSTANCE allocation: INDEX = 0 POSN = NIL COMMENT = "this is a label comment" USEDP = NIL
- sb-assem:make-segment
- emit, assemble
1.2.8. Compiler comp
ID: 624cbc9a-9797-4889-a8b5-8440b04d9c01 CREATED: <2025-02-28 Fri 19:14>
CMUCL User's Manual: Advanced Compiler Use and Efficiency Hints
–- derive-function-types
ID: 76c64438-4db7-4318-8701-241d4f253782 CREATED: <2025-03-23 Sun 15:05>
DERIVE-FUNCTION-TYPES names a special variable: Value: NIL Documentation: Should the compiler assume that function types will never change, so that it can use type information inferred from current definitions to optimize code which uses those definitions? Setting this true gives non-ANSI, early-CMU-CL behavior. It can be useful for improving the efficiency of stable code.
- Inlining
;;; An INLINEP value describes how a function is called. The values ;;; have these meanings: ;;; NIL No declaration seen: do whatever you feel like, but don't ;;; dump an inline expansion. ;;; NOTINLINE NOTINLINE declaration seen: always do full function call. ;;; INLINE INLINE declaration seen: save expansion, expanding to it ;;; if policy favors. ;;; MAYBE-INLINE ;;; Retain expansion, but only use it opportunistically. ;;; MAYBE-INLINE is quite different from INLINE. As explained ;;; by APD on #lisp 2005-11-26: "MAYBE-INLINE lambda is ;;; instantiated once per component, INLINE - for all ;;; references (even under #'without FUNCALL)." (deftype inlinep () '(member inline maybe-inline notinline nil))
1.2.9. SB-KERNEL
ID: 31cebf6f-e67c-4289-a75e-ad012b4bbe5d CREATED: <2025-04-27 Sun 16:01>
WITH-ARRAY-DATA This checks to see whether the array is simple and the start and end are in bounds. If so, it proceeds with those values. Otherwise, it calls %WITH-ARRAY-DATA. Note that %WITH-ARRAY-DATA may be further optimized. Given any ARRAY, bind DATA-VAR to the array's data vector and START-VAR and END-VAR to the start and end of the designated portion of the data vector. SVALUE and EVALUE are any start and end specified to the original operation, and are factored into the bindings of START-VAR and END-VAR. OFFSET-VAR is the cumulative offset of all displacements encountered, and does not include SVALUE. When FORCE-INLINE is set, the underlying %WITH-ARRAY-DATA form is forced to be inline, overriding the ordinary judgment of the %WITH-ARRAY-DATA DEFTRANSFORMs. Ordinarily the DEFTRANSFORMs are fairly picky about their arguments, figuring that if you haven't bothered to get all your ducks in a row, you probably don't care that much about speed anyway! But in some cases it makes sense to do type testing inside %WITH-ARRAY-DATA instead of outside, and the DEFTRANSFORM can't tell that that's going on, so it can make sense to use FORCE-INLINE option in that case.
1.3. Tree Shaker
ID: 6beca36e-6264-4741-9180-66e81bf58c49 CREATED: <2025-01-26 Sun 00:54>>>
With the complexity involved in SBCL image dumps it becomes a hard problem to design an effective tree-shaker.
- sbcl/tests/treeshake.pure.lisp
- Shake tree harder · sbcl/sbcl@f9b92e4
sb-impl::shake-packages
1.4. Contribs
ID: c33a5587-daab-4e61-a0df-fc6856b00f70 CREATED: <2025-02-11 Tue 20:55>>>
1.4.1. sb-bsd-sockets
ID: 0c2908c2-69d0-4866-b225-3d7eec026b76 CREATED: <2025-02-11 Tue 20:55>
(defvar *protocols* `((:tcp ,sockint::ipproto_tcp "tcp" "TCP") (:udp ,sockint::ipproto_udp "udp" "UDP") (:ip ,sockint::ipproto_ip "ip" "IP") (:ipv6 ,sockint::ipproto_ipv6 "ipv6" "IPV6") (:icmp ,sockint::ipproto_icmp "icmp" "ICMP") (:igmp ,sockint::ipproto_igmp "igmp" "IGMP") (:raw ,sockint::ipproto_raw "raw" "RAW")))
1.4.2. sb-cltl2
ID: d2269803-9084-4845-8860-047c37da36c7 CREATED: <2025-04-23 Wed 15:21>
Deals with environments, closures, etc.
- It seems that the
sb-kernel:closure
type applies to the result ofsb-cltl2:enclose
- test withsb-kernel:closurep
.