[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Where is the source of a function within cl package

james

10/13/2015 2:15:00 AM

I want to see how the function values implementation, Is there any easy way? I am using slime+sbcl.

http://clhs.lisp.se/Body/f_...
3 Answers

Pascal J. Bourguignon

10/13/2015 4:21:00 AM

0

james <dinglei2008@gmail.com> writes:

> I want to see how the function values implementation, Is there any
> easy way? I am using slime+sbcl.
>
> http://clhs.lisp.se/Body/f_...

The function values the implementation like its mother.
For without the implemention, the function would be dead code.

--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

rpw3

10/13/2015 6:05:00 AM

0

Pascal J. Bourguignon <pjb@informatimago.com> wrote:
+---------------
| james <dinglei2008@gmail.com> writes:
| > I want to see how the function values implementation,
| > Is there any easy way? I am using slime+sbcl.
| > http://clhs.lisp.se/Body/f_...
|
| The function values the implementation like its mother.
| For without the implemention, the function would be dead code.
+---------------

To expand slightly on Pascal's excellent koan, the
definition of VALUES (and VALUES-LIST) is hardwired deep
into the specific CL implementation's choice of machine
language function calling sequences for a given CPU target.
I don't know about SBCL, but in its ancestor CMUCL,
VALUES is defined as:

(defun values (&rest values)
"Returns all of its arguments, in order, as values."
(values-list values))

and VALUES-LIST is defined directly as a VOP [a Virtual Machine
Operation], part of the code generator of CMUCL. VOPs are
implemented as semi-declarative macros that build tables
that the code generator uses, including bits of parameterized
pseudo-assembler code. You will not be able to understand the
definition of this VOP without a deep understanding of the
CMUCL compiler internals, including the stack organization,
register use, and function calling sequence [for each CPU target].

But the code is certainly available if you really, *really*
want to look at it. Just download this ~8 MB tarball:

https://common-lisp.net/project/cmucl/downloads/release/21a/cmucl-src-2...

unpack it somewhere [it will use ~45 MB or so of disk space],
and then look in the file "src/compiler/x86/values.lisp" starting
with the line containing "(define-vop (values-list)".

Hmmm... (google*) (*google*) (grep*) (grep*)...

I see here that the code for VALUES-LIST in SBCL for x86 targets
is still very similar to that of CMUCL:

http://sourceforge.net/p/sbcl/sbcl-cvs-import/ci/d147d512602d761a2dcdfded506dd1a8f9a140dc/tree/src/compiler/x86/values.lisp?...
...
[line 41] (define-vop (values-list)
...[elided].. )

But ditto my comments above re CMUCL. That is,
"You are not expected to understand this."[1]

And of course, for other CPU targets and other CL
implementations, it will be different -- probably
very, very different.


-Rob

[1] As Dennis Ritchie famously said about the context-switch
code in v.6 Unix:
http://www.catb.org/jargon/html/Y/You-are-not-expected-to-understand...
http://www.tuhs.org/Usenet/notunde...

-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <http://rpw...
San Mateo, CA 94403

Helmut Eller

10/13/2015 8:32:00 AM

0

On Mon, Oct 12 2015, james wrote:

> I want to see how the function values implementation, Is there any
> easy way? I am using slime+sbcl.

If you press M-. on values you will see a list like this:

/scratch/sbcl/src/code/eval.lisp
(defun values)
/scratch/sbcl/src/code/setf.lisp
(define-setf-expander values)
/scratch/sbcl/src/compiler/ir1opt.lisp
(:deftransform values "optimize")
/scratch/sbcl/src/compiler/srctran.lisp
(:defoptimizer values sb-c:derive-type)
(:define-source-transform values)
/scratch/sbcl/src/compiler/ir2tran.lisp
(:defoptimizer values sb-c:ir2-convert)
/scratch/sbcl/src/compiler/fndb.lisp
(declaim values sb-c:defknown)

As you can see the SBCL compiler tries to recognize and optimize a
number of different cases. The most important to understand is, I think,
(:defoptimizer values sb-c:ir2-convert). To understand that you need to
understand SBCLs IR2 representation.

Helmut