1 /* Copyright (C) 1995,1996 Free Software Foundation, Inc.
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2, or (at your option)
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this software; see the file COPYING. If not, write to
15 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
17 * As a special exception, the Free Software Foundation gives permission
18 * for additional uses of the text contained in its release of GUILE.
20 * The exception is that, if you link the GUILE library with other files
21 * to produce an executable, this does not by itself cause the
22 * resulting executable to be covered by the GNU General Public License.
23 * Your use of that executable is in no way restricted on account of
24 * linking the GUILE library code into it.
26 * This exception does not however invalidate any other reasons why
27 * the executable file might be covered by the GNU General Public License.
29 * This exception applies only to the code released by the
30 * Free Software Foundation under the name GUILE. If you copy
31 * code from other Free Software Foundation releases into a copy of
32 * GUILE, as the General Public License permits, the exception does
33 * not apply to the code that you add in this way. To avoid misleading
34 * anyone as to the status of such modified files, you must delete
35 * this exception notice from them.
37 * If you write modifications of your own for GUILE, it is your choice
38 * whether to permit this exception to apply to your modifications.
39 * If you do not wish that, delete this exception notice.
48 /* The set of uniform scm_vector types is:
50 * unsigned char string
57 * complex double cvect
65 * This complicates things too much if allowed on any array.
66 * C code can safely call it on arrays known to be used in a single
69 * SCM_PROC(s_vector_set_length_x, "vector-set-length!", 2, 0, 0, scm_vector_set_length_x);
71 static char s_vector_set_length_x
[] = "vector-set-length!";
75 scm_vector_set_length_x (SCM vect
, SCM len
)
78 scm_vector_set_length_x (vect
, len
)
88 SCM_ASRTGO (SCM_NIMP (vect
), badarg1
);
89 switch (SCM_TYP7 (vect
))
92 badarg1
: scm_wta (vect
, (char *) SCM_ARG1
, s_vector_set_length_x
);
94 case scm_tc7_mb_string
:
95 SCM_ASRTGO (vect
!= scm_nullstr
, badarg1
);
100 SCM_ASRTGO (vect
!= scm_nullvect
, badarg1
);
105 l
= (l
+ SCM_LONG_BIT
- 1) / SCM_LONG_BIT
;
119 sz
= sizeof (long_long
);
130 sz
= sizeof (double);
133 sz
= 2 * sizeof (double);
138 SCM_ASSERT (SCM_INUMP (len
), len
, SCM_ARG2
, s_vector_set_length_x
);
143 scm_wta (SCM_MAKINUM (l
* sz
), (char *) SCM_NALLOC
, s_vector_set_length_x
);
147 scm_must_realloc (SCM_CHARS (vect
),
148 (long) SCM_LENGTH (vect
) * sz
,
150 s_vector_set_length_x
)));
151 if (SCM_VECTORP (vect
))
153 sz
= SCM_LENGTH (vect
);
155 SCM_VELTS (vect
)[--l
] = SCM_UNSPECIFIED
;
157 else if (SCM_STRINGP (vect
))
158 SCM_CHARS (vect
)[l
- 1] = 0;
159 SCM_SETLENGTH (vect
, SCM_INUM (len
), SCM_TYP7 (vect
));
184 SCM_CAR (z
) = scm_tc_flo
;
194 scm_make_uve (long k
, SCM prot
)
197 scm_make_uve (k
, prot
)
204 if (SCM_BOOL_T
== prot
)
206 i
= sizeof (long) * ((k
+ SCM_LONG_BIT
- 1) / SCM_LONG_BIT
);
207 type
= scm_tc7_bvect
;
209 else if (SCM_ICHRP (prot
) && (prot
== SCM_MAKICHR ('\0')))
211 i
= sizeof (char) * k
;
212 type
= scm_tc7_byvect
;
214 else if (SCM_ICHRP (prot
))
216 i
= sizeof (char) * k
;
217 type
= scm_tc7_string
;
219 else if (SCM_INUMP (prot
))
221 i
= sizeof (long) * k
;
222 if (SCM_INUM (prot
) > 0)
223 type
= scm_tc7_uvect
;
225 type
= scm_tc7_ivect
;
227 else if (SCM_NIMP (prot
) && SCM_SYMBOLP (prot
) && (1 == SCM_LENGTH (prot
)))
231 s
= SCM_CHARS (prot
)[0];
234 i
= sizeof (short) * k
;
235 type
= scm_tc7_svect
;
240 i
= sizeof (long_long
) * k
;
241 type
= scm_tc7_llvect
;
246 return scm_make_vector (SCM_MAKINUM (k
), SCM_UNDEFINED
, SCM_UNDEFINED
);
251 if (SCM_IMP (prot
) || !SCM_INEXP (prot
))
253 /* Huge non-unif vectors are NOT supported. */
254 return scm_make_vector (SCM_MAKINUM (k
), SCM_UNDEFINED
, SCM_UNDEFINED
); /* no special scm_vector */
257 else if (SCM_SINGP (prot
))
260 i
= sizeof (float) * k
;
261 type
= scm_tc7_fvect
;
264 else if (SCM_CPLXP (prot
))
266 i
= 2 * sizeof (double) * k
;
267 type
= scm_tc7_cvect
;
271 i
= sizeof (double) * k
;
272 type
= scm_tc7_dvect
;
280 m
= scm_must_malloc ((i
? i
: 1L), "vector");
281 SCM_SETCHARS (v
, (char *) m
);
283 SCM_SETLENGTH (v
, (k
< SCM_LENGTH_MAX
? k
: SCM_LENGTH_MAX
), type
);
288 SCM_PROC(s_uniform_vector_length
, "uniform-vector-length", 1, 0, 0, scm_uniform_vector_length
);
291 scm_uniform_vector_length (SCM v
)
294 scm_uniform_vector_length (v
)
298 SCM_ASRTGO (SCM_NIMP (v
), badarg1
);
303 badarg1
:scm_wta (v
, (char *) SCM_ARG1
, s_uniform_vector_length
);
317 return SCM_MAKINUM (SCM_LENGTH (v
));
321 SCM_PROC(s_array_p
, "array?", 1, 1, 0, scm_array_p
);
324 scm_array_p (SCM v
, SCM prot
)
327 scm_array_p (v
, prot
)
334 nprot
= SCM_UNBNDP (prot
);
339 switch (SCM_TYP7 (v
))
351 return nprot
|| SCM_BOOL_T
==prot
? SCM_BOOL_T
: SCM_BOOL_F
;
353 return nprot
|| (SCM_ICHRP(prot
) && (prot
!= SCM_MAKICHR('\0'))) ? SCM_BOOL_T
: SCM_BOOL_F
;
355 return nprot
|| (prot
== SCM_MAKICHR('\0')) ? SCM_BOOL_T
: SCM_BOOL_F
;
357 return nprot
|| (SCM_INUMP(prot
) && SCM_INUM(prot
)>0) ? SCM_BOOL_T
: SCM_BOOL_F
;
359 return nprot
|| (SCM_INUMP(prot
) && SCM_INUM(prot
)<=0) ? SCM_BOOL_T
: SCM_BOOL_F
;
363 && SCM_SYMBOLP (prot
)
364 && (1 == SCM_LENGTH (prot
))
365 && ('s' == SCM_CHARS (prot
)[0])));
370 && SCM_SYMBOLP (prot
)
371 && (1 == SCM_LENGTH (prot
))
372 && ('s' == SCM_CHARS (prot
)[0])));
377 return nprot
|| (SCM_NIMP(prot
) && SCM_SINGP(prot
)) ? SCM_BOOL_T
: SCM_BOOL_F
;
380 return nprot
|| (SCM_NIMP(prot
) && SCM_REALP(prot
)) ? SCM_BOOL_T
: SCM_BOOL_F
;
382 return nprot
|| (SCM_NIMP(prot
) && SCM_CPLXP(prot
)) ? SCM_BOOL_T
: SCM_BOOL_F
;
385 return nprot
|| SCM_NULLP(prot
) ? SCM_BOOL_T
: SCM_BOOL_F
;
392 SCM_PROC(s_array_rank
, "array-rank", 1, 0, 0, scm_array_rank
);
395 scm_array_rank (SCM ra
)
404 switch (SCM_TYP7 (ra
))
420 return SCM_MAKINUM (1L);
423 return SCM_MAKINUM (SCM_ARRAY_NDIM (ra
));
429 SCM_PROC(s_array_dimensions
, "array-dimensions", 1, 0, 0, scm_array_dimensions
);
432 scm_array_dimensions (SCM ra
)
435 scm_array_dimensions (ra
)
444 switch (SCM_TYP7 (ra
))
461 return scm_cons (SCM_MAKINUM (SCM_LENGTH (ra
)), SCM_EOL
);
463 if (!SCM_ARRAYP (ra
))
465 k
= SCM_ARRAY_NDIM (ra
);
466 s
= SCM_ARRAY_DIMS (ra
);
468 res
= scm_cons (s
[k
].lbnd
? scm_cons2 (SCM_MAKINUM (s
[k
].lbnd
), SCM_MAKINUM (s
[k
].ubnd
), SCM_EOL
) :
469 SCM_MAKINUM (1 + (s
[k
].ubnd
))
476 static char s_bad_ind
[] = "Bad scm_array index";
480 scm_aind (SCM ra
, SCM args
, char *what
)
483 scm_aind (ra
, args
, what
)
491 register scm_sizet pos
= SCM_ARRAY_BASE (ra
);
492 register scm_sizet k
= SCM_ARRAY_NDIM (ra
);
493 scm_array_dim
*s
= SCM_ARRAY_DIMS (ra
);
494 if (SCM_INUMP (args
))
497 SCM_ASSERT (1 == k
, SCM_UNDEFINED
, SCM_WNA
, what
);
498 return pos
+ (SCM_INUM (args
) - s
->lbnd
) * (s
->inc
);
500 while (k
&& SCM_NIMP (args
))
502 ind
= SCM_CAR (args
);
503 args
= SCM_CDR (args
);
504 SCM_ASSERT (SCM_INUMP (ind
), ind
, s_bad_ind
, what
);
506 SCM_ASSERT (j
>= (s
->lbnd
) && j
<= (s
->ubnd
), ind
, SCM_OUTOFRANGE
, what
);
507 pos
+= (j
- s
->lbnd
) * (s
->inc
);
511 SCM_ASSERT (0 == k
&& SCM_NULLP (args
), SCM_UNDEFINED
, SCM_WNA
, what
);
518 scm_make_ra (int ndim
)
528 SCM_SETCDR (ra
, scm_must_malloc ((long) (sizeof (scm_array
) + ndim
* sizeof (scm_array_dim
)),
530 SCM_CAR (ra
) = ((long) ndim
<< 17) + scm_tc16_array
;
531 SCM_ARRAY_V (ra
) = scm_nullvect
;
536 static char s_bad_spec
[] = "Bad scm_array dimension";
537 /* Increments will still need to be set. */
541 scm_shap2ra (SCM args
, char *what
)
544 scm_shap2ra (args
, what
)
551 int ndim
= scm_ilength (args
);
552 SCM_ASSERT (0 <= ndim
, args
, s_bad_spec
, what
);
553 ra
= scm_make_ra (ndim
);
554 SCM_ARRAY_BASE (ra
) = 0;
555 s
= SCM_ARRAY_DIMS (ra
);
556 for (; SCM_NIMP (args
); s
++, args
= SCM_CDR (args
))
558 spec
= SCM_CAR (args
);
562 SCM_ASSERT (SCM_INUMP (spec
) && SCM_INUM (spec
) >= 0, spec
, s_bad_spec
, what
);
564 s
->ubnd
= SCM_INUM (spec
) - 1;
569 SCM_ASSERT (SCM_CONSP (spec
) && SCM_INUMP (SCM_CAR (spec
)), spec
, s_bad_spec
, what
);
570 s
->lbnd
= SCM_INUM (SCM_CAR (spec
));
572 SCM_ASSERT (SCM_INUMP (SCM_CAR (sp
)) && SCM_NULLP (SCM_CDR (sp
)),
573 spec
, s_bad_spec
, what
);
574 s
->ubnd
= SCM_INUM (SCM_CAR (sp
));
581 SCM_PROC(s_dimensions_to_uniform_array
, "dimensions->uniform-array", 2, 0, 1, scm_dimensions_to_uniform_array
);
584 scm_dimensions_to_uniform_array (SCM dims
, SCM prot
, SCM fill
)
587 scm_dimensions_to_uniform_array (dims
, prot
, fill
)
593 scm_sizet k
, vlen
= 1;
597 if (SCM_INUMP (dims
))
598 if (SCM_INUM (dims
) < SCM_LENGTH_MAX
)
601 answer
= scm_make_uve (SCM_INUM (dims
), prot
);
602 if (SCM_NNULLP (fill
))
604 SCM_ASSERT (1 == scm_ilength (fill
), fill
, SCM_WNA
, s_dimensions_to_uniform_array
);
605 scm_array_fill_x (answer
, SCM_CAR (fill
));
607 else if (SCM_NIMP (prot
) && SCM_SYMBOLP (prot
))
608 scm_array_fill_x (answer
, SCM_MAKINUM (0));
610 scm_array_fill_x (answer
, prot
);
614 dims
= scm_cons (dims
, SCM_EOL
);
615 SCM_ASSERT (SCM_NULLP (dims
) || (SCM_NIMP (dims
) && SCM_CONSP (dims
)),
616 dims
, SCM_ARG1
, s_dimensions_to_uniform_array
);
617 ra
= scm_shap2ra (dims
, s_dimensions_to_uniform_array
);
618 SCM_CAR (ra
) |= SCM_ARRAY_CONTIGUOUS
;
619 s
= SCM_ARRAY_DIMS (ra
);
620 k
= SCM_ARRAY_NDIM (ra
);
623 s
[k
].inc
= (rlen
> 0 ? rlen
: 0);
624 rlen
= (s
[k
].ubnd
- s
[k
].lbnd
+ 1) * s
[k
].inc
;
625 vlen
*= (s
[k
].ubnd
- s
[k
].lbnd
+ 1);
627 if (rlen
< SCM_LENGTH_MAX
)
628 SCM_ARRAY_V (ra
) = scm_make_uve ((rlen
> 0 ? rlen
: 0L), prot
);
632 switch (SCM_TYP7 (scm_make_uve (0L, prot
)))
644 bit
= sizeof (float) * SCM_CHAR_BIT
/ sizeof (char);
647 bit
= sizeof (double) * SCM_CHAR_BIT
/ sizeof (char);
650 bit
= 2 * sizeof (double) * SCM_CHAR_BIT
/ sizeof (char);
653 SCM_ARRAY_BASE (ra
) = (SCM_LONG_BIT
+ bit
- 1) / bit
;
654 rlen
+= SCM_ARRAY_BASE (ra
);
655 SCM_ARRAY_V (ra
) = scm_make_uve (rlen
, prot
);
656 *((long *) SCM_VELTS (SCM_ARRAY_V (ra
))) = rlen
;
658 if (SCM_NNULLP (fill
))
660 SCM_ASSERT (1 == scm_ilength (fill
), fill
, SCM_WNA
, s_dimensions_to_uniform_array
);
661 scm_array_fill_x (ra
, SCM_CAR (fill
));
663 else if (SCM_NIMP (prot
) && SCM_SYMBOLP (prot
))
664 scm_array_fill_x (ra
, SCM_MAKINUM (0));
666 scm_array_fill_x (ra
, prot
);
667 if (1 == SCM_ARRAY_NDIM (ra
) && 0 == SCM_ARRAY_BASE (ra
))
668 if (s
->ubnd
< s
->lbnd
|| (0 == s
->lbnd
&& 1 == s
->inc
))
669 return SCM_ARRAY_V (ra
);
675 scm_ra_set_contp (SCM ra
)
678 scm_ra_set_contp (ra
)
682 scm_sizet k
= SCM_ARRAY_NDIM (ra
);
685 inc
= SCM_ARRAY_DIMS (ra
)[k
- 1].inc
;
688 if (inc
!= SCM_ARRAY_DIMS (ra
)[k
].inc
)
690 SCM_CAR (ra
) &= ~SCM_ARRAY_CONTIGUOUS
;
693 inc
*= (SCM_ARRAY_DIMS (ra
)[k
].ubnd
- SCM_ARRAY_DIMS (ra
)[k
].lbnd
+ 1);
695 SCM_CAR (ra
) |= SCM_ARRAY_CONTIGUOUS
;
699 SCM_PROC(s_make_shared_array
, "make-shared-array", 2, 0, 1, scm_make_shared_array
);
702 scm_make_shared_array (SCM oldra
, SCM mapfunc
, SCM dims
)
705 scm_make_shared_array (oldra
, mapfunc
, dims
)
715 long old_min
, new_min
, old_max
, new_max
;
717 SCM_ASSERT (SCM_BOOL_T
== scm_procedure_p (mapfunc
), mapfunc
, SCM_ARG2
, s_make_shared_array
);
718 SCM_ASSERT (SCM_NIMP (oldra
) && (SCM_BOOL_F
!= scm_array_p (oldra
, SCM_UNDEFINED
)), oldra
, SCM_ARG1
, s_make_shared_array
);
719 ra
= scm_shap2ra (dims
, s_make_shared_array
);
720 if (SCM_ARRAYP (oldra
))
722 SCM_ARRAY_V (ra
) = SCM_ARRAY_V (oldra
);
723 old_min
= old_max
= SCM_ARRAY_BASE (oldra
);
724 s
= SCM_ARRAY_DIMS (oldra
);
725 k
= SCM_ARRAY_NDIM (oldra
);
729 old_max
+= (s
[k
].ubnd
- s
[k
].lbnd
) * s
[k
].inc
;
731 old_min
+= (s
[k
].ubnd
- s
[k
].lbnd
) * s
[k
].inc
;
736 SCM_ARRAY_V (ra
) = oldra
;
738 old_max
= (long) SCM_LENGTH (oldra
) - 1;
741 s
= SCM_ARRAY_DIMS (ra
);
742 for (k
= 0; k
< SCM_ARRAY_NDIM (ra
); k
++)
744 inds
= scm_cons (SCM_MAKINUM (s
[k
].lbnd
), inds
);
745 if (s
[k
].ubnd
< s
[k
].lbnd
)
747 if (1 == SCM_ARRAY_NDIM (ra
))
748 ra
= scm_make_uve (0L, scm_array_prototype (ra
));
750 SCM_ARRAY_V (ra
) = scm_make_uve (0L, scm_array_prototype (ra
));
754 imap
= scm_apply (mapfunc
, scm_list_reverse (inds
), SCM_EOL
);
755 if (SCM_ARRAYP (oldra
))
756 i
= (scm_sizet
) scm_aind (oldra
, imap
, s_make_shared_array
);
759 if (SCM_NINUMP (imap
))
762 SCM_ASSERT (1 == scm_ilength (imap
) && SCM_INUMP (SCM_CAR (imap
)),
763 imap
, s_bad_ind
, s_make_shared_array
);
764 imap
= SCM_CAR (imap
);
768 SCM_ARRAY_BASE (ra
) = new_min
= new_max
= i
;
770 k
= SCM_ARRAY_NDIM (ra
);
773 if (s
[k
].ubnd
> s
[k
].lbnd
)
775 SCM_CAR (indptr
) = SCM_MAKINUM (SCM_INUM (SCM_CAR (indptr
)) + 1);
776 imap
= scm_apply (mapfunc
, scm_reverse (inds
), SCM_EOL
);
777 if (SCM_ARRAYP (oldra
))
779 s
[k
].inc
= scm_aind (oldra
, imap
, s_make_shared_array
) - i
;
782 if (SCM_NINUMP (imap
))
785 SCM_ASSERT (1 == scm_ilength (imap
) && SCM_INUMP (SCM_CAR (imap
)),
786 imap
, s_bad_ind
, s_make_shared_array
);
787 imap
= SCM_CAR (imap
);
789 s
[k
].inc
= (long) SCM_INUM (imap
) - i
;
793 new_max
+= (s
[k
].ubnd
- s
[k
].lbnd
) * s
[k
].inc
;
795 new_min
+= (s
[k
].ubnd
- s
[k
].lbnd
) * s
[k
].inc
;
798 s
[k
].inc
= new_max
- new_min
+ 1; /* contiguous by default */
799 indptr
= SCM_CDR (indptr
);
801 SCM_ASSERT (old_min
<= new_min
&& old_max
>= new_max
, SCM_UNDEFINED
,
802 "mapping out of range", s_make_shared_array
);
803 if (1 == SCM_ARRAY_NDIM (ra
) && 0 == SCM_ARRAY_BASE (ra
))
805 if (1 == s
->inc
&& 0 == s
->lbnd
806 && SCM_LENGTH (SCM_ARRAY_V (ra
)) == 1 + s
->ubnd
)
807 return SCM_ARRAY_V (ra
);
808 if (s
->ubnd
< s
->lbnd
)
809 return scm_make_uve (0L, scm_array_prototype (ra
));
811 scm_ra_set_contp (ra
);
816 /* args are RA . DIMS */
817 SCM_PROC(s_transpose_array
, "transpose-array", 0, 0, 1, scm_transpose_array
);
820 scm_transpose_array (SCM args
)
823 scm_transpose_array (args
)
827 SCM ra
, res
, vargs
, *ve
= &vargs
;
828 scm_array_dim
*s
, *r
;
830 SCM_ASSERT (SCM_NIMP (args
), SCM_UNDEFINED
, SCM_WNA
, s_transpose_array
);
832 args
= SCM_CDR (args
);
837 badarg
:scm_wta (ra
, (char *) SCM_ARG1
, s_transpose_array
);
850 SCM_ASSERT (SCM_NIMP (args
) && SCM_NULLP (SCM_CDR (args
)), SCM_UNDEFINED
, SCM_WNA
, s_transpose_array
);
851 SCM_ASSERT (SCM_INUM0
== SCM_CAR (args
), SCM_CAR (args
), SCM_ARG1
, s_transpose_array
);
854 SCM_ASRTGO (SCM_ARRAYP (ra
), badarg
);
855 vargs
= scm_vector (args
);
856 SCM_ASSERT (SCM_LENGTH (vargs
) == SCM_ARRAY_NDIM (ra
), SCM_UNDEFINED
, SCM_WNA
, s_transpose_array
);
857 ve
= SCM_VELTS (vargs
);
859 for (k
= 0; k
< SCM_ARRAY_NDIM (ra
); k
++)
861 i
= SCM_INUM (ve
[k
]);
862 SCM_ASSERT (SCM_INUMP (ve
[k
]) && i
>= 0 && i
< SCM_ARRAY_NDIM (ra
),
863 ve
[k
], SCM_ARG2
, s_transpose_array
);
868 res
= scm_make_ra (ndim
);
869 SCM_ARRAY_V (res
) = SCM_ARRAY_V (ra
);
870 SCM_ARRAY_BASE (res
) = SCM_ARRAY_BASE (ra
);
873 SCM_ARRAY_DIMS (res
)[k
].lbnd
= 0;
874 SCM_ARRAY_DIMS (res
)[k
].ubnd
= -1;
876 for (k
= SCM_ARRAY_NDIM (ra
); k
--;)
878 i
= SCM_INUM (ve
[k
]);
879 s
= &(SCM_ARRAY_DIMS (ra
)[k
]);
880 r
= &(SCM_ARRAY_DIMS (res
)[i
]);
881 if (r
->ubnd
< r
->lbnd
)
890 if (r
->ubnd
> s
->ubnd
)
892 if (r
->lbnd
< s
->lbnd
)
894 SCM_ARRAY_BASE (res
) += (s
->lbnd
- r
->lbnd
) * r
->inc
;
900 SCM_ASSERT (ndim
<= 0, args
, "bad argument scm_list", s_transpose_array
);
901 scm_ra_set_contp (res
);
906 /* args are RA . AXES */
907 SCM_PROC(s_enclose_array
, "enclose-array", 0, 0, 1, scm_enclose_array
);
910 scm_enclose_array (SCM axes
)
913 scm_enclose_array (axes
)
917 SCM axv
, ra
, res
, ra_inr
;
918 scm_array_dim vdim
, *s
= &vdim
;
919 int ndim
, j
, k
, ninr
, noutr
;
920 SCM_ASSERT (SCM_NIMP (axes
), SCM_UNDEFINED
, SCM_WNA
, s_enclose_array
);
922 axes
= SCM_CDR (axes
);
923 if (SCM_NULLP (axes
))
925 axes
= scm_cons ((SCM_ARRAYP (ra
) ? SCM_MAKINUM (SCM_ARRAY_NDIM (ra
) - 1) : SCM_INUM0
), SCM_EOL
);
926 ninr
= scm_ilength (axes
);
927 ra_inr
= scm_make_ra (ninr
);
928 SCM_ASRTGO (SCM_NIMP (ra
), badarg1
);
933 badarg1
:scm_wta (ra
, (char *) SCM_ARG1
, s_enclose_array
);
948 s
->ubnd
= SCM_LENGTH (ra
) - 1;
950 SCM_ARRAY_V (ra_inr
) = ra
;
951 SCM_ARRAY_BASE (ra_inr
) = 0;
955 SCM_ASRTGO (SCM_ARRAYP (ra
), badarg1
);
956 s
= SCM_ARRAY_DIMS (ra
);
957 SCM_ARRAY_V (ra_inr
) = SCM_ARRAY_V (ra
);
958 SCM_ARRAY_BASE (ra_inr
) = SCM_ARRAY_BASE (ra
);
959 ndim
= SCM_ARRAY_NDIM (ra
);
963 axv
= scm_make_string (SCM_MAKINUM (ndim
), SCM_MAKICHR (0));
964 SCM_ASSERT (0 <= noutr
&& 0 <= ninr
, SCM_UNDEFINED
, SCM_WNA
, s_enclose_array
);
965 res
= scm_make_ra (noutr
);
966 SCM_ARRAY_BASE (res
) = SCM_ARRAY_BASE (ra_inr
);
967 SCM_ARRAY_V (res
) = ra_inr
;
968 for (k
= 0; k
< ninr
; k
++, axes
= SCM_CDR (axes
))
970 SCM_ASSERT (SCM_INUMP (SCM_CAR (axes
)), SCM_CAR (axes
), "bad axis", s_enclose_array
);
971 j
= SCM_INUM (SCM_CAR (axes
));
972 SCM_ARRAY_DIMS (ra_inr
)[k
].lbnd
= s
[j
].lbnd
;
973 SCM_ARRAY_DIMS (ra_inr
)[k
].ubnd
= s
[j
].ubnd
;
974 SCM_ARRAY_DIMS (ra_inr
)[k
].inc
= s
[j
].inc
;
975 SCM_CHARS (axv
)[j
] = 1;
977 for (j
= 0, k
= 0; k
< noutr
; k
++, j
++)
979 while (SCM_CHARS (axv
)[j
])
981 SCM_ARRAY_DIMS (res
)[k
].lbnd
= s
[j
].lbnd
;
982 SCM_ARRAY_DIMS (res
)[k
].ubnd
= s
[j
].ubnd
;
983 SCM_ARRAY_DIMS (res
)[k
].inc
= s
[j
].inc
;
985 scm_ra_set_contp (ra_inr
);
986 scm_ra_set_contp (res
);
992 SCM_PROC(s_array_in_bounds_p
, "array-in-bounds?", 0, 0, 1, scm_array_in_bounds_p
);
995 scm_array_in_bounds_p (SCM args
)
998 scm_array_in_bounds_p (args
)
1002 SCM v
, ind
= SCM_EOL
;
1004 register scm_sizet k
;
1007 SCM_ASSERT (SCM_NIMP (args
), args
, SCM_WNA
, s_array_in_bounds_p
);
1009 args
= SCM_CDR (args
);
1010 SCM_ASRTGO (SCM_NIMP (v
), badarg1
);
1011 if (SCM_NIMP (args
))
1014 ind
= SCM_CAR (args
);
1015 args
= SCM_CDR (args
);
1016 SCM_ASSERT (SCM_INUMP (ind
), ind
, SCM_ARG2
, s_array_in_bounds_p
);
1017 pos
= SCM_INUM (ind
);
1024 badarg1
:scm_wta (v
, (char *) SCM_ARG1
, s_array_in_bounds_p
);
1025 wna
:scm_wta (args
, (char *) SCM_WNA
, s_array_in_bounds_p
);
1027 k
= SCM_ARRAY_NDIM (v
);
1028 s
= SCM_ARRAY_DIMS (v
);
1029 pos
= SCM_ARRAY_BASE (v
);
1032 SCM_ASRTGO (SCM_NULLP (ind
), wna
);
1039 if (!(j
>= (s
->lbnd
) && j
<= (s
->ubnd
)))
1041 SCM_ASRTGO (--k
== scm_ilength (args
), wna
);
1044 pos
+= (j
- s
->lbnd
) * (s
->inc
);
1045 if (!(--k
&& SCM_NIMP (args
)))
1047 ind
= SCM_CAR (args
);
1048 args
= SCM_CDR (args
);
1050 SCM_ASSERT (SCM_INUMP (ind
), ind
, s_bad_ind
, s_array_in_bounds_p
);
1052 SCM_ASRTGO (0 == k
, wna
);
1053 v
= SCM_ARRAY_V (v
);
1056 case scm_tc7_string
:
1057 case scm_tc7_byvect
:
1065 case scm_tc7_llvect
:
1067 case scm_tc7_vector
:
1068 SCM_ASRTGO (SCM_NULLP (args
) && SCM_INUMP (ind
), wna
);
1069 return pos
>= 0 && pos
< SCM_LENGTH (v
) ? SCM_BOOL_T
: SCM_BOOL_F
;
1074 SCM_PROC(s_array_ref
, "array-ref", 1, 0, 1, scm_uniform_vector_ref
);
1075 SCM_PROC(s_uniform_vector_ref
, "uniform-vector-ref", 2, 0, 0, scm_uniform_vector_ref
);
1078 scm_uniform_vector_ref (SCM v
, SCM args
)
1081 scm_uniform_vector_ref (v
, args
)
1090 SCM_ASRTGO (SCM_NULLP (args
), badarg
);
1093 else if (SCM_ARRAYP (v
))
1096 pos
= scm_aind (v
, args
, s_uniform_vector_ref
);
1097 v
= SCM_ARRAY_V (v
);
1101 if (SCM_NIMP (args
))
1104 SCM_ASSERT (SCM_CONSP (args
) && SCM_INUMP (SCM_CAR (args
)), args
, SCM_ARG2
, s_uniform_vector_ref
);
1105 pos
= SCM_INUM (SCM_CAR (args
));
1106 SCM_ASRTGO (SCM_NULLP (SCM_CDR (args
)), wna
);
1110 SCM_ASSERT (SCM_INUMP (args
), args
, SCM_ARG2
, s_uniform_vector_ref
);
1111 pos
= SCM_INUM (args
);
1113 SCM_ASRTGO (pos
>= 0 && pos
< SCM_LENGTH (v
), outrng
);
1119 if (SCM_NULLP (args
))
1121 badarg
:scm_wta (v
, (char *) SCM_ARG1
, s_uniform_vector_ref
);
1122 outrng
:scm_wta (SCM_MAKINUM (pos
), (char *) SCM_OUTOFRANGE
, s_uniform_vector_ref
);
1123 wna
:scm_wta (SCM_UNDEFINED
, (char *) SCM_WNA
, s_uniform_vector_ref
);
1126 int k
= SCM_ARRAY_NDIM (v
);
1127 SCM res
= scm_make_ra (k
);
1128 SCM_ARRAY_V (res
) = SCM_ARRAY_V (v
);
1129 SCM_ARRAY_BASE (res
) = pos
;
1132 SCM_ARRAY_DIMS (res
)[k
].lbnd
= SCM_ARRAY_DIMS (v
)[k
].lbnd
;
1133 SCM_ARRAY_DIMS (res
)[k
].ubnd
= SCM_ARRAY_DIMS (v
)[k
].ubnd
;
1134 SCM_ARRAY_DIMS (res
)[k
].inc
= SCM_ARRAY_DIMS (v
)[k
].inc
;
1139 if (SCM_VELTS (v
)[pos
/ SCM_LONG_BIT
] & (1L << (pos
% SCM_LONG_BIT
)))
1143 case scm_tc7_string
:
1144 return SCM_MAKICHR (SCM_CHARS (v
)[pos
]);
1145 case scm_tc7_byvect
:
1146 return SCM_MAKINUM (((char *)SCM_CHARS (v
))[pos
]);
1147 # ifdef SCM_INUMS_ONLY
1150 return SCM_MAKINUM (SCM_VELTS (v
)[pos
]);
1153 return scm_ulong2num(SCM_VELTS(v
)[pos
]);
1155 return scm_long2num(SCM_VELTS(v
)[pos
]);
1159 return SCM_MAKINUM (((short *) SCM_CDR (v
))[pos
]);
1161 case scm_tc7_llvect
:
1162 return scm_long_long2num (((long_long
*) SCM_CDR (v
))[pos
]);
1168 return scm_makflo (((float *) SCM_CDR (v
))[pos
]);
1171 return scm_makdbl (((double *) SCM_CDR (v
))[pos
], 0.0);
1173 return scm_makdbl (((double *) SCM_CDR (v
))[2 * pos
],
1174 ((double *) SCM_CDR (v
))[2 * pos
+ 1]);
1176 case scm_tc7_vector
:
1177 return SCM_VELTS (v
)[pos
];
1181 /* Internal version of scm_uniform_vector_ref for uves that does no error checking and
1182 tries to recycle conses. (Make *sure* you want them recycled.) */
1185 scm_cvref (SCM v
, scm_sizet pos
, SCM last
)
1188 scm_cvref (v
, pos
, last
)
1198 scm_wta (v
, (char *) SCM_ARG1
, "PROGRAMMING ERROR: scm_cvref");
1200 if (SCM_VELTS (v
)[pos
/ SCM_LONG_BIT
] & (1L << (pos
% SCM_LONG_BIT
)))
1204 case scm_tc7_string
:
1205 return SCM_MAKICHR (SCM_CHARS (v
)[pos
]);
1206 case scm_tc7_byvect
:
1207 return SCM_MAKINUM (((char *)SCM_CHARS (v
))[pos
]);
1208 # ifdef SCM_INUMS_ONLY
1211 return SCM_MAKINUM (SCM_VELTS (v
)[pos
]);
1214 return scm_ulong2num(SCM_VELTS(v
)[pos
]);
1216 return scm_long2num(SCM_VELTS(v
)[pos
]);
1219 return SCM_MAKINUM (((short *) SCM_CDR (v
))[pos
]);
1221 case scm_tc7_llvect
:
1222 return scm_long_long2num (((long_long
*) SCM_CDR (v
))[pos
]);
1227 if (SCM_NIMP (last
) && (last
!= scm_flo0
) && (scm_tc_flo
== SCM_CAR (last
)))
1229 SCM_FLO (last
) = ((float *) SCM_CDR (v
))[pos
];
1232 return scm_makflo (((float *) SCM_CDR (v
))[pos
]);
1236 if (SCM_NIMP (last
) && scm_tc_dblr
== SCM_CAR (last
))
1238 if (SCM_NIMP (last
) && (last
!= scm_flo0
) && (scm_tc_dblr
== SCM_CAR (last
)))
1241 SCM_REAL (last
) = ((double *) SCM_CDR (v
))[pos
];
1244 return scm_makdbl (((double *) SCM_CDR (v
))[pos
], 0.0);
1246 if (SCM_NIMP (last
) && scm_tc_dblc
== SCM_CAR (last
))
1248 SCM_REAL (last
) = ((double *) SCM_CDR (v
))[2 * pos
];
1249 SCM_IMAG (last
) = ((double *) SCM_CDR (v
))[2 * pos
+ 1];
1252 return scm_makdbl (((double *) SCM_CDR (v
))[2 * pos
],
1253 ((double *) SCM_CDR (v
))[2 * pos
+ 1]);
1255 case scm_tc7_vector
:
1256 return SCM_VELTS (v
)[pos
];
1258 { /* enclosed scm_array */
1259 int k
= SCM_ARRAY_NDIM (v
);
1260 SCM res
= scm_make_ra (k
);
1261 SCM_ARRAY_V (res
) = SCM_ARRAY_V (v
);
1262 SCM_ARRAY_BASE (res
) = pos
;
1265 SCM_ARRAY_DIMS (res
)[k
].ubnd
= SCM_ARRAY_DIMS (v
)[k
].ubnd
;
1266 SCM_ARRAY_DIMS (res
)[k
].lbnd
= SCM_ARRAY_DIMS (v
)[k
].lbnd
;
1267 SCM_ARRAY_DIMS (res
)[k
].inc
= SCM_ARRAY_DIMS (v
)[k
].inc
;
1274 SCM_PROC(s_uniform_array_set1_x
, "uniform-array-set1!", 3, 0, 0, scm_array_set_x
);
1275 SCM_PROC(s_array_set_x
, "array-set!", 2, 0, 1, scm_array_set_x
);
1278 scm_array_set_x (SCM v
, SCM obj
, SCM args
)
1281 scm_array_set_x (v
, obj
, args
)
1288 SCM_ASRTGO (SCM_NIMP (v
), badarg1
);
1292 pos
= scm_aind (v
, args
, s_array_set_x
);
1293 v
= SCM_ARRAY_V (v
);
1297 if (SCM_NIMP (args
))
1300 SCM_ASSERT (SCM_CONSP (args
) && SCM_INUMP (SCM_CAR (args
)), args
, SCM_ARG2
, s_array_set_x
);
1301 pos
= SCM_INUM (SCM_CAR (args
));
1302 SCM_ASRTGO (SCM_NULLP (SCM_CDR (args
)), wna
);
1306 SCM_ASSERT (SCM_INUMP (args
), args
, SCM_ARG2
, s_array_set_x
);
1307 pos
= SCM_INUM (args
);
1309 SCM_ASRTGO (pos
>= 0 && pos
< SCM_LENGTH (v
), outrng
);
1311 switch (SCM_TYP7 (v
))
1314 badarg1
:scm_wta (v
, (char *) SCM_ARG1
, s_array_set_x
);
1315 outrng
:scm_wta (SCM_MAKINUM (pos
), (char *) SCM_OUTOFRANGE
, s_array_set_x
);
1316 wna
:scm_wta (SCM_UNDEFINED
, (char *) SCM_WNA
, s_array_set_x
);
1317 case scm_tc7_smob
: /* enclosed */
1320 if (SCM_BOOL_F
== obj
)
1321 SCM_VELTS (v
)[pos
/ SCM_LONG_BIT
] &= ~(1L << (pos
% SCM_LONG_BIT
));
1322 else if (SCM_BOOL_T
== obj
)
1323 SCM_VELTS (v
)[pos
/ SCM_LONG_BIT
] |= (1L << (pos
% SCM_LONG_BIT
));
1325 badarg3
:scm_wta (obj
, (char *) SCM_ARG3
, s_array_set_x
);
1327 case scm_tc7_string
:
1328 SCM_ASRTGO (SCM_ICHRP (obj
), badarg3
);
1329 SCM_CHARS (v
)[pos
] = SCM_ICHR (obj
);
1331 case scm_tc7_byvect
:
1332 if (SCM_ICHRP (obj
))
1333 obj
= SCM_MAKINUM (SCM_ICHR (obj
));
1334 SCM_ASRTGO (SCM_INUMP (obj
), badarg3
);
1335 ((char *)SCM_CHARS (v
))[pos
] = SCM_INUM (obj
);
1337 # ifdef SCM_INUMS_ONLY
1339 SCM_ASRTGO (SCM_INUM (obj
) >= 0, badarg3
);
1341 SCM_ASRTGO(SCM_INUMP(obj
), badarg3
); SCM_VELTS(v
)[pos
] = SCM_INUM(obj
); break;
1344 SCM_VELTS(v
)[pos
] = scm_num2ulong(obj
, (char *)SCM_ARG3
, s_array_set_x
); break;
1346 SCM_VELTS(v
)[pos
] = num2long(obj
, (char *)SCM_ARG3
, s_array_set_x
); break;
1351 SCM_ASRTGO (SCM_INUMP (obj
), badarg3
);
1352 ((short *) SCM_CDR (v
))[pos
] = SCM_INUM (obj
);
1355 case scm_tc7_llvect
:
1356 ((long_long
*) SCM_CDR (v
))[pos
] = scm_num2long_long (obj
, (char *)SCM_ARG3
, s_array_set_x
);
1364 SCM_ASRTGO (SCM_NIMP (obj
) && SCM_REALP (obj
), badarg3
);
1365 ((float *) SCM_CDR (v
))[pos
] = SCM_REALPART (obj
);
1369 SCM_ASRTGO (SCM_NIMP (obj
) && SCM_REALP (obj
), badarg3
);
1370 ((double *) SCM_CDR (v
))[pos
] = SCM_REALPART (obj
);
1373 SCM_ASRTGO (SCM_NIMP (obj
) && SCM_INEXP (obj
), badarg3
);
1374 ((double *) SCM_CDR (v
))[2 * pos
] = SCM_REALPART (obj
);
1375 ((double *) SCM_CDR (v
))[2 * pos
+ 1] = SCM_CPLXP (obj
) ? SCM_IMAG (obj
) : 0.0;
1378 case scm_tc7_vector
:
1379 SCM_VELTS (v
)[pos
] = obj
;
1382 return SCM_UNSPECIFIED
;
1385 SCM_PROC(s_array_contents
, "array-contents", 1, 1, 0, scm_array_contents
);
1388 scm_array_contents (SCM ra
, SCM strict
)
1391 scm_array_contents (ra
, strict
)
1404 case scm_tc7_vector
:
1405 case scm_tc7_string
:
1407 case scm_tc7_byvect
:
1415 case scm_tc7_llvect
:
1420 scm_sizet k
, ndim
= SCM_ARRAY_NDIM (ra
), len
= 1;
1421 if (!SCM_ARRAYP (ra
) || !SCM_ARRAY_CONTP (ra
))
1423 for (k
= 0; k
< ndim
; k
++)
1424 len
*= SCM_ARRAY_DIMS (ra
)[k
].ubnd
- SCM_ARRAY_DIMS (ra
)[k
].lbnd
+ 1;
1425 if (!SCM_UNBNDP (strict
))
1428 (ra
) return SCM_BOOL_F
;
1429 if (ndim
&& (1 != SCM_ARRAY_DIMS (ra
)[ndim
- 1].inc
))
1431 if (scm_tc7_bvect
== SCM_TYP7 (SCM_ARRAY_V (ra
)))
1433 if (len
!= SCM_LENGTH (SCM_ARRAY_V (ra
)) ||
1434 SCM_ARRAY_BASE (ra
) % SCM_LONG_BIT
||
1439 if ((len
== SCM_LENGTH (SCM_ARRAY_V (ra
))) && 0 == SCM_ARRAY_BASE (ra
) && SCM_ARRAY_DIMS (ra
)->inc
)
1440 return SCM_ARRAY_V (ra
);
1441 sra
= scm_make_ra (1);
1442 SCM_ARRAY_DIMS (sra
)->lbnd
= 0;
1443 SCM_ARRAY_DIMS (sra
)->ubnd
= len
- 1;
1444 SCM_ARRAY_V (sra
) = SCM_ARRAY_V (ra
);
1445 SCM_ARRAY_BASE (sra
) = SCM_ARRAY_BASE (ra
);
1446 SCM_ARRAY_DIMS (sra
)->inc
= (ndim
? SCM_ARRAY_DIMS (ra
)[ndim
- 1].inc
: 1);
1454 scm_ra2contig (SCM ra
, int copy
)
1457 scm_ra2contig (ra
, copy
)
1464 scm_sizet k
, len
= 1;
1465 for (k
= SCM_ARRAY_NDIM (ra
); k
--;)
1466 len
*= SCM_ARRAY_DIMS (ra
)[k
].ubnd
- SCM_ARRAY_DIMS (ra
)[k
].lbnd
+ 1;
1467 k
= SCM_ARRAY_NDIM (ra
);
1468 if (SCM_ARRAY_CONTP (ra
) && ((0 == k
) || (1 == SCM_ARRAY_DIMS (ra
)[k
- 1].inc
)))
1470 if (scm_tc7_bvect
!= SCM_TYP7 (ra
))
1472 if ((len
== SCM_LENGTH (SCM_ARRAY_V (ra
)) &&
1473 0 == SCM_ARRAY_BASE (ra
) % SCM_LONG_BIT
&&
1474 0 == len
% SCM_LONG_BIT
))
1477 ret
= scm_make_ra (k
);
1478 SCM_ARRAY_BASE (ret
) = 0;
1481 SCM_ARRAY_DIMS (ret
)[k
].lbnd
= SCM_ARRAY_DIMS (ra
)[k
].lbnd
;
1482 SCM_ARRAY_DIMS (ret
)[k
].ubnd
= SCM_ARRAY_DIMS (ra
)[k
].ubnd
;
1483 SCM_ARRAY_DIMS (ret
)[k
].inc
= inc
;
1484 inc
*= SCM_ARRAY_DIMS (ra
)[k
].ubnd
- SCM_ARRAY_DIMS (ra
)[k
].lbnd
+ 1;
1486 SCM_ARRAY_V (ret
) = scm_make_uve ((inc
- 1), scm_array_prototype (ra
));
1488 scm_array_copy_x (ra
, ret
);
1494 SCM_PROC(s_uniform_array_read_x
, "uniform-array-read!", 1, 1, 0, scm_uniform_array_read_x
);
1497 scm_uniform_array_read_x (SCM ra
, SCM port
)
1500 scm_uniform_array_read_x (ra
, port
)
1508 if (SCM_UNBNDP (port
))
1511 SCM_ASSERT (SCM_NIMP (port
) && SCM_OPINFPORTP (port
), port
, SCM_ARG2
, s_uniform_array_read_x
);
1512 SCM_ASRTGO (SCM_NIMP (v
), badarg1
);
1513 len
= SCM_LENGTH (v
);
1519 badarg1
:scm_wta (v
, (char *) SCM_ARG1
, s_uniform_array_read_x
);
1521 SCM_ASRTGO (SCM_ARRAYP (v
), badarg1
);
1522 cra
= scm_ra2contig (ra
, 0);
1523 start
= SCM_ARRAY_BASE (cra
);
1524 len
= SCM_ARRAY_DIMS (cra
)->inc
*
1525 (SCM_ARRAY_DIMS (cra
)->ubnd
- SCM_ARRAY_DIMS (cra
)->lbnd
+ 1);
1526 v
= SCM_ARRAY_V (cra
);
1528 case scm_tc7_string
:
1529 case scm_tc7_byvect
:
1533 len
= (len
+ SCM_LONG_BIT
- 1) / SCM_LONG_BIT
;
1534 start
/= SCM_LONG_BIT
;
1540 sz
= sizeof (short);
1543 case scm_tc7_llvect
:
1544 sz
= sizeof (long_long
);
1550 sz
= sizeof (float);
1554 sz
= sizeof (double);
1557 sz
= 2 * sizeof (double);
1561 /* An ungetc before an fread will not work on some systems if setbuf(0).
1562 do #define NOSETBUF in scmfig.h to fix this. */
1563 if (SCM_CRDYP (port
))
1566 ungetc (SCM_CGETUN (port
), (FILE *)SCM_STREAM (port
));
1567 SCM_CLRDY (port
); /* Clear ungetted char */
1569 SCM_SYSCALL (ans
= fread (SCM_CHARS (v
) + start
* sz
, (scm_sizet
) sz
, (scm_sizet
) len
, (FILE *)SCM_STREAM (port
)));
1570 if (SCM_TYP7 (v
) == scm_tc7_bvect
)
1571 ans
*= SCM_LONG_BIT
;
1572 if (v
!= ra
&& cra
!= ra
)
1573 scm_array_copy_x (cra
, ra
);
1574 return SCM_MAKINUM (ans
);
1577 SCM_PROC(s_uniform_array_write
, "uniform-array-write", 1, 1, 0, scm_uniform_array_write
);
1580 scm_uniform_array_write (SCM v
, SCM port
)
1583 scm_uniform_array_write (v
, port
)
1590 if (SCM_UNBNDP (port
))
1591 port
= scm_cur_outp
;
1593 SCM_ASSERT (SCM_NIMP (port
) && SCM_OPOUTFPORTP (port
), port
, SCM_ARG2
, s_uniform_array_write
);
1594 SCM_ASRTGO (SCM_NIMP (v
), badarg1
);
1595 len
= SCM_LENGTH (v
);
1601 badarg1
:scm_wta (v
, (char *) SCM_ARG1
, s_uniform_array_write
);
1603 SCM_ASRTGO (SCM_ARRAYP (v
), badarg1
);
1604 v
= scm_ra2contig (v
, 1);
1605 start
= SCM_ARRAY_BASE (v
);
1606 len
= SCM_ARRAY_DIMS (v
)->inc
* (SCM_ARRAY_DIMS (v
)->ubnd
- SCM_ARRAY_DIMS (v
)->lbnd
+ 1);
1607 v
= SCM_ARRAY_V (v
);
1609 case scm_tc7_byvect
:
1610 case scm_tc7_string
:
1614 len
= (len
+ SCM_LONG_BIT
- 1) / SCM_LONG_BIT
;
1615 start
/= SCM_LONG_BIT
;
1621 sz
= sizeof (short);
1624 case scm_tc7_llvect
:
1625 sz
= sizeof (long_long
);
1631 sz
= sizeof (float);
1635 sz
= sizeof (double);
1638 sz
= 2 * sizeof (double);
1642 SCM_SYSCALL (ans
= fwrite (SCM_CHARS (v
) + start
* sz
, (scm_sizet
) sz
, (scm_sizet
) len
, (FILE *)SCM_STREAM (port
)));
1643 if (SCM_TYP7 (v
) == scm_tc7_bvect
)
1644 ans
*= SCM_LONG_BIT
;
1645 return SCM_MAKINUM (ans
);
1649 static char cnt_tab
[16] =
1650 {0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};
1652 SCM_PROC(s_bit_count
, "bit-count", 2, 0, 0, scm_bit_count
);
1655 scm_bit_count (SCM item
, SCM seq
)
1658 scm_bit_count (item
, seq
)
1664 register unsigned long cnt
= 0, w
;
1665 SCM_ASSERT (SCM_NIMP (seq
), seq
, SCM_ARG2
, s_bit_count
);
1670 scm_wta (seq
, (char *) SCM_ARG2
, s_bit_count
);
1672 if (0 == SCM_LENGTH (seq
))
1674 i
= (SCM_LENGTH (seq
) - 1) / SCM_LONG_BIT
;
1675 w
= SCM_VELTS (seq
)[i
];
1676 if (SCM_FALSEP (item
))
1678 w
<<= SCM_LONG_BIT
- 1 - ((SCM_LENGTH (seq
) - 1) % SCM_LONG_BIT
);
1682 cnt
+= cnt_tab
[w
& 0x0f];
1684 return SCM_MAKINUM (cnt
);
1685 w
= SCM_VELTS (seq
)[i
];
1686 if (SCM_FALSEP (item
))
1693 SCM_PROC(s_bit_position
, "bit-position", 3, 0, 0, scm_bit_position
);
1696 scm_bit_position (SCM item
, SCM v
, SCM k
)
1699 scm_bit_position (item
, v
, k
)
1705 long i
, lenw
, xbits
, pos
= SCM_INUM (k
);
1706 register unsigned long w
;
1707 SCM_ASSERT (SCM_NIMP (v
), v
, SCM_ARG2
, s_bit_position
);
1708 SCM_ASSERT (SCM_INUMP (k
), k
, SCM_ARG3
, s_bit_position
);
1709 SCM_ASSERT ((pos
<= SCM_LENGTH (v
)) && (pos
>= 0),
1710 k
, SCM_OUTOFRANGE
, s_bit_position
);
1711 if (pos
== SCM_LENGTH (v
))
1717 scm_wta (v
, (char *) SCM_ARG2
, s_bit_position
);
1719 if (0 == SCM_LENGTH (v
))
1720 return SCM_MAKINUM (-1L);
1721 lenw
= (SCM_LENGTH (v
) - 1) / SCM_LONG_BIT
; /* watch for part words */
1722 i
= pos
/ SCM_LONG_BIT
;
1723 w
= SCM_VELTS (v
)[i
];
1724 if (SCM_FALSEP (item
))
1726 xbits
= (pos
% SCM_LONG_BIT
);
1728 w
= ((w
>> xbits
) << xbits
);
1729 xbits
= SCM_LONG_BIT
- 1 - (SCM_LENGTH (v
) - 1) % SCM_LONG_BIT
;
1732 if (w
&& (i
== lenw
))
1733 w
= ((w
<< xbits
) >> xbits
);
1739 return SCM_MAKINUM (pos
);
1744 return SCM_MAKINUM (pos
+ 1);
1747 return SCM_MAKINUM (pos
+ 2);
1749 return SCM_MAKINUM (pos
+ 3);
1756 pos
+= SCM_LONG_BIT
;
1757 w
= SCM_VELTS (v
)[i
];
1758 if (SCM_FALSEP (item
))
1766 SCM_PROC(s_bit_set_star_x
, "bit-set*!", 3, 0, 0, scm_bit_set_star_x
);
1769 scm_bit_set_star_x (SCM v
, SCM kv
, SCM obj
)
1772 scm_bit_set_star_x (v
, kv
, obj
)
1778 register long i
, k
, vlen
;
1779 SCM_ASRTGO (SCM_NIMP (v
), badarg1
);
1780 SCM_ASRTGO (SCM_NIMP (kv
), badarg2
);
1785 badarg2
:scm_wta (kv
, (char *) SCM_ARG2
, s_bit_set_star_x
);
1791 badarg1
:scm_wta (v
, (char *) SCM_ARG1
, s_bit_set_star_x
);
1793 vlen
= SCM_LENGTH (v
);
1794 if (SCM_BOOL_F
== obj
)
1795 for (i
= SCM_LENGTH (kv
); i
;)
1797 k
= SCM_VELTS (kv
)[--i
];
1798 SCM_ASSERT ((k
< vlen
), SCM_MAKINUM (k
), SCM_OUTOFRANGE
, s_bit_set_star_x
);
1799 SCM_VELTS (v
)[k
/ SCM_LONG_BIT
] &= ~(1L << (k
% SCM_LONG_BIT
));
1801 else if (SCM_BOOL_T
== obj
)
1802 for (i
= SCM_LENGTH (kv
); i
;)
1804 k
= SCM_VELTS (kv
)[--i
];
1805 SCM_ASSERT ((k
< vlen
), SCM_MAKINUM (k
), SCM_OUTOFRANGE
, s_bit_set_star_x
);
1806 SCM_VELTS (v
)[k
/ SCM_LONG_BIT
] |= (1L << (k
% SCM_LONG_BIT
));
1809 badarg3
:scm_wta (obj
, (char *) SCM_ARG3
, s_bit_set_star_x
);
1813 SCM_ASRTGO (SCM_TYP7 (v
) == scm_tc7_bvect
&& SCM_LENGTH (v
) == SCM_LENGTH (kv
), badarg1
);
1814 if (SCM_BOOL_F
== obj
)
1815 for (k
= (SCM_LENGTH (v
) + SCM_LONG_BIT
- 1) / SCM_LONG_BIT
; k
--;)
1816 SCM_VELTS (v
)[k
] &= ~(SCM_VELTS (kv
)[k
]);
1817 else if (SCM_BOOL_T
== obj
)
1818 for (k
= (SCM_LENGTH (v
) + SCM_LONG_BIT
- 1) / SCM_LONG_BIT
; k
--;)
1819 SCM_VELTS (v
)[k
] |= SCM_VELTS (kv
)[k
];
1824 return SCM_UNSPECIFIED
;
1828 SCM_PROC(s_bit_count_star
, "bit-count*", 3, 0, 0, scm_bit_count_star
);
1831 scm_bit_count_star (SCM v
, SCM kv
, SCM obj
)
1834 scm_bit_count_star (v
, kv
, obj
)
1840 register long i
, vlen
, count
= 0;
1841 register unsigned long k
;
1842 SCM_ASRTGO (SCM_NIMP (v
), badarg1
);
1843 SCM_ASRTGO (SCM_NIMP (kv
), badarg2
);
1848 badarg2
:scm_wta (kv
, (char *) SCM_ARG2
, s_bit_count_star
);
1854 badarg1
:scm_wta (v
, (char *) SCM_ARG1
, s_bit_count_star
);
1856 vlen
= SCM_LENGTH (v
);
1857 if (SCM_BOOL_F
== obj
)
1858 for (i
= SCM_LENGTH (kv
); i
;)
1860 k
= SCM_VELTS (kv
)[--i
];
1861 SCM_ASSERT ((k
< vlen
), SCM_MAKINUM (k
), SCM_OUTOFRANGE
, s_bit_count_star
);
1862 if (!(SCM_VELTS (v
)[k
/ SCM_LONG_BIT
] & (1L << (k
% SCM_LONG_BIT
))))
1865 else if (SCM_BOOL_T
== obj
)
1866 for (i
= SCM_LENGTH (kv
); i
;)
1868 k
= SCM_VELTS (kv
)[--i
];
1869 SCM_ASSERT ((k
< vlen
), SCM_MAKINUM (k
), SCM_OUTOFRANGE
, s_bit_count_star
);
1870 if (SCM_VELTS (v
)[k
/ SCM_LONG_BIT
] & (1L << (k
% SCM_LONG_BIT
)))
1874 badarg3
:scm_wta (obj
, (char *) SCM_ARG3
, s_bit_count_star
);
1878 SCM_ASRTGO (SCM_TYP7 (v
) == scm_tc7_bvect
&& SCM_LENGTH (v
) == SCM_LENGTH (kv
), badarg1
);
1879 if (0 == SCM_LENGTH (v
))
1881 SCM_ASRTGO (SCM_BOOL_T
== obj
|| SCM_BOOL_F
== obj
, badarg3
);
1882 obj
= (SCM_BOOL_T
== obj
);
1883 i
= (SCM_LENGTH (v
) - 1) / SCM_LONG_BIT
;
1884 k
= SCM_VELTS (kv
)[i
] & (obj
? SCM_VELTS (v
)[i
] : ~SCM_VELTS (v
)[i
]);
1885 k
<<= SCM_LONG_BIT
- 1 - ((SCM_LENGTH (v
) - 1) % SCM_LONG_BIT
);
1889 count
+= cnt_tab
[k
& 0x0f];
1891 return SCM_MAKINUM (count
);
1892 k
= SCM_VELTS (kv
)[i
] & (obj
? SCM_VELTS (v
)[i
] : ~SCM_VELTS (v
)[i
]);
1895 return SCM_MAKINUM (count
);
1899 SCM_PROC(s_bit_invert_x
, "bit-invert!", 1, 0, 0, scm_bit_invert_x
);
1902 scm_bit_invert_x (SCM v
)
1905 scm_bit_invert_x (v
)
1910 SCM_ASRTGO (SCM_NIMP (v
), badarg1
);
1916 for (k
= (k
+ SCM_LONG_BIT
- 1) / SCM_LONG_BIT
; k
--;)
1917 SCM_VELTS (v
)[k
] = ~SCM_VELTS (v
)[k
];
1920 badarg1
:scm_wta (v
, (char *) SCM_ARG1
, s_bit_invert_x
);
1922 return SCM_UNSPECIFIED
;
1926 SCM_PROC(s_string_upcase_x
, "string-upcase!", 1, 0, 0, scm_string_upcase_x
);
1929 scm_string_upcase_x (SCM v
)
1932 scm_string_upcase_x (v
)
1937 register unsigned char *cs
;
1938 SCM_ASRTGO (SCM_NIMP (v
), badarg1
);
1943 case scm_tc7_string
:
1944 cs
= SCM_UCHARS (v
);
1946 cs
[k
] = scm_upcase(cs
[k
]);
1949 badarg1
:scm_wta (v
, (char *) SCM_ARG1
, s_string_upcase_x
);
1954 SCM_PROC(s_string_downcase_x
, "string-downcase!", 1, 0, 0, scm_string_downcase_x
);
1957 scm_string_downcase_x (SCM v
)
1960 scm_string_downcase_x (v
)
1965 register unsigned char *cs
;
1966 SCM_ASRTGO (SCM_NIMP (v
), badarg1
);
1971 case scm_tc7_string
:
1972 cs
= SCM_UCHARS (v
);
1974 cs
[k
] = scm_downcase(cs
[k
]);
1977 badarg1
:scm_wta (v
, (char *) SCM_ARG1
, s_string_downcase_x
);
1985 scm_istr2bve (char *str
, long len
)
1988 scm_istr2bve (str
, len
)
1993 SCM v
= scm_make_uve (len
, SCM_BOOL_T
);
1994 long *data
= (long *) SCM_VELTS (v
);
1995 register unsigned long mask
;
1998 for (k
= 0; k
< (len
+ SCM_LONG_BIT
- 1) / SCM_LONG_BIT
; k
++)
2001 j
= len
- k
* SCM_LONG_BIT
;
2002 if (j
> SCM_LONG_BIT
)
2004 for (mask
= 1L; j
--; mask
<<= 1)
2022 ra2l (SCM ra
, scm_sizet base
, scm_sizet k
)
2031 register SCM res
= SCM_EOL
;
2032 register long inc
= SCM_ARRAY_DIMS (ra
)[k
].inc
;
2033 register scm_sizet i
;
2034 if (SCM_ARRAY_DIMS (ra
)[k
].ubnd
< SCM_ARRAY_DIMS (ra
)[k
].lbnd
)
2036 i
= base
+ (1 + SCM_ARRAY_DIMS (ra
)[k
].ubnd
- SCM_ARRAY_DIMS (ra
)[k
].lbnd
) * inc
;
2037 if (k
< SCM_ARRAY_NDIM (ra
) - 1)
2042 res
= scm_cons (ra2l (ra
, i
, k
+ 1), res
);
2050 res
= scm_cons (scm_uniform_vector_ref (SCM_ARRAY_V (ra
), SCM_MAKINUM (i
)), res
);
2057 SCM_PROC(s_array_to_list
, "array->list", 1, 0, 0, scm_array_to_list
);
2060 scm_array_to_list (SCM v
)
2063 scm_array_to_list (v
)
2069 SCM_ASRTGO (SCM_NIMP (v
), badarg1
);
2074 badarg1
:scm_wta (v
, (char *) SCM_ARG1
, s_array_to_list
);
2076 SCM_ASRTGO (SCM_ARRAYP (v
), badarg1
);
2077 return ra2l (v
, SCM_ARRAY_BASE (v
), 0);
2078 case scm_tc7_vector
:
2079 return scm_vector_to_list (v
);
2080 case scm_tc7_string
:
2081 return scm_string_to_list (v
);
2084 long *data
= (long *) SCM_VELTS (v
);
2085 register unsigned long mask
;
2086 for (k
= (SCM_LENGTH (v
) - 1) / SCM_LONG_BIT
; k
> 0; k
--)
2087 for (mask
= 1L << (SCM_LONG_BIT
- 1); mask
; mask
>>= 1)
2088 res
= scm_cons (((long *) data
)[k
] & mask
? SCM_BOOL_T
: SCM_BOOL_F
, res
);
2089 for (mask
= 1L << ((SCM_LENGTH (v
) % SCM_LONG_BIT
) - 1); mask
; mask
>>= 1)
2090 res
= scm_cons (((long *) data
)[k
] & mask
? SCM_BOOL_T
: SCM_BOOL_F
, res
);
2093 # ifdef SCM_INUMS_ONLY
2097 long *data
= (long *) SCM_VELTS (v
);
2098 for (k
= SCM_LENGTH (v
) - 1; k
>= 0; k
--)
2099 res
= scm_cons (SCM_MAKINUM (data
[k
]), res
);
2103 case scm_tc7_uvect
: {
2104 long *data
= (long *)SCM_VELTS(v
);
2105 for (k
= SCM_LENGTH(v
) - 1; k
>= 0; k
--)
2106 res
= scm_cons(scm_ulong2num(data
[k
]), res
);
2109 case scm_tc7_ivect
: {
2110 long *data
= (long *)SCM_VELTS(v
);
2111 for (k
= SCM_LENGTH(v
) - 1; k
>= 0; k
--)
2112 res
= scm_cons(scm_long2num(data
[k
]), res
);
2116 case scm_tc7_svect
: {
2118 data
= (short *)SCM_VELTS(v
);
2119 for (k
= SCM_LENGTH(v
) - 1; k
>= 0; k
--)
2120 res
= scm_cons(SCM_MAKINUM (data
[k
]), res
);
2124 case scm_tc7_llvect
: {
2126 data
= (long_long
*)SCM_VELTS(v
);
2127 for (k
= SCM_LENGTH(v
) - 1; k
>= 0; k
--)
2128 res
= scm_cons(scm_long_long2num(data
[k
]), res
);
2138 float *data
= (float *) SCM_VELTS (v
);
2139 for (k
= SCM_LENGTH (v
) - 1; k
>= 0; k
--)
2140 res
= scm_cons (scm_makflo (data
[k
]), res
);
2143 #endif /*SCM_SINGLES*/
2146 double *data
= (double *) SCM_VELTS (v
);
2147 for (k
= SCM_LENGTH (v
) - 1; k
>= 0; k
--)
2148 res
= scm_cons (scm_makdbl (data
[k
], 0.0), res
);
2153 double (*data
)[2] = (double (*)[2]) SCM_VELTS (v
);
2154 for (k
= SCM_LENGTH (v
) - 1; k
>= 0; k
--)
2155 res
= scm_cons (scm_makdbl (data
[k
][0], data
[k
][1]), res
);
2158 #endif /*SCM_FLOATS*/
2163 static char s_bad_ralst
[] = "Bad scm_array contents scm_list";
2166 SCM_PROC(s_list_to_uniform_array
, "list->uniform-array", 3, 0, 0, scm_list_to_uniform_array
);
2169 scm_list_to_uniform_array (SCM ndim
, SCM prot
, SCM lst
)
2172 scm_list_to_uniform_array (ndim
, prot
, lst
)
2183 SCM_ASSERT (SCM_INUMP (ndim
), ndim
, SCM_ARG1
, s_list_to_uniform_array
);
2184 k
= SCM_INUM (ndim
);
2187 n
= scm_ilength (row
);
2188 SCM_ASSERT (n
>= 0, lst
, SCM_ARG2
, s_list_to_uniform_array
);
2189 shp
= scm_cons (SCM_MAKINUM (n
), shp
);
2191 row
= SCM_CAR (row
);
2193 ra
= scm_dimensions_to_uniform_array (scm_reverse (shp
), prot
, SCM_EOL
);
2194 if (SCM_NULLP (shp
))
2197 SCM_ASRTGO (1 == scm_ilength (lst
), badlst
);
2198 scm_array_set_x (ra
, SCM_CAR (lst
), SCM_EOL
);
2201 if (!SCM_ARRAYP (ra
))
2203 for (k
= 0; k
< SCM_LENGTH (ra
); k
++, lst
= SCM_CDR (lst
))
2204 scm_array_set_x (ra
, SCM_CAR (lst
), SCM_MAKINUM (k
));
2207 if (l2ra (lst
, ra
, SCM_ARRAY_BASE (ra
), 0))
2210 badlst
:scm_wta (lst
, s_bad_ralst
, s_list_to_uniform_array
);
2217 l2ra (SCM lst
, SCM ra
, scm_sizet base
, scm_sizet k
)
2220 l2ra (lst
, ra
, base
, k
)
2227 register long inc
= SCM_ARRAY_DIMS (ra
)[k
].inc
;
2228 register long n
= (1 + SCM_ARRAY_DIMS (ra
)[k
].ubnd
- SCM_ARRAY_DIMS (ra
)[k
].lbnd
);
2231 return (SCM_EOL
== lst
);
2232 if (k
< SCM_ARRAY_NDIM (ra
) - 1)
2236 if (SCM_IMP (lst
) || SCM_NCONSP (lst
))
2238 ok
= ok
&& l2ra (SCM_CAR (lst
), ra
, base
, k
+ 1);
2240 lst
= SCM_CDR (lst
);
2242 if (SCM_NNULLP (lst
))
2249 if (SCM_IMP (lst
) || SCM_NCONSP (lst
))
2251 ok
= ok
&& scm_array_set_x (SCM_ARRAY_V (ra
), SCM_CAR (lst
), SCM_MAKINUM (base
));
2253 lst
= SCM_CDR (lst
);
2255 if (SCM_NNULLP (lst
))
2263 rapr1 (SCM ra
, scm_sizet j
, scm_sizet k
, SCM port
, int writing
)
2266 rapr1 (ra
, j
, k
, port
, writing
)
2275 long n
= SCM_LENGTH (ra
);
2284 SCM_ARRAY_BASE (ra
) = j
;
2286 scm_iprin1 (ra
, port
, writing
);
2287 for (j
+= inc
; n
-- > 0; j
+= inc
)
2289 scm_gen_putc (' ', port
);
2290 SCM_ARRAY_BASE (ra
) = j
;
2291 scm_iprin1 (ra
, port
, writing
);
2295 if (k
+ 1 < SCM_ARRAY_NDIM (ra
))
2298 inc
= SCM_ARRAY_DIMS (ra
)[k
].inc
;
2299 for (i
= SCM_ARRAY_DIMS (ra
)[k
].lbnd
; i
< SCM_ARRAY_DIMS (ra
)[k
].ubnd
; i
++)
2301 scm_gen_putc ('(', port
);
2302 rapr1 (ra
, j
, k
+ 1, port
, writing
);
2303 scm_gen_puts (scm_regular_string
, ") ", port
);
2306 if (i
== SCM_ARRAY_DIMS (ra
)[k
].ubnd
)
2307 { /* could be zero size. */
2308 scm_gen_putc ('(', port
);
2309 rapr1 (ra
, j
, k
+ 1, port
, writing
);
2310 scm_gen_putc (')', port
);
2316 { /* Could be zero-dimensional */
2317 inc
= SCM_ARRAY_DIMS (ra
)[k
].inc
;
2318 n
= (SCM_ARRAY_DIMS (ra
)[k
].ubnd
- SCM_ARRAY_DIMS (ra
)[k
].lbnd
+ 1);
2322 ra
= SCM_ARRAY_V (ra
);
2326 scm_iprin1 (scm_uniform_vector_ref (ra
, SCM_MAKINUM (j
)), port
, writing
);
2327 for (j
+= inc
; n
-- > 0; j
+= inc
)
2329 scm_gen_putc (' ', port
);
2330 scm_iprin1 (scm_cvref (ra
, j
, SCM_UNDEFINED
), port
, writing
);
2333 case scm_tc7_string
:
2335 scm_iprin1 (SCM_MAKICHR (SCM_CHARS (ra
)[j
]), port
, writing
);
2337 for (j
+= inc
; n
-- > 0; j
+= inc
)
2339 scm_gen_putc (' ', port
);
2340 scm_iprin1 (SCM_MAKICHR (SCM_CHARS (ra
)[j
]), port
, writing
);
2343 for (j
+= inc
; n
-- > 0; j
+= inc
)
2344 scm_gen_putc (SCM_CHARS (ra
)[j
], port
);
2346 case scm_tc7_byvect
:
2348 scm_intprint (((char *)SCM_CDR (ra
))[j
], 10, port
);
2349 for (j
+= inc
; n
-- > 0; j
+= inc
)
2351 scm_gen_putc (' ', port
);
2352 scm_intprint (((char *)SCM_CDR (ra
))[j
], 10, port
);
2359 scm_intprint (SCM_VELTS (ra
)[j
], 10, port
);
2360 for (j
+= inc
; n
-- > 0; j
+= inc
)
2362 scm_gen_putc (' ', port
);
2363 scm_intprint (SCM_VELTS (ra
)[j
], 10, port
);
2369 scm_intprint (((short *)SCM_CDR (ra
))[j
], 10, port
);
2370 for (j
+= inc
; n
-- > 0; j
+= inc
)
2372 scm_gen_putc (' ', port
);
2373 scm_intprint (((short *)SCM_CDR (ra
))[j
], 10, port
);
2382 SCM z
= scm_makflo (1.0);
2383 SCM_FLO (z
) = ((float *) SCM_VELTS (ra
))[j
];
2384 scm_floprint (z
, port
, writing
);
2385 for (j
+= inc
; n
-- > 0; j
+= inc
)
2387 scm_gen_putc (' ', port
);
2388 SCM_FLO (z
) = ((float *) SCM_VELTS (ra
))[j
];
2389 scm_floprint (z
, port
, writing
);
2393 #endif /*SCM_SINGLES*/
2397 SCM z
= scm_makdbl (1.0 / 3.0, 0.0);
2398 SCM_REAL (z
) = ((double *) SCM_VELTS (ra
))[j
];
2399 scm_floprint (z
, port
, writing
);
2400 for (j
+= inc
; n
-- > 0; j
+= inc
)
2402 scm_gen_putc (' ', port
);
2403 SCM_REAL (z
) = ((double *) SCM_VELTS (ra
))[j
];
2404 scm_floprint (z
, port
, writing
);
2411 SCM cz
= scm_makdbl (0.0, 1.0), z
= scm_makdbl (1.0 / 3.0, 0.0);
2412 SCM_REAL (z
) = SCM_REAL (cz
) = (((double *) SCM_VELTS (ra
))[2 * j
]);
2413 SCM_IMAG (cz
) = ((double *) SCM_VELTS (ra
))[2 * j
+ 1];
2414 scm_floprint ((0.0 == SCM_IMAG (cz
) ? z
: cz
), port
, writing
);
2415 for (j
+= inc
; n
-- > 0; j
+= inc
)
2417 scm_gen_putc (' ', port
);
2418 SCM_REAL (z
) = SCM_REAL (cz
) = ((double *) SCM_VELTS (ra
))[2 * j
];
2419 SCM_IMAG (cz
) = ((double *) SCM_VELTS (ra
))[2 * j
+ 1];
2420 scm_floprint ((0.0 == SCM_IMAG (cz
) ? z
: cz
), port
, writing
);
2424 #endif /*SCM_FLOATS*/
2431 scm_raprin1 (SCM exp
, SCM port
, int writing
)
2434 scm_raprin1 (exp
, port
, writing
)
2442 scm_gen_putc ('#', port
);
2449 long ndim
= SCM_ARRAY_NDIM (v
);
2450 base
= SCM_ARRAY_BASE (v
);
2451 v
= SCM_ARRAY_V (v
);
2455 scm_gen_puts (scm_regular_string
, "<enclosed-array ", port
);
2456 rapr1 (exp
, base
, 0, port
, writing
);
2457 scm_gen_putc ('>', port
);
2462 scm_intprint (ndim
, 10, port
);
2468 { /* a uve, not an scm_array */
2469 register long i
, j
, w
;
2470 scm_gen_putc ('*', port
);
2471 for (i
= 0; i
< (SCM_LENGTH (exp
)) / SCM_LONG_BIT
; i
++)
2473 w
= SCM_VELTS (exp
)[i
];
2474 for (j
= SCM_LONG_BIT
; j
; j
--)
2476 scm_gen_putc (w
& 1 ? '1' : '0', port
);
2480 j
= SCM_LENGTH (exp
) % SCM_LONG_BIT
;
2483 w
= SCM_VELTS (exp
)[SCM_LENGTH (exp
) / SCM_LONG_BIT
];
2486 scm_gen_putc (w
& 1 ? '1' : '0', port
);
2493 scm_gen_putc ('b', port
);
2495 case scm_tc7_string
:
2496 scm_gen_putc ('a', port
);
2498 case scm_tc7_byvect
:
2499 scm_gen_puts (scm_regular_string
, "bytes", port
);
2502 scm_gen_putc ('u', port
);
2505 scm_gen_putc ('e', port
);
2508 scm_gen_puts (scm_regular_string
, "short", port
);
2511 case scm_tc7_llvect
:
2512 scm_gen_puts (scm_regular_string
, "long_long", port
);
2518 scm_gen_putc ('s', port
);
2520 #endif /*SCM_SINGLES*/
2522 scm_gen_putc ('i', port
);
2525 scm_gen_putc ('c', port
);
2527 #endif /*SCM_FLOATS*/
2529 scm_gen_putc ('(', port
);
2530 rapr1 (exp
, base
, 0, port
, writing
);
2531 scm_gen_putc (')', port
);
2535 SCM_PROC(s_array_prototype
, "array-prototype", 1, 0, 0, scm_array_prototype
);
2538 scm_array_prototype (SCM ra
)
2541 scm_array_prototype (ra
)
2546 SCM_ASRTGO (SCM_NIMP (ra
), badarg
);
2552 badarg
:scm_wta (ra
, (char *) SCM_ARG1
, s_array_prototype
);
2554 SCM_ASRTGO (SCM_ARRAYP (ra
), badarg
);
2556 return SCM_UNSPECIFIED
;
2557 ra
= SCM_ARRAY_V (ra
);
2559 case scm_tc7_vector
:
2563 case scm_tc7_string
:
2564 return SCM_MAKICHR ('a');
2565 case scm_tc7_byvect
:
2566 return SCM_MAKICHR ('\0');
2568 return SCM_MAKINUM (1L);
2570 return SCM_MAKINUM (-1L);
2572 return SCM_CDR (scm_intern ("s", 1));
2574 case scm_tc7_llvect
:
2575 return SCM_CDR (scm_intern ("l", 1));
2580 return scm_makflo (1.0);
2583 return scm_makdbl (1.0 / 3.0, 0.0);
2585 return scm_makdbl (0.0, 1.0);
2600 (ptr
) return SCM_BOOL_F
;
2601 SCM_SETGC8MARK (ptr
);
2602 return SCM_ARRAY_V (ptr
);
2614 scm_must_free (SCM_CHARS (ptr
));
2615 return sizeof (scm_array
) + SCM_ARRAY_NDIM (ptr
) * sizeof (scm_array_dim
);
2618 static scm_smobfuns rasmob
=
2619 {markra
, freera
, scm_raprin1
, scm_array_equal_p
};
2622 /* This must be done after scm_init_scl() */
2625 scm_init_unif (void)
2632 scm_tc16_array
= scm_newsmob (&rasmob
);
2633 scm_add_feature ("array");
2640 scm_raprin1 (SCM exp
, SCM port
, int writing
)
2643 scm_raprin1 (exp
, port
, writing
)
2654 scm_istr2bve (char *str
, long len
)
2657 scm_istr2bve (str
, len
)
2667 scm_array_equal_p (SCM ra0
, SCM ra1
)
2670 scm_array_equal_p (ra0
, ra1
)
2681 scm_make_subr (s_resizuve
, scm_tc7_subr_2
, scm_vector_set_length_x
);