[gambit-list] way interpreted code is stored / unraveling trace

lowly coder lowlycoder at huoyanjinjing.com
Mon Feb 23 03:44:59 EST 2009


Join me for episode 201 of "gambit detective stories", today, we're going to
try to solve the case of "how the f*ck does trace insert hooks"

So looking at lib/_repl.scm , we see in ##trace that we have:

(##interp-procedure-entry-hook-set! proc new-hook)

which looks something like:

(define-prim (##interp-procedure-entry-hook-set! proc hook)

 (let (($code (##interp-procedure-code proc)))

   (macro-code-set! $code (##fixnum.- (macro-code-length $code) 2) hook)))


this "2" here looks like a magic constant, let's ignore it for now; looking
for macro-code-set! in lib/_eval#.scm , we see:

(##define-macro (macro-code-set! c n x)

 `(##vector-set! ,c (##fixnum.+ ,n 5) ,x))

now, this 5 here is anothe rmagical constant -- but this looks interesting;
for the interpreter, does gambit basically store the procedure in a vector
... and for inserting traces, we just _DYNAMICALLY REWRITE THE CODE_ to
insert stuff before & after? If so, this is really really cool.

Any insights / clarifications / tips / deatils appreciated.

Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20090223/aac0b068/attachment.htm>


More information about the Gambit-list mailing list