A set of primitives for debugging environments - #838
Conversation
%debug-environment will print a nice representation of the static + dynamic environment.
(define e 0)
(let ((a 1)
(b 2))
(let-syntax ((m (syntax-rules () ((m) 10)))
(s (syntax-rules () ((s) 20))))
(let ((c 3))
(set! e (#%current-environment)))))
(define f (%environment-dynamic-environment e))
(define s (%environment-static-environment e))
stklos> ,d f
stklos> (%frame-length f)
1
stklos> (%frame-ref f 0)
3
And, the really nice part:
stklos> (%debug_environment e)
----------------
/ FRAME with 1 variables:
| c --> 3
\
----------------
/ LEXICAL LEVEL with 2 syntaxes:
| s
| m
\
----------------
/ FRAME with 2 variables:
| b --> 2
| a --> 1
\
----------------
|
It doesn't print the frame owner... Maybe that would be nice? |
|
Now that I think of it... This may be an interesting didactic tool. And it's missing the module name at the bottom! Also, it would be nice to enclose the lines in a pretty box. I'll try to make those enhancements later (much later), and perhaps rewrite it in Scheme. |
|
Also, this: while(CONSP(stat)) { /* For each level */means it only shows things up to the topmost lexical level... So won't work for nested function calls, like this But that would be much harder anyway (we captured |
Unless the information about lexical levels is included in the dynamic frames at runtime... Ok, that is reeeeally not something we'd expect to be easily done at this point 😁 |
|
Hi @jpellegrini, That is really interesting. However, note that I intend to change the way environment are implemented. So, do not invest too much in the current representation of environments. I have already started some work on it, but I will perhaps postpone a bit, since I would like to release a stable version (the previous one is more than a year ago!) . I should also change the way new version are built, because it really takes too much time. |
|
Hmm, ok, so I'll wait for the new environment implementation. |
Any idea of what will be included from the current open pull requests? |
I have no predefined list, but probably not a lot (otherwise, I will never release it :smile) Sorry to be so slow. |
If it's OK, I'll open an issue with a list of suggestions for inclusion, each with a short comment.
You're not! 😁 |
I'm not sure this is OK, but it was reeeeeeally fun to write.
I think I could have written
%debug-environmentin Scheme, but it ws too late when I realized that. 😄