[slime-devel] Understanding sbcl source code

Helmut Eller heller at common-lisp.net
Wed Feb 4 14:23:10 UTC 2009


* jcm at sdf.lonestar.org [2009-02-04 13:50+0100] writes:

> I'm sure there's a simple answer to this question.  I'm browsing the sbcl
> source to find the lowest level implementation of CAR and I found this
>
> (defun car (list) (car list))
>
> So the 'real' definition of CAR must be elsewhere.  :)  Perhaps in the C
> source code?  Would someone point me to the correct location?

You can start in the file compiler/generic/objdef.lisp and look at the
definition of cons.  If you macroexpand the define-primitive-object
form you will see somehing like:

  ...
  (DEF-REFFER CAR 0 LIST-POINTER-LOWTAG)

This tells the compiler that CAR is a function to access slot 0 in
objects with LIST-POINTER-LOWTAG. 
If you read further at %DEF-REFFER you will see that CAR is
eventually handled by IR2-CONVERT-REFFER which calls

 (vop slot  ...)
 (move-lvar-result node block locs lvar)

The name of the vop is SLOT.
That vop is defined in compiler/x86/cell.lisp.  
And there we have it:

 (loadw result object offset lowtag)

Yes, M-. could be more useful to find all those places.

Helmut.





More information about the slime-devel mailing list