Skip to content

How SBCL does multiple entry points.

Неточка Незванова edited this page Oct 22, 2021 · 2 revisions

What sbcl does to:

(defun f (x &optional (y (complex-thing)))
  (+ x y))

=>
     
COMPONENT: DEFUN F
  FUNCTION: f-XEP (arg-count x y)
    if arg-count = 1
       tail-call f-optional-processor (x)
    if arg-count = 2
       tail-call fixed-arg-f (x y)
    else arg-count-error ()
  FUNCTION: f-optional-processor (x)
    tail-call fixed-arg-f (x (call complex-thing))
  FUNCTION: fixed-arg-f (x y)
    (+ x y)

Then whenever you call f externally like (f 4) from the REPL it is actually f-XEP that you are calling.

If f was compiled in the same component as another function g which calls f like (f 3 4), then g can simply use knowledge of F's arglist to pick the fixed-arg-f "entry point" function without going through f-XEP.

Clone this wiki locally