|
16 | 16 | (mat vector
|
17 | 17 | (equal? (vector 1 2 3 4) '#(1 2 3 4))
|
18 | 18 | (eq? (vector) '#())
|
19 |
| - ) |
| 19 | + ) |
20 | 20 |
|
21 | 21 | (mat immutable-vector
|
22 | 22 | (equal? (immutable-vector 1 2 3 4) (vector->immutable-vector '#(1 2 3 4)))
|
|
129 | 129 | )
|
130 | 130 |
|
131 | 131 | (mat vector-copy
|
132 |
| - (equal? (vector-copy '#()) '#()) |
| 132 | + (eq? (vector-copy '#()) '#()) |
133 | 133 | (equal? (vector-copy '#(a b c)) '#(a b c))
|
134 | 134 | (equal? (vector-copy '#(a b c) 0 1) '#(a))
|
135 | 135 | (equal? (vector-copy '#(a b c) 2 1) '#(c))
|
136 | 136 | (equal? (vector-copy '#(a b c d) 1 2) '#(b c))
|
137 | 137 | (eq? (vector-copy '#(a b c d) 1 0) '#())
|
| 138 | + (mutable-vector? (vector-copy '#(a b c))) |
| 139 | + (mutable-vector? (vector-copy '#(a b c) 0 1)) |
| 140 | + (mutable-vector? (vector-copy '#(a b c) 2 1)) |
| 141 | + (mutable-vector? (vector-copy '#(a b c d) 1 2)) |
138 | 142 | (let* ((x1 (vector 1 2 3)) (x2 (vector-copy x1)))
|
139 | 143 | (and (equal? x2 x1) (not (eq? x2 x1))))
|
140 | 144 | (andmap
|
|
150 | 154 | (error? (vector-copy '#(a b c) 2 -1))
|
151 | 155 | )
|
152 | 156 |
|
| 157 | +(mat immutable-vector-copy |
| 158 | + (eq? (immutable-vector-copy '#()) (immutable-vector)) |
| 159 | + (equal? (immutable-vector-copy '#(a b c)) '#(a b c)) |
| 160 | + (equal? (immutable-vector-copy '#(a b c) 0 1) '#(a)) |
| 161 | + (equal? (immutable-vector-copy '#(a b c) 2 1) '#(c)) |
| 162 | + (equal? (immutable-vector-copy '#(a b c d) 1 2) '#(b c)) |
| 163 | + (immutable-vector? (immutable-vector-copy '#(a b c))) |
| 164 | + (immutable-vector? (immutable-vector-copy '#(a b c) 0 1)) |
| 165 | + (immutable-vector? (immutable-vector-copy '#(a b c) 2 1)) |
| 166 | + (immutable-vector? (immutable-vector-copy '#(a b c d) 1 2)) |
| 167 | + (eq? (immutable-vector-copy '#(a b c d) 1 0) (immutable-vector)) |
| 168 | + (let* ((x1 (vector 1 2 3)) (x2 (immutable-vector-copy x1))) |
| 169 | + (and (equal? x2 x1) (not (eq? x2 x1)))) |
| 170 | + (andmap |
| 171 | + (lambda (n) |
| 172 | + (let ([v (vector-map random (make-vector n 1000))]) |
| 173 | + (equal? (immutable-vector-copy v) v))) |
| 174 | + (map random (make-list 500 2500))) |
| 175 | + (error? (immutable-vector-copy '(a b c))) |
| 176 | + (error? (immutable-vector-copy '#(a b c) 'x 2)) |
| 177 | + (error? (immutable-vector-copy '#(a b c) 1 'x)) |
| 178 | + (error? (immutable-vector-copy '#(a b c) -1 2)) |
| 179 | + (error? (immutable-vector-copy '#(a b c) 1 3)) |
| 180 | + (error? (immutable-vector-copy '#(a b c) 2 -1)) |
| 181 | + ) |
| 182 | + |
153 | 183 | (mat vector-set/copy
|
154 | 184 | (equal? (vector-set/copy '#(a b c) 0 'x) '#(x b c))
|
155 | 185 | (equal? (vector-set/copy '#(a b c) 1 'x) '#(a x c))
|
156 | 186 | (equal? (vector-set/copy '#(a b c) 2 'x) '#(a b x))
|
157 | 187 | (equal? (vector-set/copy '#(a b c d e f g h i) 2 'x) '#(a b x d e f g h i))
|
| 188 | + (mutable-vector? (vector-set/copy '#(a b c) 0 'x)) |
| 189 | + (mutable-vector? (vector-set/copy '#(a b c) 1 'x)) |
| 190 | + (mutable-vector? (vector-set/copy '#(a b c) 2 'x)) |
| 191 | + (mutable-vector? (vector-set/copy '#(a b c d e f g h i) 2 'x)) |
158 | 192 | (error? (vector-set/copy 1))
|
159 | 193 | (error? (vector-set/copy '#(a b c)))
|
160 | 194 | (error? (vector-set/copy '#(a b c) 1))
|
|
163 | 197 | (error? (vector-set/copy '#(a b c) 3 'x))
|
164 | 198 | )
|
165 | 199 |
|
| 200 | +(mat immutable-vector-set/copy |
| 201 | + (equal? (immutable-vector-set/copy '#(a b c) 0 'x) '#(x b c)) |
| 202 | + (equal? (immutable-vector-set/copy '#(a b c) 1 'x) '#(a x c)) |
| 203 | + (equal? (immutable-vector-set/copy '#(a b c) 2 'x) '#(a b x)) |
| 204 | + (equal? (immutable-vector-set/copy '#(a b c d e f g h i) 2 'x) '#(a b x d e f g h i)) |
| 205 | + (immutable-vector? (immutable-vector-set/copy '#(a b c) 0 'x)) |
| 206 | + (immutable-vector? (immutable-vector-set/copy '#(a b c) 1 'x)) |
| 207 | + (immutable-vector? (immutable-vector-set/copy '#(a b c) 2 'x)) |
| 208 | + (immutable-vector? (immutable-vector-set/copy '#(a b c d e f g h i) 2 'x)) |
| 209 | + (error? (immutable-vector-set/copy 1)) |
| 210 | + (error? (immutable-vector-set/copy '#(a b c))) |
| 211 | + (error? (immutable-vector-set/copy '#(a b c) 1)) |
| 212 | + (error? (immutable-vector-set/copy '#(a b c) 'y 'x)) |
| 213 | + (error? (immutable-vector-set/copy '#(a b c) -1 'x)) |
| 214 | + (error? (immutable-vector-set/copy '#(a b c) 3 'x)) |
| 215 | + ) |
| 216 | + |
166 | 217 | (mat vector-append
|
167 | 218 | (eq? (vector-append) '#())
|
168 | 219 | (eq? (vector-append '#()) '#())
|
169 | 220 | (eq? (vector-append '#() '#()) '#())
|
170 | 221 | (eq? (vector-append '#() '#() '#()) '#())
|
171 | 222 | (eq? (vector-append '#() '#() '#() '#()) '#())
|
172 | 223 | (equal? (vector-append '#(a b c)) '#(a b c))
|
| 224 | + (mutable-vector? (vector-append '#(a b c))) |
173 | 225 | (equal? (vector-append '#(a b c) '#(d e)) '#(a b c d e))
|
| 226 | + (mutable-vector? (vector-append '#(a b c) '#(d e))) |
174 | 227 | (equal? (vector-append '#(a b c) '#(d e) '#(f) '#(g h i)) '#(a b c d e f g h i))
|
| 228 | + (mutable-vector? (vector-append '#(a b c) '#(d e) '#(f) '#(g h i))) |
175 | 229 | (equal? (vector-append (vector 'p) '#()) '#(p))
|
| 230 | + (mutable-vector? (vector-append (vector 'p) '#())) |
176 | 231 | (equal? (vector-append '#() (vector 'p)) '#(p))
|
| 232 | + (mutable-vector? (vector-append '#() (vector 'p))) |
177 | 233 | (equal? (vector-append (vector 'p) '#(a b c)) '#(p a b c))
|
178 | 234 | (equal? (vector-append '#(a b c) (vector 'p)) '#(a b c p))
|
| 235 | + (mutable-vector? (vector-append (vector 'p) '#(a b c))) |
| 236 | + (mutable-vector? (vector-append '#(a b c) (vector 'p))) |
179 | 237 | (error? (vector-append 1))
|
180 | 238 | (error? (vector-append '#(a b c) 'x))
|
181 | 239 | (error? (vector-append '#(a b c) '#(d) 'x))
|
|
199 | 257 | (equal? (vector-ref v N) "8")))))))
|
200 | 258 | )
|
201 | 259 |
|
| 260 | +(mat immutable-vector-append |
| 261 | + (eq? (immutable-vector-append) (immutable-vector)) |
| 262 | + (eq? (immutable-vector-append '#()) (immutable-vector)) |
| 263 | + (eq? (immutable-vector-append '#() '#()) (immutable-vector)) |
| 264 | + (eq? (immutable-vector-append '#() '#() '#()) (immutable-vector)) |
| 265 | + (eq? (immutable-vector-append '#() '#() '#() '#()) (immutable-vector)) |
| 266 | + (equal? (immutable-vector-append '#(a b c)) '#(a b c)) |
| 267 | + (immutable-vector? (immutable-vector-append '#(a b c))) |
| 268 | + (equal? (immutable-vector-append '#(a b c) '#(d e)) '#(a b c d e)) |
| 269 | + (immutable-vector? (immutable-vector-append '#(a b c) '#(d e))) |
| 270 | + (equal? (immutable-vector-append '#(a b c) '#(d e) '#(f) '#(g h i)) '#(a b c d e f g h i)) |
| 271 | + (immutable-vector? (immutable-vector-append '#(a b c) '#(d e) '#(f) '#(g h i))) |
| 272 | + (equal? (immutable-vector-append (vector 'p) '#()) '#(p)) |
| 273 | + (immutable-vector? (immutable-vector-append (vector 'p) '#())) |
| 274 | + (equal? (immutable-vector-append '#() (vector 'p)) '#(p)) |
| 275 | + (immutable-vector? (immutable-vector-append '#() (vector 'p))) |
| 276 | + (equal? (immutable-vector-append (vector 'p) '#(a b c)) '#(p a b c)) |
| 277 | + (equal? (immutable-vector-append '#(a b c) (vector 'p)) '#(a b c p)) |
| 278 | + (immutable-vector? (immutable-vector-append (vector 'p) '#(a b c))) |
| 279 | + (immutable-vector? (immutable-vector-append '#(a b c) (vector 'p))) |
| 280 | + (error? (immutable-vector-append 1)) |
| 281 | + (error? (immutable-vector-append '#(a b c) 'x)) |
| 282 | + (error? (immutable-vector-append '#(a b c) '#(d) 'x)) |
| 283 | + (error? (immutable-vector-append '#(a b c) '#(d) '#(e)'x)) |
| 284 | + |
| 285 | + ;; same as mutable-vector test above |
| 286 | + (with-interrupts-disabled |
| 287 | + (letrec ([f (lambda (m) |
| 288 | + (collect 0 1) |
| 289 | + (number->string m))] |
| 290 | + [N 1000]) |
| 291 | + (let ([v (immutable-vector-append (make-vector N) |
| 292 | + (vector (f 8)))]) |
| 293 | + (and (eqv? 0 (#%$generation (vector-ref v N))) |
| 294 | + (eqv? 0 (#%$generation v)) |
| 295 | + (begin |
| 296 | + (collect 0 1) |
| 297 | + (and (eqv? 1 (#%$generation (vector-ref v N))) |
| 298 | + (equal? (vector-ref v N) "8"))))))) |
| 299 | + ) |
| 300 | + |
| 301 | +(mat vector-cbuild-cp0 (parameters [enable-cp0 #t] [#%$suppress-primitive-inlining #f]) |
| 302 | + (equivalent-expansion? |
| 303 | + (expand/optimize '(vector->immutable-vector (vector 1 2))) |
| 304 | + `(quote ,(immutable-vector 1 2))) |
| 305 | + (equivalent-expansion? |
| 306 | + (expand/optimize '(vector->immutable-vector (immutable-vector 1 2))) |
| 307 | + `(quote ,(immutable-vector 1 2))) |
| 308 | + (not |
| 309 | + (equivalent-expansion? |
| 310 | + (expand/optimize `(vector->immutable-vector '#(1 2))) |
| 311 | + `(quote ,(immutable-vector 1 2)))) |
| 312 | + (equivalent-expansion? |
| 313 | + (expand/optimize `(vector->immutable-vector '#())) |
| 314 | + `(quote ,(immutable-vector))) |
| 315 | + (equivalent-expansion? |
| 316 | + (expand/optimize `(vector->immutable-vector ',(immutable-vector 1 2))) |
| 317 | + `(quote ,(immutable-vector 1 2))) |
| 318 | + (equivalent-expansion? |
| 319 | + (expand/optimize '(lambda (x y) (vector->immutable-vector (vector x y)))) |
| 320 | + `(lambda (x y) (#3%immutable-vector x y))) |
| 321 | + (equivalent-expansion? |
| 322 | + (expand/optimize '(lambda (x y) (vector->immutable-vector (immutable-vector x y)))) |
| 323 | + `(lambda (x y) (#3%immutable-vector x y))) |
| 324 | + (equivalent-expansion? |
| 325 | + (expand/optimize '(lambda (x y) (vector->immutable-vector (begin (x) (vector x y))))) |
| 326 | + `(lambda (x y) (x) (#3%immutable-vector x y))) |
| 327 | + (equivalent-expansion? |
| 328 | + (expand/optimize '(lambda (x y) (vector->immutable-vector (begin (x) (immutable-vector x y))))) |
| 329 | + `(lambda (x y) (x) (#3%immutable-vector x y))) |
| 330 | +
|
| 331 | + (equivalent-expansion? |
| 332 | + (expand/optimize '(immutable-vector-copy (vector 1 2))) |
| 333 | + `(quote ,(immutable-vector 1 2))) |
| 334 | + (equivalent-expansion? |
| 335 | + (expand/optimize '(immutable-vector-copy (immutable-vector 1 2))) |
| 336 | + `(quote ,(immutable-vector 1 2))) |
| 337 | + (equivalent-expansion? |
| 338 | + (expand/optimize `(immutable-vector-copy ',(immutable-vector 1 2))) |
| 339 | + `(quote ,(immutable-vector 1 2))) |
| 340 | + (equivalent-expansion? |
| 341 | + (expand/optimize '(lambda (x y) (immutable-vector-copy (vector x y)))) |
| 342 | + `(lambda (x y) (#3%immutable-vector x y))) |
| 343 | + (equivalent-expansion? |
| 344 | + (expand/optimize '(lambda (x y) (immutable-vector-copy (immutable-vector x y)))) |
| 345 | + `(lambda (x y) (#3%immutable-vector x y))) |
| 346 | + |
| 347 | + (equivalent-expansion? |
| 348 | + (expand/optimize '(vector-copy (vector 1 2))) |
| 349 | + `(#3%vector 1 2)) |
| 350 | + (equivalent-expansion? |
| 351 | + (expand/optimize '(vector-copy (immutable-vector 1 2))) |
| 352 | + `(#3%vector 1 2)) |
| 353 | + (equivalent-expansion? |
| 354 | + (expand/optimize `(vector-copy ',(immutable-vector 1 2))) |
| 355 | + `(#3%vector 1 2)) |
| 356 | + (equivalent-expansion? |
| 357 | + (expand/optimize '(lambda (x y) (vector-copy (vector x y)))) |
| 358 | + `(lambda (x y) (#3%vector x y))) |
| 359 | + (equivalent-expansion? |
| 360 | + (expand/optimize '(lambda (x y) (vector-copy (immutable-vector x y)))) |
| 361 | + `(lambda (x y) (#3%vector x y))) |
| 362 | +
|
| 363 | + (equivalent-expansion? |
| 364 | + (expand/optimize '(immutable-vector-append (vector 1 2))) |
| 365 | + `(quote ,(immutable-vector 1 2))) |
| 366 | + (equivalent-expansion? |
| 367 | + (expand/optimize '(immutable-vector-append (vector 1 2) (vector 3 4))) |
| 368 | + `(quote ,(immutable-vector 1 2 3 4))) |
| 369 | + (equivalent-expansion? |
| 370 | + (expand/optimize '(immutable-vector-append (immutable-vector 1 2))) |
| 371 | + `(quote ,(immutable-vector 1 2))) |
| 372 | + (equivalent-expansion? |
| 373 | + (expand/optimize '(immutable-vector-append (immutable-vector 1 2) (vector 3 4))) |
| 374 | + `(quote ,(immutable-vector 1 2 3 4))) |
| 375 | + (equivalent-expansion? |
| 376 | + (expand/optimize `(immutable-vector-append ',(immutable-vector 1 2))) |
| 377 | + `(quote ,(immutable-vector 1 2))) |
| 378 | + (equivalent-expansion? |
| 379 | + (expand/optimize `(immutable-vector-append ',(immutable-vector 1 2) (vector 3 4))) |
| 380 | + `(quote ,(immutable-vector 1 2 3 4))) |
| 381 | + (equivalent-expansion? |
| 382 | + (expand/optimize '(lambda (x y) (immutable-vector-append (vector x y)))) |
| 383 | + `(lambda (x y) (#3%immutable-vector x y))) |
| 384 | + (equivalent-expansion? |
| 385 | + (expand/optimize '(lambda (x y) (immutable-vector-append (vector x y) (vector y x)))) |
| 386 | + `(lambda (x y) (#3%immutable-vector x y y x))) |
| 387 | + (equivalent-expansion? |
| 388 | + (expand/optimize '(lambda (x y) (immutable-vector-append (immutable-vector x y)))) |
| 389 | + `(lambda (x y) (#3%immutable-vector x y))) |
| 390 | + (equivalent-expansion? |
| 391 | + (expand/optimize '(lambda (x y) (immutable-vector-append (immutable-vector x y) (immutable-vector y x)))) |
| 392 | + `(lambda (x y) (#3%immutable-vector x y y x))) |
| 393 | + (equivalent-expansion? |
| 394 | + (expand/optimize `(lambda (x y) (immutable-vector-append (immutable-vector 1 x) |
| 395 | + (vector 2 y) |
| 396 | + (vector-copy (vector 6 7 x)) |
| 397 | + ',(immutable-vector 8)))) |
| 398 | + `(lambda (x y) (#3%immutable-vector 1 x 2 y 6 7 x 8))) |
| 399 | + |
| 400 | + (equivalent-expansion? |
| 401 | + (expand/optimize '(vector-append (vector 1 2))) |
| 402 | + `(#3%vector 1 2)) |
| 403 | + (equivalent-expansion? |
| 404 | + (expand/optimize '(vector-append (vector 1 2) (vector 3 4))) |
| 405 | + `(#3%vector 1 2 3 4)) |
| 406 | + (equivalent-expansion? |
| 407 | + (expand/optimize '(vector-append (immutable-vector 1 2))) |
| 408 | + `(#3%vector 1 2)) |
| 409 | + (equivalent-expansion? |
| 410 | + (expand/optimize '(vector-append (immutable-vector 1 2) (vector 3 4))) |
| 411 | + `(#3%vector 1 2 3 4)) |
| 412 | + (equivalent-expansion? |
| 413 | + (expand/optimize `(vector-append ',(immutable-vector 1 2))) |
| 414 | + `(#3%vector 1 2)) |
| 415 | + (equivalent-expansion? |
| 416 | + (expand/optimize `(vector-append ',(immutable-vector 1 2) (vector 3 4))) |
| 417 | + `(#3%vector 1 2 3 4)) |
| 418 | + (equivalent-expansion? |
| 419 | + (expand/optimize '(lambda (x y) (vector-append (vector x y)))) |
| 420 | + `(lambda (x y) (#3%vector x y))) |
| 421 | + (equivalent-expansion? |
| 422 | + (expand/optimize '(lambda (x y) (vector-append (vector x y) (vector y x)))) |
| 423 | + `(lambda (x y) (#3%vector x y y x))) |
| 424 | + (equivalent-expansion? |
| 425 | + (expand/optimize '(lambda (x y) (vector-append (immutable-vector x y)))) |
| 426 | + `(lambda (x y) (#3%vector x y))) |
| 427 | + (equivalent-expansion? |
| 428 | + (expand/optimize '(lambda (x y) (vector-append (immutable-vector x y) (immutable-vector y x)))) |
| 429 | + `(lambda (x y) (#3%vector x y y x))) |
| 430 | + (equivalent-expansion? |
| 431 | + (expand/optimize `(lambda (x y) (vector-append (immutable-vector 1 x) |
| 432 | + (vector 2 y) |
| 433 | + (vector-copy (vector 6 7 x)) |
| 434 | + ',(immutable-vector 8)))) |
| 435 | + `(lambda (x y) (#3%vector 1 x 2 y 6 7 x 8))) |
| 436 | +
|
| 437 | + |
| 438 | + (equivalent-expansion? |
| 439 | + (expand/optimize `(lambda (x y) |
| 440 | + (vector-ref (vector-copy (immutable-vector 1 x)) 1))) |
| 441 | + `(lambda (x y) x)) |
| 442 | + (equivalent-expansion? |
| 443 | + (expand/optimize `(lambda (x y) |
| 444 | + (vector->immutable-vector |
| 445 | + (vector (vector-ref (vector-copy (immutable-vector 1 x)) 1) |
| 446 | + (vector-ref (immutable-vector-append (immutable-vector 2 3) |
| 447 | + (vector y 0)) |
| 448 | + 2))))) |
| 449 | + `(lambda (x y) (#3%immutable-vector x y))) |
| 450 | +
|
| 451 | + ) |
| 452 | +
|
202 | 453 | (mat vector-fill!
|
203 | 454 | (let ([v (vector-copy '#5(a b c d e))])
|
204 | 455 | (and (equal? v '#5(a b c d e))
|
|
1469 | 1720 | (equal? '#(1 2 3) immutable-123-vector)
|
1470 | 1721 | (eq? immutable-123-vector
|
1471 | 1722 | (vector->immutable-vector immutable-123-vector))
|
1472 |
| - |
| 1723 | + |
| 1724 | + ;; these also turn out to be conversions that should |
| 1725 | + ;; leave an immutable vector alone: |
| 1726 | + (eq? immutable-123-vector |
| 1727 | + (immutable-vector-copy immutable-123-vector)) |
| 1728 | + (eq? immutable-123-vector |
| 1729 | + (immutable-vector-append immutable-123-vector)) |
| 1730 | + |
1473 | 1731 | (mutable-vector? (make-vector 5))
|
1474 | 1732 | (not (immutable-vector? (make-vector 5)))
|
1475 | 1733 |
|
|
0 commit comments