As a follow up to this ... assume that this dynamically rewriting the code is how tracing works ...<br><br>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)<br>
<br>sorry for many spammy emails; the internals are fascinating, i'm trying to get the gurus to answser my questions :-)<br><br><div class="gmail_quote">On Mon, Feb 23, 2009 at 12:44 AM, lowly coder <span dir="ltr"><<a href="mailto:lowlycoder@huoyanjinjing.com">lowlycoder@huoyanjinjing.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">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"<br>
<br>So looking at lib/_repl.scm , we see in ##trace that we have:<br>
<br><span dir="ltr">(##interp-procedure-entry-hook-set! proc new-hook)<br><br>which looks something like:<br><br></span><span dir="ltr">(define-prim (##interp-procedure-entry-hook-set! proc hook)                              <br>

  (let (($code (##interp-procedure-code proc)))                                          <br>    (macro-code-set! $code (##fixnum.- (macro-code-length $code) 2) hook)))   <br><br>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:<br>

<br></span><span dir="ltr">(##define-macro (macro-code-set! c n x)                                                  <br>  `(##vector-set! ,c (##fixnum.+ ,n 5) ,x))     </span><br><span dir="ltr"><br>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.<br>

<br>Any insights / clarifications / tips / deatils appreciated.<br><br>Thanks!<br></span>
</blockquote></div><br>