File: consistent-state.lisp

package info (click to toggle)
acl2 8.6%2Bdfsg-2
  • links: PTS
  • area: main
  • in suites: trixie
  • size: 1,111,420 kB
  • sloc: lisp: 17,818,294; java: 125,359; python: 28,122; javascript: 23,458; cpp: 18,851; ansic: 11,569; perl: 7,678; xml: 5,591; sh: 3,976; makefile: 3,833; ruby: 2,633; yacc: 1,126; ml: 763; awk: 295; csh: 233; lex: 197; php: 178; tcl: 49; asm: 23; haskell: 17
file content (161 lines) | stat: -rw-r--r-- 5,850 bytes parent folder | download | duplicates (2)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
(in-package "ACL2")
(include-book "jvm-model")
(include-book "bcv-model")
;; (defmacro extract-sig-frame (frame method-table)
;;   `(s 'method-table ,method-table
;;      (s 'max-stack 
;;         (g 'max-stack ,frame)
;;         (s 'method-name 
;;            (g 'method-name ,frame)
;;            (s 'pc (g 'pc ,frame)
;;               (s 'op-stack (len (g 'op-stack ,frame))
;;                  (s 'locals
;;                     (extract-sig-locals ,frame) nil)))))))



(defun consistent-caller-frame (caller-frame callee-frame method-table)
  (let*  ((caller-name (g 'method-name caller-frame))
          (callee-name (g 'method-name callee-frame))
          (caller (binding caller-name method-table))
          (callee (binding callee-name method-table))
          (sig-frame (extract-sig-frame caller-frame
                                        method-table))
          (pc (g 'pc sig-frame))
          (record-frame-sig (binding pc (collect-witness-bcv-method caller method-table))))
    (and (bcv-method caller method-table)
         (<= (+ 1 (len (g 'op-stack caller-frame)))
             (g 'max-stack caller-frame))
         (equal (g 'method-name caller)
                caller-name)
         (integerp (g 'pc caller-frame))
         (<= 1 (g 'pc caller-frame))
         (< (g 'pc caller-frame) (len (g 'code caller)))
         ;; (equal (arg (nth (- pc 1) (g 'code caller)))
         ;;       callee-name)
         ;; do I need the above assertion? as long as return value size 
         ;; is the same for all method, we don't. 
         ;; However, this invariant should be easy to maintain. 
         ;; does not add more complexity (proof-wise) to have it. 
         (sig-frame-compatible
          (sig-frame-push-value (g 'ret callee) sig-frame)
          record-frame-sig))))



;; need to deal with top call frame and other call frames below it a bit
;; differently

;; because the caller's pc is pointing to the next instruction, however
;; caller's operand stack does not reflect that!! The hope is that when callee
;; returns it will return the correct number of arguments and the execution can
;; resume from a state. execution from such a state is within the "coverage" of
;; the BCV!!


;; (defun pc-in-range (frame method-table)
;;  (let* ((method-name (g 'method-name frame))
;;         (method (binding method-name method-table))
;;         (pc (g 'pc frame))
;;         (code (g 'code method)))
;;    (and (integerp pc)
;;         (<= 0 pc)
;;         (< pc (len code)))))

(defun consistent-frame (frame method-table)
  (let* ((method-name (g 'method-name frame))
         (method (binding method-name method-table)))
    (and ;; Sun Oct  2 04:29:07 2005
         ;; (pc-in-range frame method-table)
         ;; When PC is out of range, we know the next instruction will be
         ;; undefined. It will be treated as a halt.
         ;;
         ;; so consistent-state will be preserved. 
         ;; and our main goal can still be established under this weaker
         ;; consistent-state predicate. 
         ;; (integerp (g 'pc frame))
         ;; (equal (g 'method-name method)
         ;;         method-name)                 !!! Thu Nov  3 22:31:32 2005
         (bound? method-name method-table)
         (<= (len (g 'op-stack frame))
             (g 'max-stack frame))
         (equal (g 'max-stack frame)
                (g 'max-stack method)))))

;; only assert this! 

(defun consistent-callee-frame (frame method-table)
  (let* ((method-name (g 'method-name frame))
         (method (binding method-name method-table)))
    (and (bcv-method method method-table)
         (equal (g 'method-name method)
                method-name)
         (sig-frame-compatible
          (extract-sig-frame frame method-table)
          (binding (g 'pc frame) 
                   (collect-witness-bcv-method method method-table))))))



(defun consistent-call-stack1 (call-stack topframe method-table)
  (if (endp call-stack) t
    (and (consistent-frame (topx call-stack) method-table)
         (consistent-caller-frame (topx call-stack)
                                  topframe method-table)
         (consistent-call-stack1 
          (popx call-stack) (topx call-stack) method-table))))

;; (i-am-here) 

(defun consistent-call-stack (call-stack method-table)
  (and (consp call-stack)
       (consistent-frame (topx call-stack) method-table)
       (consistent-callee-frame (topx call-stack) method-table)
       (consistent-call-stack1 (popx call-stack) (topx call-stack) method-table)))
                               


(defun all-method-verified1 (method-table1 method-table)
  (if (endp method-table1) t
      (and (bcv-method (cdr (car method-table1))  method-table)
           (all-method-verified1 (cdr method-table1) method-table))))


(defun all-method-verified (method-table)
  (all-method-verified1 method-table method-table))

;;
;; note: this all-method-verified1 is using bcv-simple-method!!  we will have a
;; more "procedural" style bcv-simple-method and bcv-verified-method-table!!
;;


;;(i-am-here) ;; Sun Nov 20 17:19:14 2005


(defun wff-method (method)
  (declare (ignore method))
  t)

(defun wff-method-table (method-table)
  (if (endp method-table) t
    (and (equal (g 'method-name (cdar method-table))
                (caar method-table))
         (wff-method (cdr method-table))
         (wff-method-table (cdr method-table)))))


(defun consistent-state (st)
  (let*  ((method-table (g 'method-table st))
          (call-stack   (g 'call-stack st)))
    (and (pc-in-range st)
         (wff-method-table (g 'method-table st))
         (consistent-call-stack call-stack method-table)
         (all-method-verified method-table))))

;----------------------------------------------------------------------


;----------------------------------------------------------------------