Skip to content

Instantly share code, notes, and snippets.

@athos
Created December 25, 2009 08:50
Show Gist options
  • Save athos/263565 to your computer and use it in GitHub Desktop.
Save athos/263565 to your computer and use it in GitHub Desktop.
(define-module breakpoint
(use gauche.parameter)
(export bp bp-enabled? inspect set!-inspect resume reset))
(select-module breakpoint)
(define %inspect #f)
(define %set!-inspect #f)
(define %cont #f)
(define %return #f)
(define bp-enabled? (make-parameter #t))
(define-syntax inspect
(syntax-rules ()
[(_ var)
(%inspect 'var)]))
(define-syntax set!-inspect
(syntax-rules ()
[(_ var val)
(%set!-inspect 'var val)]))
(define (reset)
(define (not-suspended . _)
(error "not suspended"))
(call/cc
(lambda (cc)
(set! %inspect not-suspended)
(set! %set!-inspect not-suspended)
(set! %cont not-suspended)
(set! %return cc)
(undefined))))
(define (resume)
(call/cc
(lambda (cc)
(set! %return cc)
(%cont #f))))
(define-syntax bp
(syntax-rules ()
[(_ name var ...)
(when (bp-enabled?)
(call/cc
(lambda (cc)
(define (unknown-symbol sym)
(error "unknown symbol" sym))
(set! %cont cc)
(set! %inspect
(lambda (arg)
(case arg
[(var) var]
...
[else (unknown-symbol arg)])))
(set! %set!-inspect
(lambda (arg val)
(case arg
[(var) (set! var val)]
...
[else (unknown-symbol arg)])))
(%return name))))]))
(provide "breakpoint")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment