disassemble
disassemble copied to clipboard
Use `extract-procedure`.
This should fix #18 but doesn't for reasons that I don't yet understand.
Note that this code works, so I'm confused:
#lang racket/base
(define (f #:x [x #f]) (+ x 1))
(require ffi/unsafe/vm)
(define extract-procedure (vm-eval '(lambda (x) (extract-procedure x #f))))
(eq? f (extract-procedure f))
f
(extract-procedure f)
(require disassemble)
(disassemble (extract-procedure f))
@metaxal If you can see what I've done wrong here, I'm sure it's dumb.
I have no clue about what's going on here, sorry. I checked for impersonators (though I don't understand that stuff much) in case that would defeat the eq?
but they all return #f
so I guess they are indeed eq?
. And then I'm at a loss, since (disassemble f)
still raises an exception.
Could it be about transparency, code inspectors and such, that behave differently in the two cases?
@Metaxal can you confirm that the patch in this PR doesn't fix the big for you, but that the code snippet does work?
That's correct:
> (disassemble my-proc)
#<procedure:my-proc> #<procedure:my-proc>
inspector-object: invalid message 'code to object type 'record [,bt for context]
and by contrast:
> (require ffi/unsafe/vm)
> (define extract-procedure (vm-eval '(lambda (x) (extract-procedure x #f))))
> (disassemble (extract-procedure my-proc))
#<procedure:my-proc> #<procedure:my-proc>
0: 4d8b7f0b (mov r15 (mem64+ r15 #xb))
4: 41ff6703 (jmp (mem64+ r15 #x3))
The fact that it shows only 2 lines is probably because my-proc
is defined using define2 — and it looks like there's an indirection that should be avoided, I'm just not sure how.