From: Knut O. B. <kn...@on...> - 2008-10-31 13:50:46
|
Hi, I have a method: (defmethod foo ((x fixnum) (y fixnum)) (declare (optimize (speed 3) (safety 0))) (the fixnum (+ x y))) In lispworks I can do: (disassemble (slot-value (find-method #'add '() (mapcar #'find-class '(fixnum fixnum))) 'function)) It does not work in SBCL. I get some result from (disassemble (slot-value (find-method #'add '() (mapcar #'find-class '(fixnum fixnum))) 'SB-PCL::%FUNCTION)) But I don't realy know what it is.. It looks like it is the method dispatcher. Is threre a way to get similar result in SBCL as I did in lispworks with disasemble on methods? -- Konsulent, Fri Programvare / Free Software Consultant Cell: +47 - 473 44 008 Phone: +47 - 21 53 69 00, Fax: +47 - 21 53 69 09 Addr: Nydalsveien 30 B, 0484 Oslo Web: www.freecode.no "It seems that I know that I know. What I'd like to see, Is the I that knows me, When I know that I know that I know." |
From: Nikodemus S. <nik...@ra...> - 2008-10-31 14:11:54
|
On Fri, Oct 31, 2008 at 3:50 PM, Knut Olav Bøhmer <kn...@on...> wrote: > Is threre a way to get similar result in SBCL as I did in lispworks with > disasemble on methods? You have to dip under the hood a bit to get the function you are actually interested in: (defmethod foo ((x fixnum)) (bar x)) (disassemble (sb-pcl::safe-method-fast-function (find-method #'foo () '(fixnum)))) Gives you: ; 12359CE0: 8BD6 MOV EDX, ESI ; no-arg-parsing entry point ; E2: 8B05A89C3512 MOV EAX, [#x12359CA8] ; #<FDEFINITION object for BAR> ; E8: B904000000 MOV ECX, 4 ; ED: FF75F8 PUSH DWORD PTR [EBP-8] ; F0: FF6005 JMP DWORD PTR [EAX+5] ; F3: 0F0B0A BREAK 10 ; error trap ; F6: 02 BYTE #X02 ; F7: 18 BYTE #X18 ; INVALID-ARG-COUNT-ERROR ; F8: 4D BYTE #X4D ; ECX ; F9: 0F0B0A BREAK 10 ; error trap ; FC: 02 BYTE #X02 ; FD: 08 BYTE #X08 ; OBJECT-NOT-FIXNUM-ERROR ; FE: 8E BYTE #X8E ; EDX Teaching DISASSEMBLE about method would be nice, yes. Incidentally, does anyone know why do our fast functions have traps for arg-count and type errors for specializers? Surely they should never happen? Cheers, -- Nikodemus |
From: Christophe R. <cs...@ca...> - 2008-10-31 14:32:40
|
"Nikodemus Siivola" <nik...@ra...> writes: > Incidentally, does anyone know why do our fast functions have traps > for arg-count and type errors for specializers? Surely they should > never happen? The method function can be retrieved and called using (sb-mop:method-function <method>), and dispatches to the fast function. While internally to method dispatch and calling no mismatches should occur, the user can provide arbitrary input to the method function, so something needs to perform checks. Example: (let ((d-o-package-t (find-method #'describe-object nil (mapcar 'find-class '(package t))))) (funcall (sb-mop:method-function d-o-package-t) (list 1 2) nil)) Cheers, Christophe |
From: Nikodemus S. <nik...@ra...> - 2008-10-31 14:46:40
Attachments:
0001-teach-DISASSEMBLE-about-methods.patch
|
On Fri, Oct 31, 2008 at 4:11 PM, Nikodemus Siivola <nik...@ra...> wrote: > Teaching DISASSEMBLE about method would be nice, yes. Attached patch does this, though only methods with fast function get disassembled. Cheers, -- Nikodemus |
From: Nikodemus S. <nik...@ra...> - 2008-10-31 16:58:33
|
On Fri, Oct 31, 2008 at 4:46 PM, Nikodemus Siivola <nik...@ra...> wrote: > On Fri, Oct 31, 2008 at 4:11 PM, Nikodemus Siivola > <nik...@ra...> wrote: > >> Teaching DISASSEMBLE about method would be nice, yes. > > Attached patch does this, though only methods with fast function get > disassembled. After discussing this on #lisp, something a bit different is now in CVS HEAD (1.0.22.5): (disassemble (sb-mop:method-function (find-method ...))) will show you what you want. The part that you are most probably interested in (your code, not the CLOS machinery), is under the ; disassembly for (FAST-METHOD ...) line. Cheers, -- Nikodemus |