Hello
I want to add code to store the current continuation of each step in the single-stepper (to be able to feed it to ##repl-within or similar).
How can I do it?
I have found the ##main-stepper hook and the (##step-handler leapable? $code rte execute-body . other) definition. I've tried:
(define conts '())
(define (stepper-init) (set! ##main-stepper (vector (make-vector 7 (lambda args (apply (lambda (leapable? $code rte execute-body . other) (set! conts (cons $code conts)) (apply ##step-handler args)) args))) #f #f #f #f #f #f #f)))
But I can't manage to extract the continuation out of either |$code|, |rte|, |execute-body| or |other|.
How is |$code| being structured? (I'm seeing that $code is being extracted out of cont in several places, so maybe it's not possible to the the continuation this way.)
I've also tried:
(define (stepper-init) (set! ##main-stepper (vector (make-vector 7 (lambda args (##continuation-capture (lambda (cont) (set! conts (cons cont conts)) (let ((res (apply ##step-handler args))) (step);; attempt against stepping being turned off res))))) #f #f #f #f #f #f #f)))
but somehow single-stepping seems to be turned off after a few steps (even if my above code is compiled). I don't get any interesting continuation this way.
Could you please guide me a bit?
Thanks Christian.
Afficher les réponses par date
I've now tried this:
(define (stepper-init) (set! ##main-stepper (vector (make-vector 7 (lambda args (##continuation-capture (lambda (cont) (set! conts (cons cont conts)))) (apply ##step-handler args))) #f #f #f #f #f #f #f)))
(define (stepper-off) ;; reset to the original handler. (set! ##main-stepper (vector (make-vector 7 ##step-handler) #f #f #f #f #f #f #f)))
(stepper-init)
If I call stepper-init immediately, before loading the code that I want to step into, the issue with stepping being "turned off after a few steps" has gone (I wonder why?).
The new handler catches continuations including the ##step-handler call, to make sure I will be able to continue the stepping process, as I hope.
Here's a sequence of commands I'm trying:
(bruse exp-stepper) (use cj-transactionlog) (step) (transactionlog:open '("tmp/bla"))
*** STOPPED IN (stdin)@4.2 1> #||#,s; | > transactionlog:open | #<procedure #2 transactionlog:open> *** STOPPED IN (stdin)@4.22 1> #||#,s; | > '("tmp/bla") | ("tmp/bla") *** STOPPED IN (stdin)@4.1 1> #||#,s; | > (transactionlog:open '("tmp/bla")) *** STOPPED IN transactionlog:open, "cj-transactionlog.scm"@19.4 1> #||#,s; | | > make-transactionlog | | #<procedure #3 make-transactionlog> *** STOPPED IN transactionlog:open, "cj-transactionlog.scm"@19.24 1> #||#,s; | | > list-of-filepaths | | ("tmp/bla") *** STOPPED IN transactionlog:open, "cj-transactionlog.scm"@21.10 1> #||#,s; | | > list-of-filepaths | | ("tmp/bla") *** STOPPED IN transactionlog:open, "cj-transactionlog.scm"@22.10 1> #||#,s; | | > #f | | #f *** STOPPED IN transactionlog:open, "cj-transactionlog.scm"@23.10 1> ,c | #<transactionlog #4 files: ("tmp/bla") curfile: ("tmp/bla") port: #f parser... #<transactionlog #4 files: ("tmp/bla") curfile: ("tmp/bla") port: #f parser: #f>
(stepper-off) conts
(#<continuation #5> #<continuation #6> #<continuation #7> #<continuation #8> #<continuation #9> #<continuation #10> #<continuation #11> #<continuation #12>)
Now:
(##repl-within #11 #f)
*** STOPPED IN (stdin)@36.2 ---> why is single-stepping now being switched on again? 1> ,c <---- so that it continues until the sub repl is running. 1> , (s #f) <--- ok subr-repl is running, I'm entering (s #f) to continue from cont #11 *** STOPPED IN (stdin)@4.22 1> (step) <-- just to make "really sure" single-stepping is on. 1> ,s <-- one step please. | > '("tmp/bla") ----> but it evaluates everything until the end at once. Why? | ("tmp/bla") #<transactionlog #18 files: ("tmp/bla") curfile: ("tmp/bla") port: #f parser: #f>
I don't understand why the stepper is being switched back on above, and then off again.
Why does this happen?
How does the interpreter use the current continuation itself? Does taking a continuation work at all this way?
Thanks, Christian.
On 21-Jul-06, at 4:04 AM, Christian wrote:
I've now tried this:
(define (stepper-init) (set! ##main-stepper (vector (make-vector 7 (lambda args (##continuation-capture (lambda (cont) (set! conts (cons cont conts)))) (apply ##step-handler args))) #f #f #f #f #f #f #f)))
(define (stepper-off) ;; reset to the original handler. (set! ##main-stepper (vector (make-vector 7 ##step-handler) #f #f #f #f #f #f #f)))
(stepper-init)
If I call stepper-init immediately, before loading the code that I want to step into, the issue with stepping being "turned off after a few steps" has gone (I wonder why?).
It is because the value of ##main-stepper is attached to the code when the interpreter "compiles" it (i.e. when a file is loaded or an expression is evaluated at the REPL or by calling eval). So modifying the value of the variable ##main-stepper will only affect the code loaded after the variable is changed. In principle, this allows you to attach a different stepper to different modules, but Gambit does not take advantage of that.
You can get around this by modifying the main stepper vector itself, i.e.:
(define (stepper-init) (vector-set! ##main-stepper 0 (make-vector 7 (lambda args (##continuation-capture (lambda (cont) (set! conts (cons cont conts)))) (apply ##step-handler args)))))
The new handler catches continuations including the ##step-handler call, to make sure I will be able to continue the stepping process, as I hope.
Here's a sequence of commands I'm trying:
(bruse exp-stepper) (use cj-transactionlog) (step) (transactionlog:open '("tmp/bla"))
*** STOPPED IN (stdin)@4.2 1> #||#,s; | > transactionlog:open | #<procedure #2 transactionlog:open> *** STOPPED IN (stdin)@4.22 1> #||#,s; | > '("tmp/bla") | ("tmp/bla") *** STOPPED IN (stdin)@4.1 1> #||#,s; | > (transactionlog:open '("tmp/bla")) *** STOPPED IN transactionlog:open, "cj-transactionlog.scm"@19.4 1> #||#,s; | | > make-transactionlog | | #<procedure #3 make-transactionlog> *** STOPPED IN transactionlog:open, "cj-transactionlog.scm"@19.24 1> #||#,s; | | > list-of-filepaths | | ("tmp/bla") *** STOPPED IN transactionlog:open, "cj-transactionlog.scm"@21.10 1> #||#,s; | | > list-of-filepaths | | ("tmp/bla") *** STOPPED IN transactionlog:open, "cj-transactionlog.scm"@22.10 1> #||#,s; | | > #f | | #f *** STOPPED IN transactionlog:open, "cj-transactionlog.scm"@23.10 1> ,c | #<transactionlog #4 files: ("tmp/bla") curfile: ("tmp/bla") port: #f parser... #<transactionlog #4 files: ("tmp/bla") curfile: ("tmp/bla") port: #f parser: #f>
(stepper-off) conts
(#<continuation #5> #<continuation #6> #<continuation #7> #<continuation #8> #<continuation #9> #<continuation #10> #<continuation #11> #<continuation #12>)
Now:
(##repl-within #11 #f)
*** STOPPED IN (stdin)@36.2 ---> why is single-stepping now being switched on again?
I think this is because continuation #11 calls ##step-handler and the code you are single stepping is attached to the stepper that you created in stepper-init, not the one you created in stepper-off. I think this problem will go away if you mutate the ##main-stepper vector instead of set!-ing the ##main-stepper variable. (I'm sorry for the doubt but I'm not sure what you are trying to do).
Marc