SBCL

1. SBCL

ID: a7f9b428-9323-492f-aaa5-94669bfbc55b

[2025-03-01 Sat 19:51] Getting Started - Steel Bank Common Lisp [2025-03-03 Mon 16:33] info [2025-03-03 Mon 16:34] man

1.1. Extensions

ID: 868e5534-1ab9-49aa-88c8-f9529b3dfc98
CREATED: <2025-03-03 Mon 14:53>

[2025-03-03 Mon 17:58] info [2025-03-06 Thu 14:07] << Contribs

1.1.1. ed functions

ID: 11329fdb-2923-4ccf-953c-037e78433b1a
CREATED: <2025-03-03 Mon 14:53>
  • State "NOTE" from [2023-10-20 Fri 01:14]
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
  1. 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.
  2. Timers
    ID: 6ff7096f-a666-4103-8f32-1dc62c04cb35
    CREATED: <2025-03-06 Thu 14:19>
    

    [2025-03-06 Thu 14:19] info

  3. sb-thread
    ID: 7bf0993f-6212-4635-a071-bf2e7d9ba7f9
    CREATED: <2025-03-06 Thu 14:06>
    

    [2025-03-06 Thu 14:07] -> Asynchrony [2025-03-06 Thu 14:08] info

    (make-thread (lambda () (write-line "Hello, world")))
    
    #<THREAD tid=0 RUNNING {100933AD93}>
    
  4. Atomics
    ID: bb27d9c3-513a-4ac6-8780-580c09257040
    CREATED: <2025-03-06 Thu 14:11>
    

    [2025-03-06 Thu 14:13] info

1.2. Internals

ID: 9aac997a-5d9c-43dd-b2ca-8b8b02d9f2dd

[2025-01-17 Fri 15:50] An exploration of SBCL internals - simonsafar.com [2025-01-17 Fri 19:03] 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>

[2025-02-09 Sun 14:22] Binding and unbinding - SBCL Internals

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

1.2.5. VOP

ID: f9bcac71-99b9-4375-9c23-8b650d21d86c
CREATED: <2025-02-28 Fri 19:08>

[2025-02-28 Fri 19:08] SBCL: the ultimate assembly code breadboard - Paul Khuong: some Lisp [2025-02-28 Fri 19:08] How to define new intrinsics in SBCL - Paul Khuong: some Lisp [2025-02-28 Fri 19:12] 001-sbcl-vops.txt

Virtual Operations

1.2.6. Aliens   ffi

ID: 93e1ed13-dc82-4a9b-8b9e-f60f06b01a4f
CREATED: <2025-02-28 Fri 19:09>

[2025-02-28 Fri 19:10] Lazy Alien Resolution - SBCL Internals [2025-02-28 Fri 19:10] Callbacks - SBCL Internals [2025-02-28 Fri 19:10] Linkage-table - SBCL Internals

1.2.7. SB-ASSEM   asm

ID: 86674fe2-4105-4246-9682-f6e3fb84f7de
CREATED: <2025-03-08 Sat 20:24>

[2025-03-08 Sat 20:54] -> Assembly

  • 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>

[2025-02-28 Fri 19:14] CMUCL User's Manual: Advanced Compiler Use and Efficiency Hints

1.3. Tree Shaker

ID: 6beca36e-6264-4741-9180-66e81bf58c49
CREATED: <2025-01-26 Sun 00:54>

[2025-03-03 Mon 17:57] >> Tree Shaking

With the complexity involved in SBCL image dumps it becomes a hard problem to design an effective tree-shaker.

1.4. Contribs

ID: c33a5587-daab-4e61-a0df-fc6856b00f70
CREATED: <2025-02-11 Tue 20:55>

[2025-03-06 Thu 14:07] >> Extensions

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")))