diff options
author | Mikael Djurfeldt <djurfeldt@nada.kth.se> | 1996-10-20 03:28:34 +0000 |
---|---|---|
committer | Mikael Djurfeldt <djurfeldt@nada.kth.se> | 1996-10-20 03:28:34 +0000 |
commit | 898a256f9156643b4ceb275776372ee4380b8df1 (patch) | |
tree | fad48588aa635930dd21135883d0db9bcf6fab91 | |
parent | 3f46d9597804cda1f9d92ef239007b3b8b35ddb8 (diff) | |
download | guile-898a256f9156643b4ceb275776372ee4380b8df1.tar.gz |
* pairs.h, eval.c, gc.c, init.c, ioext.c, ports.c, ports.h,
srcprop.h, tags.h, throw.c, unif.c: Added new selectors
SCM_SETAND_CAR, SCM_SETAND_CDR, SCM_SETOR_CAR and SCM_SETOR_CDR.
Motivation: Safer use. Some other macros are defined in terms of
these operations. If these are defined using the SCM_SETCXR
(<e1>, SCM_CXR (<e1>) <op> <e2>) pattern a complex <e1> will lead
to inefficiency and an <e1> with side-effects could potentially
break. Also, these particular operations are heavily utilized in
the garbage collector. In unoptimized code there will be a
measurable speedup.
* alist.c, arbiters.c, continuations.c, debug.c, debug.h, eval.c,
eval.h, feature.c, filesys.c, fports.c, gc.c, gsubr.c, init.c,
ioext.c, kw.c, list.c, load.c, mallocs.c, numbers.c, numbers.h,
pairs.c, pairs.h, ports.c, ports.h, posix.c, procprop.c, procs.c,
procs.h, ramap.c, read.c, root.c, srcprop.c, srcprop.h,
strports.c, symbols.c, tags.h, throw.c, unif.c, variable.c,
vports.c: Cleaned up use of pairs: Don't make any special
assumptions about the internal structure of selectors and
mutators: SCM_CXR (<e1>) = <e2> --> SCM_SETCXR (<e1>, <e2>),
SCM_CXR (<e1>) &= <e2> --> SCM_SETAND_CXR (<e1>, <e2>) etc.
(Among other things, this change makes it easier to build Guile
with certain compilers which have problems with casted lvalues.)
-rw-r--r-- | libguile/init.c | 10 | ||||
-rw-r--r-- | libguile/ioext.c | 14 | ||||
-rw-r--r-- | libguile/ports.c | 4 | ||||
-rw-r--r-- | libguile/ports.h | 6 | ||||
-rw-r--r-- | libguile/srcprop.h | 4 | ||||
-rw-r--r-- | libguile/tags.h | 8 | ||||
-rw-r--r-- | libguile/throw.c | 8 | ||||
-rw-r--r-- | libguile/unif.c | 12 |
8 files changed, 34 insertions, 32 deletions
diff --git a/libguile/init.c b/libguile/init.c index 229402dd1..0c071e42b 100644 --- a/libguile/init.c +++ b/libguile/init.c @@ -145,13 +145,13 @@ scm_start_stack (base, in, out, err) { SCM_NEWCELL (scm_def_inp); pt = scm_add_to_port_table (scm_def_inp); - SCM_CAR (scm_def_inp) = (scm_tc16_fport | SCM_OPN | SCM_RDNG); + SCM_SETCAR (scm_def_inp, (scm_tc16_fport | SCM_OPN | SCM_RDNG)); SCM_SETPTAB_ENTRY (scm_def_inp, pt); SCM_SETSTREAM (scm_def_inp, (SCM)in); if (isatty (fileno (in))) { scm_setbuf0 (scm_def_inp); /* turn off stdin buffering */ - SCM_CAR (scm_def_inp) |= SCM_BUF0; + SCM_SETOR_CAR (scm_def_inp, SCM_BUF0); } scm_set_port_revealed_x (scm_def_inp, SCM_MAKINUM (1)); } @@ -164,7 +164,7 @@ scm_start_stack (base, in, out, err) { SCM_NEWCELL (scm_def_outp); pt = scm_add_to_port_table (scm_def_outp); - SCM_CAR (scm_def_outp) = (scm_tc16_fport | SCM_OPN | SCM_WRTNG); + SCM_SETCAR (scm_def_outp, (scm_tc16_fport | SCM_OPN | SCM_WRTNG)); SCM_SETPTAB_ENTRY (scm_def_outp, pt); SCM_SETSTREAM (scm_def_outp, (SCM)out); scm_set_port_revealed_x (scm_def_outp, SCM_MAKINUM (1)); @@ -178,7 +178,7 @@ scm_start_stack (base, in, out, err) { SCM_NEWCELL (scm_def_errp); pt = scm_add_to_port_table (scm_def_errp); - SCM_CAR (scm_def_errp) = (scm_tc16_fport | SCM_OPN | SCM_WRTNG); + SCM_SETCAR (scm_def_errp, (scm_tc16_fport | SCM_OPN | SCM_WRTNG)); SCM_SETPTAB_ENTRY (scm_def_errp, pt); SCM_SETSTREAM (scm_def_errp, (SCM)err); scm_set_port_revealed_x (scm_def_errp, SCM_MAKINUM (1)); @@ -199,7 +199,7 @@ scm_start_stack (base, in, out, err) */ SCM_NEWCELL (scm_rootcont); SCM_SETJMPBUF (scm_rootcont, scm_must_malloc ((long) sizeof (scm_contregs), "continuation")); - SCM_CAR (scm_rootcont) = scm_tc7_contin; + SCM_SETCAR (scm_rootcont, scm_tc7_contin); SCM_SEQ (scm_rootcont) = 0; /* The root continuation if further initialized by scm_restart_stack. */ diff --git a/libguile/ioext.c b/libguile/ioext.c index 221b72fab..0cc53ecc7 100644 --- a/libguile/ioext.c +++ b/libguile/ioext.c @@ -116,14 +116,15 @@ scm_sys_freopen (filename, modes, port) SCM p; p = port; port = SCM_MAKINUM (errno); - SCM_CAR (p) &= ~SCM_OPN; + SCM_SETAND_CAR (p, ~SCM_OPN); scm_remove_from_port_table (p); } else { - SCM_CAR (port) = scm_tc16_fport | scm_mode_bits (SCM_CHARS (modes)); + SCM_SETCAR (port, scm_tc16_fport | scm_mode_bits (SCM_CHARS (modes))); SCM_SETSTREAM (port, (SCM)f); - if (SCM_BUF0 & (SCM_CAR (port) = scm_tc16_fport | scm_mode_bits (SCM_CHARS (modes)))) + SCM_SETCAR (port, scm_tc16_fport | scm_mode_bits (SCM_CHARS (modes))); + if (SCM_BUF0 & SCM_CAR (port)) scm_setbuf0 (port); } SCM_ALLOW_INTS; @@ -163,7 +164,8 @@ scm_sys_duplicate_port (oldpt, modes) struct scm_port_table * pt; pt = scm_add_to_port_table (newpt); SCM_SETPTAB_ENTRY (newpt, pt); - if (SCM_BUF0 & (SCM_CAR (newpt) = scm_tc16_fport | scm_mode_bits (SCM_CHARS (modes)))) + SCM_SETCAR (newpt, scm_tc16_fport | scm_mode_bits (SCM_CHARS (modes))); + if (SCM_BUF0 & SCM_CAR (newpt)) scm_setbuf0 (newpt); SCM_SETSTREAM (newpt, (SCM)f); SCM_PTAB_ENTRY (newpt)->file_name = SCM_PTAB_ENTRY (oldpt)->file_name; @@ -249,8 +251,8 @@ scm_sys_fdopen (fdes, modes) scm_syserror (s_sys_fdopen); pt = scm_add_to_port_table (port); SCM_SETPTAB_ENTRY (port, pt); - if (SCM_BUF0 & (SCM_CAR (port) = scm_tc16_fport - | scm_mode_bits (SCM_CHARS (modes)))) + SCM_SETCAR (port, scm_tc16_fport | scm_mode_bits (SCM_CHARS (modes))); + if (SCM_BUF0 & SCM_CAR (port)) scm_setbuf0 (port); SCM_SETSTREAM (port, (SCM)f); SCM_ALLOW_INTS; diff --git a/libguile/ports.c b/libguile/ports.c index 5c18031c9..342c15d3f 100644 --- a/libguile/ports.c +++ b/libguile/ports.c @@ -444,7 +444,7 @@ scm_close_port (port) if (scm_ptobs[i].fclose) SCM_SYSCALL ((scm_ptobs[i].fclose) (SCM_STREAM (port))); scm_remove_from_port_table (port); - SCM_CAR (port) &= ~SCM_OPN; + SCM_SETAND_CAR (port, ~SCM_OPN); SCM_ALLOW_INTS; return SCM_UNSPECIFIED; } @@ -877,7 +877,7 @@ scm_void_port (mode_str) SCM_DEFER_INTS; mode_bits = scm_mode_bits (mode_str); pt = scm_add_to_port_table (answer); - SCM_CAR (answer) = scm_tc16_void_port | mode_bits; + SCM_SETCAR (answer, scm_tc16_void_port | mode_bits); SCM_SETPTAB_ENTRY (answer, pt); SCM_SETSTREAM (answer, SCM_BOOL_F); SCM_ALLOW_INTS; diff --git a/libguile/ports.h b/libguile/ports.h index 46d0f5cad..55875b197 100644 --- a/libguile/ports.h +++ b/libguile/ports.h @@ -122,9 +122,9 @@ extern int scm_port_table_size; /* Number of ports in scm_port_table. */ #define SCM_SETREVEALED(x,s) (SCM_PTAB_ENTRY(x)->revealed = s) #define SCM_PORT_REPRESENTATION(x) SCM_PTAB_ENTRY(x)->representation #define SCM_SET_PORT_REPRESENTATION(x,s) (SCM_PTAB_ENTRY(x)->representation = s) -#define SCM_CRDYP(port) (SCM_CAR(port) & SCM_CRDY) -#define SCM_CLRDY(port) {SCM_CAR(port) &= SCM_CUC;} -#define SCM_SETRDY(port) {SCM_CAR(port) |= SCM_CRDY;} +#define SCM_CRDYP(port) (SCM_CAR (port) & SCM_CRDY) +#define SCM_CLRDY(port) {SCM_SETAND_CAR (port, SCM_CUC);} +#define SCM_SETRDY(port) {SCM_SETOR_CAR (port, SCM_CRDY);} #define SCM_CUNGET(c,port) {SCM_PTAB_ENTRY(port)->unchr = c; SCM_SETRDY(port);} #define SCM_CGETUN(port) (SCM_PTAB_ENTRY(port)->unchr) diff --git a/libguile/srcprop.h b/libguile/srcprop.h index a5924d737..ae9358b0c 100644 --- a/libguile/srcprop.h +++ b/libguile/srcprop.h @@ -100,8 +100,8 @@ typedef struct scm_srcprops_chunk #define SRCPROPFNAME(p) ((scm_srcprops *) SCM_CDR (p))->fname #define SRCPROPCOPY(p) ((scm_srcprops *) SCM_CDR (p))->copy #define SRCPROPPLIST(p) ((scm_srcprops *) SCM_CDR (p))->plist -#define SETSRCPROPBRK(p) (SCM_CAR (p) = SCM_CAR (p) | (1L << 16)) -#define CLEARSRCPROPBRK(p) (SCM_CAR (p) = SCM_CAR (p) & ~(1L << 16)) +#define SETSRCPROPBRK(p) (SCM_SETOR_CAR (p, (1L << 16))) +#define CLEARSRCPROPBRK(p) SCM_SETAND_CAR (p, ~(1L << 16)) #define SRCPROPMAKPOS(l,c) (((l) << 12) + (c)) #define SETSRCPROPPOS(p,l,c) (SRCPROPPOS (p) = SRCPROPMAKPOS (l, c)) #define SETSRCPROPLINE(p,l) SETSRCPROPPOS (p, l, SRCPROPCOL (p)) diff --git a/libguile/tags.h b/libguile/tags.h index e30798f43..1b21ba8c9 100644 --- a/libguile/tags.h +++ b/libguile/tags.h @@ -323,10 +323,10 @@ typedef long SCM; */ #define SCM_GCMARKP(x) (1 & (int)SCM_CDR(x)) #define SCM_GC8MARKP(x) (0x80 & (int)SCM_CAR(x)) -#define SCM_SETGCMARK(x) (SCM_CDR(x) |= 1) -#define SCM_CLRGCMARK(x) (SCM_CDR(x) &= ~1L) -#define SCM_SETGC8MARK(x) (SCM_CAR(x) |= 0x80) -#define SCM_CLRGC8MARK(x) (SCM_CAR(x) &= ~0x80L) +#define SCM_SETGCMARK(x) SCM_SETOR_CDR (x,1) +#define SCM_CLRGCMARK(x) SCM_SETAND_CDR (x, ~1L) +#define SCM_SETGC8MARK(x) SCM_SETOR_CAR (x, 0x80) +#define SCM_CLRGC8MARK(x) SCM_SETAND_CAR (x, ~0x80L) diff --git a/libguile/throw.c b/libguile/throw.c index 195e3f74a..2b527c16a 100644 --- a/libguile/throw.c +++ b/libguile/throw.c @@ -62,8 +62,8 @@ static int scm_tc16_jmpbuffer; #define SCM_JMPBUFP(O) (SCM_TYP16(O) == scm_tc16_jmpbuffer) #define JBACTIVE(O) (SCM_CAR (O) & (1L << 16L)) -#define ACTIVATEJB(O) (SCM_CAR (O) |= (1L << 16L)) -#define DEACTIVATEJB(O) (SCM_CAR (O) &= ~(1L << 16L)) +#define ACTIVATEJB(O) (SCM_SETOR_CAR (O, (1L << 16L))) +#define DEACTIVATEJB(O) (SCM_SETAND_CAR (O, ~(1L << 16L))) #ifndef DEBUG_EXTENSIONS #define JBJMPBUF(O) ((jmp_buf*)SCM_CDR (O) ) @@ -71,7 +71,7 @@ static int scm_tc16_jmpbuffer; #else #define SCM_JBDFRAME(O) ((scm_debug_frame*)SCM_CAR (SCM_CDR (O)) ) #define JBJMPBUF(O) ((jmp_buf*)SCM_CDR (SCM_CDR (O)) ) -#define SCM_SETJBDFRAME(O,X) SCM_CAR(SCM_CDR (O)) = (SCM)(X) +#define SCM_SETJBDFRAME(O,X) SCM_SETCAR (SCM_CDR (O), (SCM)(X)) #define SETJBJMPBUF(O,X) SCM_SETCDR(SCM_CDR (O), X) static scm_sizet freejb SCM_P ((SCM jbsmob)); @@ -122,7 +122,7 @@ make_jmpbuf () char *mem = scm_must_malloc (sizeof (scm_cell), "jb"); SCM_SETCDR (answer, (SCM) mem); #endif - SCM_CAR(answer) = scm_tc16_jmpbuffer; + SCM_SETCAR (answer, scm_tc16_jmpbuffer); SETJBJMPBUF(answer, (jmp_buf *)0); DEACTIVATEJB(answer); } diff --git a/libguile/unif.c b/libguile/unif.c index cca2ff4f9..9f3aeefb2 100644 --- a/libguile/unif.c +++ b/libguile/unif.c @@ -182,7 +182,7 @@ scm_makflo (x) return scm_flo0; SCM_NEWCELL (z); SCM_DEFER_INTS; - SCM_CAR (z) = scm_tc_flo; + SCM_SETCAR (z, scm_tc_flo); SCM_FLO (z) = x; SCM_ALLOW_INTS; return z; @@ -501,7 +501,7 @@ scm_make_ra (ndim) SCM_DEFER_INTS; SCM_SETCDR (ra, scm_must_malloc ((long) (sizeof (scm_array) + ndim * sizeof (scm_array_dim)), "array")); - SCM_CAR (ra) = ((long) ndim << 17) + scm_tc16_array; + SCM_SETCAR (ra, ((long) ndim << 17) + scm_tc16_array); SCM_ARRAY_V (ra) = scm_nullvect; SCM_ALLOW_INTS; return ra; @@ -583,7 +583,7 @@ scm_dimensions_to_uniform_array (dims, prot, fill) SCM_ASSERT (SCM_NULLP (dims) || (SCM_NIMP (dims) && SCM_CONSP (dims)), dims, SCM_ARG1, s_dimensions_to_uniform_array); ra = scm_shap2ra (dims, s_dimensions_to_uniform_array); - SCM_CAR (ra) |= SCM_ARRAY_CONTIGUOUS; + SCM_SETOR_CAR (ra, SCM_ARRAY_CONTIGUOUS); s = SCM_ARRAY_DIMS (ra); k = SCM_ARRAY_NDIM (ra); while (k--) @@ -653,14 +653,14 @@ scm_ra_set_contp (ra) { if (inc != SCM_ARRAY_DIMS (ra)[k].inc) { - SCM_CAR (ra) &= ~SCM_ARRAY_CONTIGUOUS; + SCM_SETAND_CAR (ra, ~SCM_ARRAY_CONTIGUOUS); return; } inc *= (SCM_ARRAY_DIMS (ra)[k].ubnd - SCM_ARRAY_DIMS (ra)[k].lbnd + 1); } } - SCM_CAR (ra) |= SCM_ARRAY_CONTIGUOUS; + SCM_SETOR_CAR (ra, SCM_ARRAY_CONTIGUOUS); } @@ -736,7 +736,7 @@ scm_make_shared_array (oldra, mapfunc, dims) { if (s[k].ubnd > s[k].lbnd) { - SCM_CAR (indptr) = SCM_MAKINUM (SCM_INUM (SCM_CAR (indptr)) + 1); + SCM_SETCAR (indptr, SCM_MAKINUM (SCM_INUM (SCM_CAR (indptr)) + 1)); imap = scm_apply (mapfunc, scm_reverse (inds), SCM_EOL); if (SCM_ARRAYP (oldra)) |