File: let-designations.lisp

package info (click to toggle)
acl2 8.5dfsg-5
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 991,452 kB
  • sloc: lisp: 15,567,759; javascript: 22,820; cpp: 13,929; ansic: 12,092; perl: 7,150; java: 4,405; xml: 3,884; makefile: 3,507; sh: 3,187; ruby: 2,633; ml: 763; python: 746; yacc: 723; awk: 295; csh: 186; php: 171; lex: 154; tcl: 49; asm: 23; haskell: 17
file content (306 lines) | stat: -rw-r--r-- 10,191 bytes parent folder | download
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
; C Library
;
; Copyright (C) 2021 Kestrel Institute (http://www.kestrel.edu)
; Copyright (C) 2021 Kestrel Technology LLC (http://kestreltechnology.com)
;
; License: A 3-clause BSD license. See the LICENSE file distributed with ACL2.
;
; Author: Alessandro Coglio (coglio@kestrel.edu)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(in-package "C")

(include-book "kestrel/std/util/defmacro-plus" :dir :system)
(include-book "std/util/define" :dir :system)
(include-book "xdoc/defxdoc-plus" :dir :system)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defxdoc+ atc-let-designations
  :parents (atc-implementation)
  :short "Designations of @(tsee let) and @(tsee mv-let) representations
          for ATC."
  :long
  (xdoc::topstring
   (xdoc::p
    "ACL2's @(tsee let) is used to represent four different things in C:")
   (xdoc::ul
    (xdoc::li
     "A local variable declaration with an initializer.")
    (xdoc::li
     "An assignment of an expression to a local variable.")
    (xdoc::li
     "An assignment to an element of an array variable.")
    (xdoc::li
     "A transformation of a (local or array) variable via statements."))
   (xdoc::p
    "The case of an array element assignment
     is recognized by the presence of the array write functions,
     according to the pattern described in the user documentation.
     The other three cases could be recognized
     by looking at the conditions that must hold in each cases,
     but in order to ease ATC's task,
     and also to encourage the user to explicate their intentions,
     we use @(tsee declar) and @(tsee assign)
     to indicate the declaration and assignment cases,
     as explained in the user documentation.
     Thus, the fourth case is what remains when the other three do not apply.")
   (xdoc::p
    "In all four cases above,
     the term to which the variable is bound must be single-valued.
     For multi-valued terms, we follow a similar approach for @(tsee mv-let),
     which is used to represent three different things in C:")
   (xdoc::ul
    (xdoc::li
     "A local variable declaration with an initializer
      that side-effects some array(s)
      in addition to returning the value to initialize the variable with.")
    (xdoc::li
     "An assignment of an expression to a local variable
      where the expression side-effects some array(s)
      in addition to returning the value to assign to the variable.")
    (xdoc::li
     "A transformation of two or more (local or array) variables
      via statements."))
   (xdoc::p
    "These cases mirror three of the @(tsee let) cases described above,
     with the exclusion of array writes, which are only for @(tsee let),
     due to the restrictions on the ACL2 terms accepted by ATC.")
   (xdoc::p
    "For these @(tsee mv-let) cases,
     we use a similiar approach to the @(tsee let) cases,
     i.e. we explicitly use indicators for declarations and assignments.
     But the functions @(tsee declar) and @(tsee assign)
     cannot be applied to multi-valued terms.
     Thus, we introduce macros @('declar<n>') and @('assign<n>'),
     for @('<n>') equal to 2, 3, etc.
     (we stop at some point, but it is easy to add more if needed).
     These must be macros, and cannot be functions,
     because function may be only applied to single-valued terms,
     while macros do not have that restriction;
     and we need to have different macros for different values of @('<n>').
     These representations are described in the user documentation.")
   (xdoc::p
    "Since ATC works on translated terms,
     it does not directly see the macros @('declar<n>') and @('assign<n>').
     But it recognizes their presence as the term patterns they expand to.
     See the ATC developer documentation for details.")
   (xdoc::p
    "We remark that an external (APT) transformation
     could automatically add the needed wrappers
     based on the conditions under which a @(tsee let) or @(tsee mv-let) occurs.
     Thus, our approach does not forgo automation,
     but rather modularizes the problem into simpler pieces."))
  :order-subtopics t
  :default-parent t)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define declar (x)
  :short "Wrapper to indicate a C local variable declaration in a @(tsee let)."
  :long
  (xdoc::topstring-p
   "See @(tsee atc-let-designations).")
  x)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define assign (x)
  :short "Wrapper to indicate a C local variable assignment in a @(tsee let)."
  :long
  (xdoc::topstring-p
   "See @(tsee atc-let-designations).")
  x)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defmacro+ declar2 (x)
  :short "Wrapper to indicate a C local variable declaration
          in an @(tsee mv-let) for 2 bound variables."
  :long
  (xdoc::topstring-p
   "See @(tsee atc-let-designations).")
  `(mv-let (*1 *2)
     ,x
     (mv (declar *1) *2)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defmacro+ assign2 (x)
  :short "Wrapper to indicate a C local variable assignment
          in an @(tsee mv-let) for 2 bound variables."
  :long
  (xdoc::topstring-p
   "See @(tsee atc-let-designations).")
  `(mv-let (*1 *2)
     ,x
     (mv (assign *1) *2)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defmacro+ declar3 (x)
  :short "Wrapper to indicate a C local variable declaration
          in an @(tsee mv-let) for 3 bound variables."
  :long
  (xdoc::topstring-p
   "See @(tsee atc-let-designations).")
  `(mv-let (*1 *2 *3)
     ,x
     (mv (declar *1) *2 *3)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defmacro+ assign3 (x)
  :short "Wrapper to indicate a C local variable assignment
          in an @(tsee mv-let) for 3 bound variables."
  :long
  (xdoc::topstring-p
   "See @(tsee atc-let-designations).")
  `(mv-let (*1 *2 *3)
     ,x
     (mv (assign *1) *2 *3)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defmacro+ declar4 (x)
  :short "Wrapper to indicate a C local variable declaration
          in an @(tsee mv-let) for 4 bound variables."
  :long
  (xdoc::topstring-p
   "See @(tsee atc-let-designations).")
  `(mv-let (*1 *2 *3 *4)
     ,x
     (mv (declar *1) *2 *3 *4)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defmacro+ assign4 (x)
  :short "Wrapper to indicate a C local variable assignment
          in an @(tsee mv-let) for 4 bound variables."
  :long
  (xdoc::topstring-p
   "See @(tsee atc-let-designations).")
  `(mv-let (*1 *2 *3 *4)
     ,x
     (mv (assign *1) *2 *3 *4)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defmacro+ declar5 (x)
  :short "Wrapper to indicate a C local variable declaration
          in an @(tsee mv-let) for 5 bound variables."
  :long
  (xdoc::topstring-p
   "See @(tsee atc-let-designations).")
  `(mv-let (*1 *2 *3 *4 *5)
     ,x
     (mv (declar *1) *2 *3 *4 *5)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defmacro+ assign5 (x)
  :short "Wrapper to indicate a C local variable assignment
          in an @(tsee mv-let) for 5 bound variables."
  :long
  (xdoc::topstring-p
   "See @(tsee atc-let-designations).")
  `(mv-let (*1 *2 *3 *4 *5)
     ,x
     (mv (assign *1) *2 *3 *4 *5)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defmacro+ declar6 (x)
  :short "Wrapper to indicate a C local variable declaration
          in an @(tsee mv-let) for 6 bound variables."
  :long
  (xdoc::topstring-p
   "See @(tsee atc-let-designations).")
  `(mv-let (*1 *2 *3 *4 *5 *6)
     ,x
     (mv (declar *1) *2 *3 *4 *5 *6)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defmacro+ assign6 (x)
  :short "Wrapper to indicate a C local variable assignment
          in an @(tsee mv-let) for 6 bound variables."
  :long
  (xdoc::topstring-p
   "See @(tsee atc-let-designations).")
  `(mv-let (*1 *2 *3 *4 *5 *6)
     ,x
     (mv (assign *1) *2 *3 *4 *5 *6)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defmacro+ declar7 (x)
  :short "Wrapper to indicate a C local variable declaration
          in an @(tsee mv-let) for 7 bound variables."
  :long
  (xdoc::topstring-p
   "See @(tsee atc-let-designations).")
  `(mv-let (*1 *2 *3 *4 *5 *6 *7)
     ,x
     (mv (declar *1) *2 *3 *4 *5 *6 *7)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defmacro+ assign7 (x)
  :short "Wrapper to indicate a C local variable assignment
          in an @(tsee mv-let) for 7 bound variables."
  :long
  (xdoc::topstring-p
   "See @(tsee atc-let-designations).")
  `(mv-let (*1 *2 *3 *4 *5 *6 *7)
     ,x
     (mv (assign *1) *2 *3 *4 *5 *6 *7)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defmacro+ declar8 (x)
  :short "Wrapper to indicate a C local variable declaration
          in an @(tsee mv-let) for 8 bound variables."
  :long
  (xdoc::topstring-p
   "See @(tsee atc-let-designations).")
  `(mv-let (*1 *2 *3 *4 *5 *6 *7 *8)
     ,x
     (mv (declar *1) *2 *3 *4 *5 *6 *7 *8)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defmacro+ assign8 (x)
  :short "Wrapper to indicate a C local variable assignment
          in an @(tsee mv-let) for 8 bound variables."
  :long
  (xdoc::topstring-p
   "See @(tsee atc-let-designations).")
  `(mv-let (*1 *2 *3 *4 *5 *6 *7 *8)
     ,x
     (mv (assign *1) *2 *3 *4 *5 *6 *7 *8)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defmacro+ declar9 (x)
  :short "Wrapper to indicate a C local variable declaration
          in an @(tsee mv-let) for 8 bound variables."
  :long
  (xdoc::topstring-p
   "See @(tsee atc-let-designations).")
  `(mv-let (*1 *2 *3 *4 *5 *6 *7 *8 *9)
     ,x
     (mv (declar *1) *2 *3 *4 *5 *6 *7 *8 *9)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defmacro+ assign9 (x)
  :short "Wrapper to indicate a C local variable assignment
          in an @(tsee mv-let) for 8 bound variables."
  :long
  (xdoc::topstring-p
   "See @(tsee atc-let-designations).")
  `(mv-let (*1 *2 *3 *4 *5 *6 *7 *8 *9)
     ,x
     (mv (assign *1) *2 *3 *4 *5 *6 *7 *8 *9)))