/* Copyright (c) 1979 Regents of the University of California */
static char sccsid
[] = "@(#)cset.c 1.2 10/19/80";
* rummage through a `constant' set (i.e. anything within [ ]'s) tree
* and decide if this is a compile time constant set or a runtime set.
* this information is returned in a structure passed from the caller.
* while rummaging, this also reorders the tree so that all ranges
* preceed all singletons.
precset( r
, settype
, csetp
)
register struct nl
*exptype
;
csetp
-> comptime
= TRUE
;
if ( settype
-> class == SET
) {
* the easy case, we are told the type of the set.
exptype
= settype
-> type
;
* we are told the type, but it's not a set
* supposedly possible if someone tries
* e.g string context [1,2] = 'abc'
error("Constant set involved in non set context");
return csetp
-> comptime
;
* So far we have no indication
* of what the set type should be.
* We "look ahead" and try to infer
* The type of the constant set
* by evaluating one of its members.
* tentative for [], return type of `intset'
settype
= lookup( intset
);
settype
= settype
-> type
;
return csetp
-> comptime
;
if ( isnta( settype
, "t" ) ) {
error("Set default type \"intset\" is not a set");
return csetp
-> comptime
;
csetp
-> csettype
= settype
;
return csetp
-> comptime
;
return csetp
-> comptime
;
t
= rvalue(e
, NIL
, RREQ
);
return csetp
-> comptime
;
* The type of the set, settype, is
* deemed to be a set of the base type
* of t, which we call exptype. If,
* however, this would involve a
* "set of integer", we cop out
* and use "intset"'s current scoped
error("Sets may not have 'real' elements");
return csetp
-> comptime
;
error("Set elements must be scalars, not %ss", nameof(t
));
return csetp
-> comptime
;
settype
= lookup(intset
);
return csetp
-> comptime
;
if (isnta(settype
, "t")) {
error("Set default type \"intset\" is not a set");
return csetp
-> comptime
;
* say we are doing an intset
* but, if we get out of range errors for intset
* we punt constructing the set at compile time.
return csetp
-> comptime
;
if (exptype
->class != RANGE
)
settype
= defnl(0, SET
, exptype
, 0);
csetp
-> csettype
= settype
;
upper
= set
.lwrb
+ set
.uprbp
;
* don't hang this one anywhere.
if ( csetp
-> comptime
&& constval( e
[2] ) ) {
if ( ((long)con
.crval
) < lower
|| ((long)con
.crval
) > upper
) {
csetp
-> comptime
= FALSE
;
error("Range upper bound of %d out of set bounds" , ((long)con
.crval
) );
rangeupper
= ((long)con
.crval
);
csetp
-> comptime
= FALSE
;
t
= rvalue(e
[2], NIL
, RREQ
);
rvalue(e
[1], NIL
, RREQ
);
if (incompat(t
, exptype
, e
[2])) {
cerror("Upper bound of element type clashed with set type in constant set");
if ( csetp
-> comptime
&& constval( e
[1] ) ) {
if ( ((long)con
.crval
) < lower
|| ((long)con
.crval
) > upper
) {
csetp
-> comptime
= FALSE
;
error("Range lower bound of %d out of set bounds" , ((long)con
.crval
) );
csetp
-> comptime
= FALSE
;
t
= rvalue(e
[1], NIL
, RREQ
);
if (incompat(t
, exptype
, e
[1])) {
cerror("Lower bound of element type clashed with set type in constant set");
* remove this range from the tree list and
* hang it on the pairs list.
if ( csetp
-> comptime
&& constval( e
) ) {
if ( ((long)con
.crval
) < lower
|| ((long)con
.crval
) > upper
) {
csetp
-> comptime
= FALSE
;
error("Value of %d out of set bounds" , ((long)con
.crval
) );
csetp
-> comptime
= FALSE
;
t
= rvalue((int *) e
, NLNIL
, RREQ
);
if (incompat(t
, exptype
, e
)) {
cerror("Element type clashed with set type in constant set");
* take this expression off the tree list and
* hang it on the list of singletons.
for ( el
= pairp
; el
[2] != NIL
; el
= el
[2] ) /* void */;
for ( el
= singp
; el
[2] != NIL
; el
= el
[2] ) /* void */;
if ( csetp
-> csettype
== NIL
) {
csetp
-> comptime
= TRUE
;
return csetp
-> comptime
;
#define BITSPERLONG ( sizeof( long ) * BITSPERBYTE )
* mask[i] has the low i bits turned off.
0xffffffff , 0xfffffffe , 0xfffffffc , 0xfffffff8 ,
0xfffffff0 , 0xffffffe0 , 0xffffffc0 , 0xffffff80 ,
0xffffff00 , 0xfffffe00 , 0xfffffc00 , 0xfffff800 ,
0xfffff000 , 0xffffe000 , 0xffffc000 , 0xffff8000 ,
0xffff0000 , 0xfffe0000 , 0xfffc0000 , 0xfff80000 ,
0xfff00000 , 0xffe00000 , 0xffc00000 , 0xff800000 ,
0xff000000 , 0xfe000000 , 0xfc000000 , 0xf8000000 ,
0xf0000000 , 0xe0000000 , 0xc0000000 , 0x80000000 ,
* given a csetstr, either
* put out a compile time constant set and an lvalue to it.
* put out rvalues for the singletons and the pairs
long tempset
[ ( MAXSET
/ BITSPERLONG
) + 1 ];
char labelname
[ BUFSIZ
];
if ( csetp
-> comptime
) {
setran( ( csetp
-> csettype
) -> type
);
limit
= &tempset
[ ( set
.uprbp
/ BITSPERLONG
) + 1 ];
for ( lp
= &tempset
[0] ; lp
< limit
; lp
++ ) {
for ( el
= r
[2] ; el
!= NIL
; el
= el
[2] ) {
lower
= (long) con
.crval
;
upper
= (long) con
.crval
;
lowerdiv
= ( lower
- set
.lwrb
) / BITSPERLONG
;
lowermod
= ( lower
- set
.lwrb
) % BITSPERLONG
;
upperdiv
= ( upper
- set
.lwrb
) / BITSPERLONG
;
uppermod
= ( upper
- set
.lwrb
) % BITSPERLONG
;
if ( lowerdiv
== upperdiv
) {
temp
&= ~mask
[ uppermod
+ 1 ];
tempset
[ lowerdiv
] |= temp
;
limit
= &tempset
[ upperdiv
-1 ];
for ( lp
= &tempset
[ lowerdiv
+1 ] ; lp
<= limit
; lp
++ ) {
if ( lowerdiv
!= upperdiv
) {
tempset
[ upperdiv
] |= ~mask
[ uppermod
+ 1 ];
lowerdiv
= ( ((long)con
.crval
) - set
.lwrb
) / BITSPERLONG
;
lowermod
= ( ((long)con
.crval
) - set
.lwrb
) % BITSPERLONG
;
tempset
[ lowerdiv
] |= ( 1 << lowermod
);
putprintf( " .data" , 0 );
putprintf( " .align 2" , 0 );
limit
= &tempset
[ ( set
.uprbp
/ BITSPERLONG
) + 1 ];
putprintf( " .long 0x%x" , 1 , *lp
++ );
for ( temp
= 2 ; ( temp
<= 8 ) && lp
< limit
; temp
++ ) {
putprintf( ",0x%x" , 1 , *lp
++ );
putprintf( " .text" , 0 );
sprintf( labelname
, PREFIXFORMAT
, LABELPREFIX
, label
);
putleaf( P2ICON
, 0 , 0 , P2PTR
| P2STRTY
, labelname
);
put( 2, O_CON
, (set
.uprbp
/ BITSPERLONG
+ 1) *
(BITSPERLONG
/ BITSPERBYTE
));
limit
= &tempset
[ ( set
.uprbp
/ BITSPERLONG
) + 1 ];
put( 2, O_CASE4
, *lp
++);
putleaf( P2ICON
, csetp
-> paircnt
, 0 , P2INT
, 0 );
putop( P2LISTOP
, P2INT
);
putleaf( P2ICON
, csetp
-> singcnt
, 0 , P2INT
, 0 );
putop( P2LISTOP
, P2INT
);
for ( el
= r
[2] ; el
!= NIL
; el
= el
[2] ) {
rvalue( e
[2] , NIL
, RREQ
);
putop( P2LISTOP
, P2INT
);
rvalue( e
[1] , NIL
, RREQ
);
putop( P2LISTOP
, P2INT
);
rvalue( e
, NIL
, RREQ
);
putop( P2LISTOP
, P2INT
);
for ( el
= r
[2] ; el
!= NIL
; el
= el
[2] ) {
stkrval( e
[2] , NIL
, RREQ
);
stkrval( e
[1] , NIL
, RREQ
);
stkrval( e
, NIL
, RREQ
);
put( 2 , O_CON24
, csetp
-> singcnt
);
put( 2 , O_CON24
, csetp
-> paircnt
);