added current-process and trace* and bind
svn: r182
This commit is contained in:
parent
bd1c915644
commit
58114baeee
|
@ -8,7 +8,7 @@
|
|||
(lib "load-annotator.ss" "mztake" "private")
|
||||
(prefix srfi: (lib "search.ss" "srfi" "1"))
|
||||
)
|
||||
(provide annotate-stx annotate-for-single-stepping bindings)
|
||||
(provide annotate-stx annotate-for-single-stepping)
|
||||
|
||||
(define (arglist-bindings arglist-stx)
|
||||
(syntax-case arglist-stx ()
|
||||
|
@ -27,6 +27,7 @@
|
|||
;; Returns a list of pairs `(,variable-name-stx ,variable-value). Each
|
||||
;; item in the list is a shadowed instance of a variable with the given
|
||||
;; name, with the first item being the one in scope.
|
||||
#;
|
||||
(define (bindings top-mark marks sym)
|
||||
(let ([mark-list (cons top-mark (continuation-mark-set->list marks debug-key))])
|
||||
(map (lambda (binding) (list (mark-binding-binding binding)
|
||||
|
|
|
@ -1,16 +1,13 @@
|
|||
(require (lib "animation.ss" "frtime"))
|
||||
(require (lib "mztake-syntax.ss" "mztake"))
|
||||
|
||||
(define-mztake-process p ("sine.ss" [x/sinx-trace 5 8 bind '(x sin-x)]))
|
||||
|
||||
|
||||
(define x/sinx (hold x/sinx-trace))
|
||||
(require (lib "animation.ss" "frtime")
|
||||
(lib "list.ss" "frtime")
|
||||
(lib "useful-code.ss" "mztake" "private"))
|
||||
(require (lib "mztake.ss" "mztake"))
|
||||
|
||||
(define x/sinx (hold (trace "sine.ss" 5 8 (bind (x sin-x) (list x sin-x)))))
|
||||
|
||||
(define x (first x/sinx))
|
||||
(define sin-x (second x/sinx))
|
||||
|
||||
|
||||
(printf-b "x: ~a" x)
|
||||
(printf-b "sin(x/20): ~a" sin-x)
|
||||
|
||||
|
@ -37,5 +34,5 @@
|
|||
(if (< 200 x) "blue" "darkblue") #| Quadrants 3 and 4 |#
|
||||
(if (< 200 x) "red" "darkred")))))))) #| 1 and 2 |#
|
||||
|
||||
(start/resume)
|
||||
|
||||
(start/resume p)
|
|
@ -17,11 +17,7 @@
|
|||
; ; ; ; ; ; ;; ; ; ; ; ;
|
||||
; ;;;;; ;;;; ;;;; ; ;;; ;;; ;;;;
|
||||
|
||||
(define-struct trace-struct (evnt-rcvr)) ; frp:event-receiver
|
||||
|
||||
(define-struct (entry-trace trace-struct) ())
|
||||
(define-struct (bind-trace trace-struct)
|
||||
(variable-to-bind)) ; symbol
|
||||
(define-struct trace-struct (evnt-rcvr thunk)) ; frp:event-receiver
|
||||
|
||||
(define-struct debug-client (modpath ; complete-path of the module
|
||||
tracepoints ; hash-table of traces
|
||||
|
@ -35,7 +31,8 @@
|
|||
exceptions ; (an event stream) Exceptions thrown during the evaluation of the target
|
||||
runtime ; Behavior with current runtime in milliseconds
|
||||
main-client ; the main client module that will be run
|
||||
clients)) ; list of all the clients attached to this process
|
||||
clients ; list of all the clients attached to this process
|
||||
marks)) ; while paused, the marks at the point of the pause (else false)
|
||||
|
||||
;###########################################################################################################
|
||||
|
||||
|
@ -55,14 +52,6 @@
|
|||
; ; ; ; ; ; ;; ; ; ; ;; ; ; ; ; ; ;; ; ; ; ; ; ;
|
||||
; ;;;;; ;;;; ;;;; ; ;;; ;;; ;;;;; ; ;;;; ;;;; ; ;;; ;;;; ; ;;;;
|
||||
|
||||
; Creates a trace that binds to the value of a variable in scope
|
||||
(define (create-bind-trace sym-to-bind) ; ((union (listof symbol?) symbol?) . -> . trace?)
|
||||
(make-bind-trace (frp:event-receiver) sym-to-bind))
|
||||
|
||||
; Creates a trace that simply alerts that it was hit
|
||||
(define (create-entry-trace) ; (void? . -> . trace?)
|
||||
(make-entry-trace (frp:event-receiver)))
|
||||
|
||||
(define (create-empty-debug-process)
|
||||
(make-debug-process (make-custodian)
|
||||
null ; run-semaphore - null so we know it has never started
|
||||
|
@ -71,7 +60,8 @@
|
|||
(frp:event-receiver) ; exceptions
|
||||
null ; runtime
|
||||
null ; main-client
|
||||
empty)) ; clients
|
||||
empty ; clients
|
||||
false)) ; marks
|
||||
|
||||
(define (create-empty-debug-client)
|
||||
(make-debug-client null ; modpath
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
#|
|
||||
(mztake-process p ("sine.ss" [sin/x 5 8 bind '(sin-x x)]
|
||||
[foo 10 20 bind '(sin-x x)])
|
||||
("sine-extra.ss"))
|
||||
|
||||
(define sin/x (hold sin/x))
|
||||
(define x (+ 200 (second sin/x)))
|
||||
(print-b "x:" x)
|
||||
|
||||
*** translates to ***
|
||||
|
||||
(define p (create-debug-process))
|
||||
(define-values (sin/x foo ...)(
|
||||
(let ([tmp (create-debug-client p "sine.ss")])
|
||||
(values (create-trace tmp 5 8 'bind '(sin-x x))))
|
||||
...
|
||||
|#
|
||||
|
||||
(module mztake-syntax (lib "frtime-big.ss" "frtime")
|
||||
|
||||
(require (lib "mztake.ss" "mztake")
|
||||
(lib "useful-code.ss" "mztake" "private"))
|
||||
|
||||
(define-syntax define-mztake-process
|
||||
(syntax-rules (define-mztake-process)
|
||||
[(define-mztake-process proc-id (client (trace line col cmd . args) ...) ...)
|
||||
(begin
|
||||
(define proc-id (create-debug-process))
|
||||
(begin
|
||||
(define-values (trace ...)
|
||||
(let ([tmp (create-debug-client proc-id 'client)])
|
||||
(values
|
||||
(create-trace tmp line col 'cmd . args)
|
||||
...))) ...))]))
|
||||
|
||||
(provide define-mztake-process
|
||||
(all-from (lib "frtime-big.ss" "frtime"))
|
||||
(all-from (lib "mztake.ss" "mztake"))
|
||||
(all-from (lib "useful-code.ss" "mztake" "private"))))
|
|
@ -13,10 +13,10 @@
|
|||
"annotator.ss"
|
||||
)
|
||||
|
||||
(provide/contract [start/resume (debug-process? . -> . void?)]
|
||||
[kill (debug-process? . -> . void?)]
|
||||
(provide/contract [start/resume (() (debug-process?) . opt-> . void?)]
|
||||
[kill (() (debug-process?) . opt-> . void?)]
|
||||
[kill-all (-> void?)]
|
||||
[pause (debug-process? . -> . void?)]
|
||||
[pause (() (debug-process?) . opt-> . void?)]
|
||||
[rename debug-process-exceptions
|
||||
process:exceptions
|
||||
(debug-process? . -> . frp:event?)]
|
||||
|
@ -107,43 +107,8 @@
|
|||
(display (format "mztake: ~a~n---~n" str)))
|
||||
|
||||
|
||||
(define create-trace
|
||||
(case-lambda
|
||||
[(client line col type args)
|
||||
(case type
|
||||
['bind (trace/bind client line col args)]
|
||||
['entry (trace/entry client line col)]
|
||||
[else (script-error (format "Invalid trace type: `~a' in client: `~a'"
|
||||
(symbol->string type)
|
||||
(debug-client-modpath client)))])]
|
||||
|
||||
[(client line col type)
|
||||
(create-trace client line col type null)]))
|
||||
|
||||
|
||||
; takes a single trace, looks up what it needs to do, and returns an frp-event to publish
|
||||
(define (trace->frp-event client top-mark marks trace)
|
||||
(match trace
|
||||
[($ entry-trace evnt-rcvr)
|
||||
(list evnt-rcvr #t)]
|
||||
|
||||
[($ bind-trace evnt-rcvr variable-to-bind)
|
||||
(let* ([vars (if (list? variable-to-bind) variable-to-bind
|
||||
(list variable-to-bind))]
|
||||
[values (map
|
||||
(lambda (var)
|
||||
(let ([val (bindings top-mark marks var)])
|
||||
(if (empty? val)
|
||||
(script-error
|
||||
(format "Variable not found at the syntax location for the BIND: `~a'" var))
|
||||
(cadar (bindings top-mark marks var)))))
|
||||
vars)])
|
||||
(list evnt-rcvr
|
||||
(if (list? variable-to-bind) values
|
||||
(first values))))]))
|
||||
|
||||
; returns a memoized function that takes (line column) -> position
|
||||
; line-col->pos : (debug-file? . -> . (number? number? . -> . (union void? number?)))
|
||||
;; returns a memoized function that takes (line column) -> position
|
||||
;; line-col->pos : (debug-file? . -> . (number? number? . -> . (union void? number?)))
|
||||
(define (line-col->pos filename)
|
||||
; produces a nested list of (line column offset) for all addressable syntax
|
||||
(define (unwrap-syntax stx)
|
||||
|
@ -198,41 +163,41 @@
|
|||
; ; ; ;;;; ;;; ;;;; ;;;; ;;;; ; ;;;; ; ; ; ;;; ;;;;
|
||||
|
||||
|
||||
(define current-process (make-parameter (create-empty-debug-process)))
|
||||
|
||||
(define (find-client process modpath)
|
||||
(begin0/rtn
|
||||
(cond
|
||||
[(memf (lambda (c) (equal? (debug-client-modpath c) (path->string modpath)))
|
||||
(debug-process-clients process)) => first]
|
||||
[else false])
|
||||
(printf "find-client ~s ~s : ~s~n" (map debug-client-modpath (debug-process-clients process)) modpath rtn)))
|
||||
[else false]))
|
||||
|
||||
(define (break? process client)
|
||||
(printf "break? ~a ~a~n" client (debug-client-tracepoints client))
|
||||
(let ([tracepoints (and client (debug-client-tracepoints client))])
|
||||
(if tracepoints
|
||||
(lambda (pos)
|
||||
(begin0/rtn
|
||||
(hash-get tracepoints (sub1 pos) (lambda () false))
|
||||
(printf "break? ~a~n" rtn)))
|
||||
(lambda (pos) false))))
|
||||
(or (not (running-now? process))
|
||||
(and tracepoints
|
||||
(hash-get tracepoints (sub1 pos) (lambda () false)))))))
|
||||
|
||||
(define (receive-result process client top-mark marks)
|
||||
(printf "receive-result~n")
|
||||
(define (receive-result process client top-mark rest-marks)
|
||||
(let* ([byte-offset (sub1 (syntax-position (mark-source top-mark)))]
|
||||
[traces (hash-get (debug-client-tracepoints client) byte-offset)])
|
||||
[traces (hash-get (debug-client-tracepoints client) byte-offset (lambda () empty))]
|
||||
[marks (cons top-mark (continuation-mark-set->list rest-marks debug-key))])
|
||||
|
||||
(assert (not (empty? traces))
|
||||
(format "There are no traces at offset ~a, but a trace point is defined!~n"
|
||||
(number->string byte-offset)))
|
||||
(set-debug-process-marks! process marks)
|
||||
|
||||
; Run all traces at this trace point
|
||||
(let ([to-send (map (lambda (t) (trace->frp-event client top-mark marks t)) traces)])
|
||||
(printf "frp:send-synchronous-events ~a~n" to-send)
|
||||
(frp:send-synchronous-events to-send))
|
||||
(let ([to-send (map (lambda (t)
|
||||
(list (trace-struct-evnt-rcvr t)
|
||||
((trace-struct-thunk t))))
|
||||
traces)])
|
||||
(unless (empty? to-send)
|
||||
(frp:send-synchronous-events to-send)))
|
||||
|
||||
; Now that we processed the trace, do we want to pause ojr continue
|
||||
(unless (running-now? process)
|
||||
(semaphore-wait (debug-process-run-semaphore process)))))
|
||||
(semaphore-wait (debug-process-run-semaphore process)))
|
||||
|
||||
(set-debug-process-marks! process false)))
|
||||
|
||||
|
||||
|
||||
|
@ -256,12 +221,8 @@
|
|||
`(file ,(debug-client-modpath (debug-process-main-client process)))
|
||||
;; annotate-module?
|
||||
(lambda (filename module-name)
|
||||
(begin0/rtn
|
||||
(memf (lambda (c) (equal? (debug-client-modpath c) (path->string filename)));; TODO: harmonize path & string
|
||||
(debug-process-clients process))
|
||||
(printf "annotate-module? ~s ~s ~s : ~s~n"
|
||||
(map debug-client-modpath (debug-process-clients process))
|
||||
filename module-name rtn)))
|
||||
(debug-process-clients process)))
|
||||
;; annotator
|
||||
(lambda (stx)
|
||||
(let ([client (and (syntax-source stx)
|
||||
|
@ -301,9 +262,12 @@
|
|||
(split-path (debug-client-modpath (debug-process-main-client process)))])
|
||||
name))
|
||||
|
||||
|
||||
|
||||
; Switches the running state on or off
|
||||
; (debug-process? boolean? . -> . void?)
|
||||
(define (set-running! process run?)
|
||||
(define set-running!
|
||||
(opt-lambda (run? [process (current-process)])
|
||||
(set-debug-process-running?! process run?)
|
||||
|
||||
; start the debugger if needed
|
||||
|
@ -313,15 +277,17 @@
|
|||
|
||||
(when run?
|
||||
(semaphore-post (debug-process-run-semaphore process)))
|
||||
(void))
|
||||
(void)))
|
||||
|
||||
|
||||
(define (pause process)
|
||||
(define pause
|
||||
(opt-lambda ([process (current-process)])
|
||||
(print-info (format "pausing debugger for ~a" (main-client-name process)))
|
||||
(set-running! process #f))
|
||||
(set-running! #f process)))
|
||||
|
||||
|
||||
(define (start/resume process)
|
||||
(define start/resume
|
||||
(opt-lambda ([process (current-process)])
|
||||
(let ([val (frp:value-now (debug-process-exited? process))])
|
||||
(when (not (null? (debug-process-run-semaphore process)))
|
||||
(print-info (format "resuming debugger for ~a" (main-client-name process))))
|
||||
|
@ -330,23 +296,25 @@
|
|||
(if ((not (equal? val frp:undefined)) . and . val)
|
||||
(print-info (format "Cannot restart a process once it has exited (~a). Try restarting the script."
|
||||
(main-client-name process)))
|
||||
(set-running! process #t))))
|
||||
(set-running! #t process)))))
|
||||
|
||||
; Kills and prints out a message stating it
|
||||
(define (kill process)
|
||||
(define kill
|
||||
(opt-lambda ([process (current-process)])
|
||||
(print-info (format "killing debugger for ~a" (main-client-name process)))
|
||||
(stop process))
|
||||
(stop process)))
|
||||
|
||||
; Kills the debugger process immediately and permanently
|
||||
(define (stop process)
|
||||
(define stop
|
||||
(opt-lambda ([process (current-process)])
|
||||
; remove the process from the process list
|
||||
(set! all-debug-processes (remq process all-debug-processes))
|
||||
|
||||
(set-running! process #f)
|
||||
(set-running! #f process)
|
||||
; shutdown the custodian
|
||||
(custodian-shutdown-all (debug-process-custodian process))
|
||||
; set the exit predicate to 'exited'
|
||||
(frp:set-cell! (debug-process-exited? process) #t))
|
||||
(frp:set-cell! (debug-process-exited? process) #t)))
|
||||
|
||||
|
||||
; creates and initializes a debug process
|
||||
|
@ -354,6 +322,7 @@
|
|||
(let ([p (create-empty-debug-process)])
|
||||
(set-debug-process-runtime! p (runtime p))
|
||||
(set! all-debug-processes (cons p all-debug-processes))
|
||||
(current-process p)
|
||||
p))
|
||||
|
||||
|
||||
|
@ -396,12 +365,14 @@
|
|||
; ;
|
||||
|
||||
|
||||
#;(define (running? process)
|
||||
#;
|
||||
(define (running? process)
|
||||
(script-error "client-running? is broken")
|
||||
(and (running-now? process)
|
||||
(not (debug-process-exited? process))))
|
||||
|
||||
#;(define (time-per-event/milliseconds process behavior)
|
||||
#;
|
||||
(define (time-per-event/milliseconds process behavior)
|
||||
(frp:lift (truncate (/ (frp:value-now (debug-process-runtime process))
|
||||
(add1 (frp:value-now (count-e (frp:changes behavior))))))))
|
||||
|
||||
|
@ -460,8 +431,39 @@
|
|||
client))))
|
||||
|
||||
|
||||
(define (trace* modpath line col thunk)
|
||||
(let* ([clients (member modpath (debug-process-clients (current-process)))]
|
||||
[client (if clients
|
||||
(first clients)
|
||||
(create-debug-client (current-process) modpath))]
|
||||
[trace-hash (debug-client-tracepoints client)]
|
||||
[trace (make-trace-struct (frp:event-receiver) thunk)]
|
||||
[pos ((debug-client-line-col->pos client) line col)])
|
||||
; add the trace to the list of traces for that byte-offset
|
||||
(hash-put! trace-hash pos
|
||||
(append (hash-get trace-hash pos (lambda () '()))
|
||||
(list trace)))
|
||||
(trace-struct-evnt-rcvr trace)))
|
||||
|
||||
(define-syntax trace
|
||||
(syntax-rules ()
|
||||
[(_ client line col)
|
||||
(trace* client line col (lambda () true))]
|
||||
[(_ client line col body ...)
|
||||
(trace* client line col (lambda () body ...))]))
|
||||
|
||||
(define-syntax bind
|
||||
(syntax-rules ()
|
||||
[(_ (name ...) body0 body ...)
|
||||
(let ([name (mark-binding-value
|
||||
(first (lookup-all-bindings
|
||||
(lambda (id) (eq? (syntax-e id) 'name))
|
||||
(debug-process-marks (current-process)))))] ...)
|
||||
body0 body ...)]))
|
||||
|
||||
; (client (offset | line column) (symbol | listof symbols) -> (frp:event-receiver)
|
||||
; (debug-client? number? number? (union symbol? (listof symbol?)) . -> . frp:event?)
|
||||
#;
|
||||
(define (trace/bind client line col binding-symbol)
|
||||
(when (empty? binding-symbol)
|
||||
(script-error (format "No symbols defined in BIND for client: `~a'"
|
||||
|
@ -480,6 +482,7 @@
|
|||
|
||||
|
||||
;(debug-file? number? number? . -> . frp:event?)
|
||||
#;
|
||||
(define (trace/entry client line col)
|
||||
(let ([trace-hash (debug-client-tracepoints client)]
|
||||
[trace (create-entry-trace)]
|
||||
|
@ -490,8 +493,7 @@
|
|||
(trace-struct-evnt-rcvr trace)))
|
||||
|
||||
|
||||
(provide create-trace
|
||||
create-debug-process
|
||||
(provide trace trace* bind create-debug-process
|
||||
create-debug-client
|
||||
mztake-version)
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
|#
|
||||
|
||||
(define (require/sandbox+annotations custodian err-display-handler initial-module annotate-module? annotator)
|
||||
(printf "require/sandbox+annotations ~a~n" initial-module)
|
||||
(parameterize ([current-custodian custodian]
|
||||
[current-namespace (make-namespace-with-mred)]
|
||||
[error-display-handler err-display-handler])
|
||||
|
|
Loading…
Reference in New Issue
Block a user