LOAD '_OBJWD_/varbit.so';

CREATE FUNCTION varbitin(opaque)
   RETURNS bit
   AS '_OBJWD_/varbit.so'
   LANGUAGE 'c';

CREATE FUNCTION zpbitout(opaque)
   RETURNS opaque
   AS '_OBJWD_/varbit.so'
   LANGUAGE 'c';

CREATE TYPE bit (
   internallength = -1,
   input = varbitin,
   output = zpbitout
);

CREATE FUNCTION bitcat(bit,bit) RETURNS bit
  AS '_OBJWD_/varbit.so'
  LANGUAGE 'C';

CREATE OPERATOR || (
  leftarg = bit,
  rightarg = bit,
  procedure = bitcat
);

CREATE FUNCTION bitsubstr(bit,integer,integer) RETURNS bit
  AS '_OBJWD_/varbit.so'
  LANGUAGE 'C';

CREATE FUNCTION biteq(bit,bit) RETURNS bool
  AS '_OBJWD_/varbit.so'
  LANGUAGE 'C';

CREATE OPERATOR = (
  leftarg = bit,
  rightarg = bit,
  procedure = biteq,
  negator = <>,
  commutator = =
); 

CREATE FUNCTION bitne(bit,bit) RETURNS bool
  AS '_OBJWD_/varbit.so'
  LANGUAGE 'C';

CREATE OPERATOR <> (
  leftarg = bit,
  rightarg = bit,
  procedure = bitne,
  negator = =,
  commutator = <>
); 

CREATE FUNCTION bitlt(bit,bit) RETURNS bool
  AS '_OBJWD_/varbit.so'
  LANGUAGE 'C';

CREATE OPERATOR < (
  leftarg = bit,
  rightarg = bit,
  procedure = bitlt
); 

CREATE FUNCTION bitle(bit,bit) RETURNS bool
  AS '_OBJWD_/varbit.so'
  LANGUAGE 'C';

CREATE OPERATOR <= (
  leftarg = bit,
  rightarg = bit,
  procedure = bitle
); 

CREATE FUNCTION bitgt(bit,bit) RETURNS bool
  AS '_OBJWD_/varbit.so'
  LANGUAGE 'C';

CREATE OPERATOR > (
  leftarg = bit,
  rightarg = bit,
  procedure = bitgt,
  negator = <=,
  commutator = <
); 

CREATE FUNCTION bitge(bit,bit) RETURNS bool
  as '_OBJWD_/varbit.so'
  language 'C';

CREATE OPERATOR >= (
  leftarg = bit,
  rightarg = bit,
  procedure = bitge,
  negator = <,
  commutator = <=
); 

CREATE FUNCTION bitcmp(bit,bit) RETURNS integer
  AS '_OBJWD_/varbit.so'
  LANGUAGE 'C';

CREATE OPERATOR <=> (
  leftarg = bit,
  rightarg = bit,
  procedure = bitcmp
); 

CREATE FUNCTION bitor(bit,bit) RETURNS bit
  AS '_OBJWD_/varbit.so'
  LANGUAGE 'C';

CREATE OPERATOR | (
  leftarg = bit,
  rightarg = bit,
  procedure = bitor,
  commutator = |
); 

CREATE FUNCTION bitand(bit,bit) RETURNS bit
  AS '_OBJWD_/varbit.so'
  LANGUAGE 'C';

CREATE OPERATOR & (
  leftarg = bit,
  rightarg = bit,
  procedure = bitand,
  commutator = &
); 


CREATE FUNCTION bitxor(bit,bit) RETURNS bit
  AS '_OBJWD_/varbit.so'
  LANGUAGE 'C';

CREATE OPERATOR ^ (
  leftarg = bit,
  rightarg = bit,
  procedure = bitxor
); 

CREATE FUNCTION bitnot(bit) RETURNS bit
  AS '_OBJWD_/varbit.so'
  LANGUAGE 'C';

CREATE OPERATOR ~ (
  rightarg = bit,
  procedure = bitnot
); 

CREATE FUNCTION bitshiftleft(bit,integer) RETURNS bit
  AS '_OBJWD_/varbit.so'
  LANGUAGE 'C';

CREATE OPERATOR << (
  leftarg = bit,
  rightarg = integer,
  procedure = bitshiftleft
);

CREATE FUNCTION bitshiftright(bit,integer) RETURNS bit
  AS '_OBJWD_/varbit.so'
  LANGUAGE 'C';

CREATE OPERATOR >> (
  leftarg = bit,
  rightarg = integer,
  procedure = bitshiftright
);
