-
Notifications
You must be signed in to change notification settings - Fork 0
/
analysis-tools.scm
60 lines (56 loc) · 2.6 KB
/
analysis-tools.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
;; Analysis Tools
;; Platform: chez
(define make-probe-func
(lambda (pre-proc pro-proc)
(let ((probe-storage #f))
(lambda (target . arglist)
(begin
(pre-proc probe-storage arglist)
(let ((ret (apply target arglist)))
(pro-proc probe-storage ret)
ret))))))
(define make-probe-repo
(lambda ()
(let ((repo (make-eq-hashtable)))
(define register!
(lambda (key value)
(cond ((hashtable-contains? repo key)
(raise-continuable 'duplicated-registration))
(else (hashtable-set! repo key value)))))
(define quest
(lambda (key)
(cond ((hashtable-contains? repo key)
(hashtable-ref repo key #f))
(else (raise-continuable 'unregisted-key)))))
(define unregister!
(lambda (key)
(cond ((hashtable-contains? repo key)
(hashtable-delete! repo key))
(else (raise-continuable 'unregisted-key)))))
(define dispatcher
(lambda (message . arglist)
(cond ((eq? message 'register!) (apply register! arglist))
((eq? message 'quest) (apply quest arglist))
((eq? message 'unregister!) (apply unregister! arglist))
(else (break #f)))))
dispatcher)))
;;(raise-continuable 'unknown-message)
(define-syntax hook
(syntax-rules (probe! unprobe!)
((_ 'probe! #;probe: symbol #;with: prob)
(begin
(set! symbol (let ((tar symbol)) (lambda arglist (apply prob (cons tar arglist)))))))
((_ 'probe! #;probe: symbol #;with: prob #;save-origion-to repo)
(let ((repository repo))
(repository 'register! 'symbol symbol)
(set! symbol (lambda arglist (apply prob (cons (repository 'quest 'symbol) arglist))))))
((_ 'unprobe! #;recover-origion: symbol #;from: repo)
(begin
(set! symbol (repo 'quest 'symbol))
(repo 'unregister! 'symbol)))))
(define probe-func-time
(lambda (target output-port)
(let ((time (current-time)))
(target)
(let ((interval (time-difference (current-time) time)))
(format output-port "~s ~s\n" x (+ (* (time-second interval) 1000000000) (time-nanosecond interval)))))))