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