Skip to content

A set of primitives for debugging environments - #838

Open
jpellegrini wants to merge 3 commits into
egallesio:masterfrom
jpellegrini:debug-envs
Open

A set of primitives for debugging environments#838
jpellegrini wants to merge 3 commits into
egallesio:masterfrom
jpellegrini:debug-envs

Conversation

@jpellegrini

Copy link
Copy Markdown
Contributor

I'm not sure this is OK, but it was reeeeeeally fun to write.

(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
\
 ----------------

I think I could have written %debug-environment in Scheme, but it ws too late when I realized that. 😄

%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
\
 ----------------
@jpellegrini

Copy link
Copy Markdown
Contributor Author

It doesn't print the frame owner... Maybe that would be nice?

@jpellegrini

Copy link
Copy Markdown
Contributor Author

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.

@jpellegrini

Copy link
Copy Markdown
Contributor Author

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

stklos> (define (g x) (let ((a 2)) (set! e (#%current-environment)) (* a x)))
;; g
stklos> (define (f x) (let ((b 10)) (- (g x) b)))
;; f
stklos> (f 50)
90
stklos> e
#[environment 7fecc99e7990]
stklos> (%debug-environment e)
 ----------------
/ FRAME with 1 variables:
| a --> 2
\
 ----------------
/ FRAME with 1 variables:
| x --> 50
\
 ----------------

But that would be much harder anyway (we captured g's static info. Nobody did that for f, and we can't do that at runtime... And we don't know at compile time who will be calling g!)

@jpellegrini

Copy link
Copy Markdown
Contributor Author

means it only shows things up to the topmost lexical level... So won't work for nested function calls, like this

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 😁

@egallesio

Copy link
Copy Markdown
Owner

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.

@jpellegrini

Copy link
Copy Markdown
Contributor Author

Hmm, ok, so I'll wait for the new environment implementation.
By the way, maybe it's also good to wait for the new environments before trying new implementations of macro hygiene and macro lexical scope? I'll wait. :)

@jpellegrini

Copy link
Copy Markdown
Contributor Author

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!) .

Any idea of what will be included from the current open pull requests?

@egallesio

Copy link
Copy Markdown
Owner

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)
The Pr which are not merged are the ones I have not completely looked at because they are too complex, or simple ones but which need some modification.

Sorry to be so slow.

@jpellegrini

Copy link
Copy Markdown
Contributor Author

I have no predefined list, but probably not a lot (otherwise, I will never release it :smile) The Pr which are not merged are the ones I have not completely looked at because they are too complex, or simple ones but which need some modification.

If it's OK, I'll open an issue with a list of suggestions for inclusion, each with a short comment.

Sorry to be so slow.

You're not! 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants