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

lowly coder lowlycoder at huoyanjinjing.com
Mon Feb 23 03:50:02 EST 2009


As a follow up to this ... assume that this dynamically rewriting the code
is how tracing works ...

does this essentially mean that trying to get the entire stack frame / call
stack would be rather difficult (or atleast the current approach would not
easily work)

sorry for many spammy emails; the internals are fascinating, i'm trying to
get the gurus to answser my questions :-)

On Mon, Feb 23, 2009 at 12:44 AM, lowly coder
<lowlycoder at huoyanjinjing.com>wrote:

> 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/916253fc/attachment.htm>


More information about the Gambit-list mailing list