bit.sa


Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
 
------------------------->  GNU Sather - sourcefile  <-------------------------
-- Copyright (C) 2000 by K Hopper, University of Waikato, New Zealand        --
-- This file is part of the GNU Sather library. It is free software; you may --
-- redistribute  and/or modify it under the terms of the GNU Library General --
-- Public  License (LGPL)  as published  by the  Free  Software  Foundation; --
-- either version 2 of the license, or (at your option) any later version.   --
-- This  library  is distributed  in the  hope that it will  be  useful, but --
-- WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See Doc/LGPL for more details.       --
-- The license text is also available from:  Free Software Foundation, Inc., --
-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA                     --
-------------->  Please email comments to <bug-sather@gnu.org>  <--------------


abstract class $BIT_PATTERNS < $IS_EQ

abstract class $BIT_PATTERNS < $IS_EQ is -- This abstract class models the concept of an object to which no -- semantics is attached - save that of being a bit pattern! -- Version 1.0 May 2001. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 17 May 01 kh Original asize : CARD ; -- The number of bits contained in the storage used by this kind of -- object. end ; -- $BIT_PATTERNS

abstract class $BIT_PATTERN{ETP} < $BIT_PATTERNS, $IMMUTABLE, $HASH

abstract class $BIT_PATTERN{ETP} < $BIT_PATTERNS, $IMMUTABLE, $HASH is -- This abstract class models the concept of an object to which no -- semantics is attached, other than bit-pattern equality and conversion to -- and from a binary string along with the ability to use a bit-pattern as -- the key into a hash table.. -- Version 1.2 May 2001. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 16 Feb 99 kh Original -- 14 Nov 00 kh Introduced features from children! -- 28 May 01 kh Added slice reader/writer null : SAME ; -- This feature returns an object in which all bits are clear. octet : OCTET ; -- This feature returns the octet which contains the eight bits of self -- with the indices 0 to 7. hextet : HEXTET ; -- This feature returns the hextet object which contains the lowest -- sixteen bits of self - extended with clear bits if self does not contain -- sixteen bits - with the indices 0 to 15. quad : QUADBITS ; -- This feature returns the object which contains the lowest thirty-two -- bits of self - extended with clear bits if self does not contain -- thirty-two bits - with the indices 0 to 31. maxnum : CARD ; -- This feature returns the maximum unsigned whole number which can be -- stored in this class of object. card : CARD ; -- This feature returns the cardinal number formed by taking the bit- -- pattern of self in the lowest indexed bit positions in the result extended -- with clear bits to make up the number of bits required in a cardinal -- number. char : CHAR ; -- This feature returns the same bit-pattern as an object of type CHAR -- with which, however, no particular culture-dependent semantics are -- associated. bool : BOOL ; -- This predicate returns true if and only if at least one bit is set. int : INT ; -- This feature returns a signed integer number formed by taking the bit- -- pattern of self in the lowest indexed bit positions in the result extended -- with clear bits to make up the number of bits required in a cardinal -- number. bit( index : CARD ) : BIT ; -- This feature returns the value of the bit indexed by the given -- parameter. alter( index : CARD, val : BIT ) : SAME ; -- This feature returns a new object containing the same bit-pattern as -- self except for the one indexed by the first argument which has been set -- to val. slice( lsb : CARD, count : CARD ) : SAME ; -- This feature returns a new object containing the indicated group of -- bits in the lowest count positions (ie starting from bit 0). slice( lsb : CARD, count : CARD, val : ETP ) : SAME ; -- This feature returns a new object containing the indicated group of -- bits in the lowest count positions (ie starting from bit 0). set( index : CARD ) : BOOL ; -- This predicate returns true if and only if the indexed bit of self -- has the value bitset. clear( index : CARD ) : BOOL ; -- This predicate returns true if and only if the indexed bit of self -- has the value bitclear. bit_and( other : ETP ) : SAME ; -- This feature returns the result of applying the and operation to each -- individual bit of self and the corresponding bit of other. bit_invert : SAME ; -- This feature returns the result of setting each bit of self which has -- the value bitset to bitclear and vice versa. bit_or( other : ETP ) : SAME ; -- This feature returns the result of applying the or operation to each -- individual bit of self and the corresponding bit of other. bit_xor( other : ETP ) : SAME ; -- This feature returns the result of applying the xor operation to each -- individual bit of self and the corresponding bit of other. left( places : CARD ) : SAME ; -- This feature returns the object which results from shifting the bit- -- pattern of self left (towards higher indices) by the number of places -- indicated, filling vacated positions by the value bitclear. right( places : CARD ) : SAME ; -- This feature returns the object which results from shifting the bit- -- pattern of self right (towards lower indices) by the number of places -- indicated, filling vacated positions by the value bitclear. highest( val : BIT ) : CARD ; -- This feature returns the index of the highest bit which has the value -- given by the argument - or CARD::nil if no bit has that value. highest : CARD ; -- This feature returns the index of the highest bit which has the value -- bitset - or CARD::nil if no bit has that value. lowest( val : BIT ) : CARD ; -- This feature returns the index of the lowest bit which has the value -- given by the argument - or CARD::nil if no bit has that value. lowest : CARD ; -- This feature returns the index of the lowest bit which has the value -- bitset - or CARD::nil if no bit has that value. hex_str( lib : LIBCHARS ) : STR ; -- This feature returns a hexadecimal text string representation of self -- using the given encoding and repertoire. hex_str : STR ; -- This feature returns a hexadecimal text string representation of self -- using the default encoding and repertoire. end ; -- $BIT_PATTERN

immutable class BIT < $IS_EQ

immutable class BIT < $IS_EQ is -- This class is defined by the Sather language as the fundamental binary -- digit from which everything except object of the class BOOL are constructed. -- The two possible states are bitset and bitclear which are specified to be -- a binary one and binary zero respectively. These values are prevasive in -- the language. -- Version 1.2 Apr 97. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 11 Dec 96 kh Original -- 3 Jan 97 kh Changed to CARD from INT -- 8 Apr 97 kh The values setbit and clearbit now reserved! include COMPARABLE ; create( val : CARD ) : SAME pre (val <= 1) is -- This produces a single bit object which has a nominal single bit -- size so far as program manipulation is concerned!! builtin CARD_BIT end ; card : CARD is -- This converts the bit into an integer numeric value (of zero -- or one). builtin BIT_CARD end ; is_eq( other : SAME ) : BOOL is -- This returns reus if and only if the bits self and other have the -- same binary value. builtin BIT_IS_EQ end ; set : BOOL is -- This routine returns true if and only if self has the binary -- value one. return (self = setbit) end ; clear : BOOL is -- This routine returns true if and only if self has the binary -- value zero. return (self = clearbit) end ; end ; -- BIT