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" id=":qv">(##interp-procedure-entry-hook-set! proc new-hook)<br><br>which looks something like:<br><br></span><span dir="ltr" id=":qv">(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" id=":qv">(##define-macro (macro-code-set! c n x)                                                  <br>  `(##vector-set! ,c (##fixnum.+ ,n 5) ,x))     </span><br><span dir="ltr" id=":qv"><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>