state.scm 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. ;;;; (ice-9 debugger state) -- debugger state representation
  2. ;;; Copyright (C) 2002, 2006 Free Software Foundation, Inc.
  3. ;;;
  4. ;; This library is free software; you can redistribute it and/or
  5. ;; modify it under the terms of the GNU Lesser General Public
  6. ;; License as published by the Free Software Foundation; either
  7. ;; version 2.1 of the License, or (at your option) any later version.
  8. ;;
  9. ;; This library is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. ;; Lesser General Public License for more details.
  13. ;;
  14. ;; You should have received a copy of the GNU Lesser General Public
  15. ;; License along with this library; if not, write to the Free Software
  16. ;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. (define-module (ice-9 debugger state)
  18. #:export (make-state
  19. state-stack
  20. state-index
  21. state-flags
  22. set-stack-index!))
  23. (define state-rtd (make-record-type "debugger-state" '(stack index flags)))
  24. (define state? (record-predicate state-rtd))
  25. (define make-state
  26. (let ((make-state-internal (record-constructor state-rtd
  27. '(stack index flags))))
  28. (lambda (stack index . flags)
  29. (make-state-internal stack index flags))))
  30. (define state-stack (record-accessor state-rtd 'stack))
  31. (define state-index (record-accessor state-rtd 'index))
  32. (define state-flags (record-accessor state-rtd 'flags))
  33. (define set-state-index! (record-modifier state-rtd 'index))
  34. (define (set-stack-index! state index)
  35. (let* ((stack (state-stack state))
  36. (ssize (stack-length stack)))
  37. (set-state-index! state
  38. (cond ((< index 0) 0)
  39. ((>= index ssize) (- ssize 1))
  40. (else index)))))
  41. ;;; (ice-9 debugger state) ends here.