disassemble icon indicating copy to clipboard operation
disassemble copied to clipboard

Use `extract-procedure`.

Open samth opened this issue 1 year ago • 5 comments

This should fix #18 but doesn't for reasons that I don't yet understand.

samth avatar Oct 19 '22 21:10 samth

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))

samth avatar Oct 19 '22 21:10 samth

@metaxal If you can see what I've done wrong here, I'm sure it's dumb.

samth avatar Oct 19 '22 21:10 samth

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.

Metaxal avatar Oct 19 '22 22:10 Metaxal

Could it be about transparency, code inspectors and such, that behave differently in the two cases?

Metaxal avatar Oct 20 '22 10:10 Metaxal

@Metaxal can you confirm that the patch in this PR doesn't fix the big for you, but that the code snippet does work?

samth avatar Oct 20 '22 11:10 samth

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.

Metaxal avatar Oct 21 '22 12:10 Metaxal