|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.princeton.toy.lang.TWord
public class TWord
TWord is the primitive value which toy registers and memory can take. TWord is immutable, like java.lang.String, which means that classes can return TWords without being concerned with wheter or not the recipient will change the value. The immutable feature allows us to keep track of and reuse TWord CACHED_REFERENCES to save memory allocation overhead.
CACHED_REFERENCES of TWord are slightly different than short primitives in that they can take on a special value, UNINITIALIZED_VALUE, which is identical to getWord(0) except for two things:
Field Summary | |
---|---|
static int |
BIT_COUNT
The number of bits a TWord would take. |
static char[] |
HEX_DIGITS
An array to convert an integer between 0 and 16 to a hexidecimal digit. |
static String[] |
HEX_PAIRS
An array to convert an integer between 0 and 256 to a pair of hexidecimal digit. |
static TWord |
MAX_VALUE
The maximum value a TWord can take. |
static TWord |
MIN_VALUE
The minimum value a TWord can take. |
static TWord |
ONE
A constant for getWord((short)0). |
static TWord |
UNINITIALIZED_VALUE
The uninitialized value is identical to getWord(0) with the following exceptions: The isInitialized() method returns false in UNINITIALIZED_VALUE but not in getWord(0). |
static TWord |
ZERO
A constant for getWord((short)0). |
Method Summary | |
---|---|
static TWord |
add(TWord a,
TWord b,
TExceptionHandler exceptionHandler)
Implements the addition operator for the TWord type. |
static TWord |
and(TWord a,
TWord b,
TExceptionHandler exceptionHandler)
Implements the bitwise-and operator for the TWord type. |
boolean |
equals(Object obj)
Evaluates wheter or not two TWords have the same values. |
byte |
getD()
Returns the second leftmost/most-significant four bits of the TWord. |
short |
getImm()
Returns the rightmost/least-significant eight bits of the TWord. |
byte |
getOp()
Returns the leftmost/most-significant four bits of the TWord. |
byte |
getS()
Returns the third leftmost/most-significant four bits of the TWord. |
byte |
getT()
Returns the rightmost/least-significant four bits of the TWord. |
short |
getValue()
Returns the short primitive to which this TWord corresponds. |
static TWord |
getWord(short value)
Returns a TWord initialize to the given value. |
static int |
hexDigitToInt(char c)
Returns the hexidecimal value of a character. |
TWord |
initializedValue()
Returns the initialized equivalent of this word. |
static boolean |
isHexDigit(char c)
Returns whether or not a character is a hexidecimal digit. |
boolean |
isInitialized()
Returns wheter or not this word has been defined yet. |
static TWord |
leftShift(TWord a,
TWord b,
TExceptionHandler exceptionHandler)
Implements the logical-left-shift operator for the TWord type. |
static TWord |
parseWord(String string,
int radix)
Parses a TWord from a string. |
static TWord |
rightShift(TWord a,
TWord b,
TExceptionHandler exceptionHandler)
Implements the arithmatic-right-shift operator for the TWord type. |
static TWord |
subtract(TWord a,
TWord b,
TExceptionHandler exceptionHandler)
Implements the subtraction operator for the TWord type. |
String |
toBinaryString(boolean distinguishUninitialized)
Returns the binary representation of this TWord. |
String |
toDecimalString(boolean distinguishUninitialized)
Returns the decimal representation of this TWord. |
String |
toFormattedBinaryString(boolean distinguishUninitialized)
Returns the formatted binary representation of this TWord in which every four bits are separated by a space. |
String |
toHexString(boolean distinguishUninitialized)
Returns the hexidecimal representation of this TWord. |
String |
toPseudoCodeString(boolean distinguishUninitialized)
Returns the pseudo-code form of the TWord. |
String |
toString()
Returns the detailed representation of this TWord. |
String |
toString(boolean distinguishUninitialized)
Returns the detailed representation of this TWord. |
static TWord |
xor(TWord a,
TWord b,
TExceptionHandler exceptionHandler)
Implements the bitwise-xor operator for the TWord type. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int BIT_COUNT
public static final char[] HEX_DIGITS
public static final String[] HEX_PAIRS
public static final TWord UNINITIALIZED_VALUE
public static final TWord MIN_VALUE
public static final TWord MAX_VALUE
public static final TWord ZERO
public static final TWord ONE
Method Detail |
---|
public boolean isInitialized()
public short getValue()
public byte getOp()
public byte getD()
public byte getS()
public byte getT()
public TWord initializedValue()
public short getImm()
public static TWord getWord(short value)
value
- The value which the TWord should take.
public static TWord parseWord(String string, int radix) throws NumberFormatException
string
- The string to parse.radix
- The base of the number being parsed (probably 2, 10, or 16).
NumberFormatException
public boolean equals(Object obj)
equals
in class Object
obj
- The object being compared to this TWord.
public String toBinaryString(boolean distinguishUninitialized)
distinguishUninitialized
- Wheter or not to return a string of question marks if this
TWord is UNINITIALIZED_VALUE.
public String toFormattedBinaryString(boolean distinguishUninitialized)
distinguishUninitialized
- Wheter or not to return a string of question marks if this
TWord is UNINITIALIZED_VALUE.
public String toDecimalString(boolean distinguishUninitialized)
distinguishUninitialized
- Wheter or not to return a string of question marks if this
TWord is UNINITIALIZED_VALUE.
public String toHexString(boolean distinguishUninitialized)
distinguishUninitialized
- Wheter or not to return a string of question marks if this
TWord is UNINITIALIZED_VALUE.
public String toString()
toString
in class Object
public String toString(boolean distinguishUninitialized)
distinguishUninitialized
- Wheter or not to return a string of question marks if this
TWord is UNINITIALIZED_VALUE.
public String toPseudoCodeString(boolean distinguishUninitialized)
distinguishUninitialized
- Wheter or not to return "Uninitialized Value" if
this TWord is UNINITIALIZED_VALUE.
public static TWord add(TWord a, TWord b, TExceptionHandler exceptionHandler) throws TException
a
- The left operand.b
- The right operand.exceptionHandler
- The hander for any exceptional conditions which might be raised. If
the exceptionHandler is null, all exceptions will be ignored.
TException
TExceptionType.REGISTER_UNINITIALIZED
,
TExceptionType.OVERFLOW
public static TWord subtract(TWord a, TWord b, TExceptionHandler exceptionHandler) throws TException
a
- The left operand.b
- The right operand.exceptionHandler
- The hander for any exceptional conditions which might be raised. If
the exceptionHandler is null, all exceptions will be ignored.
TException
TExceptionType.REGISTER_UNINITIALIZED
,
TExceptionType.OVERFLOW
public static TWord and(TWord a, TWord b, TExceptionHandler exceptionHandler) throws TException
a
- The left operand.b
- The right operand.exceptionHandler
- The hander for any exceptional conditions which might be raised. If
the exceptionHandler is null, all exceptions will be ignored.
TException
TExceptionType.REGISTER_UNINITIALIZED
,
TExceptionType.OVERFLOW
public static TWord xor(TWord a, TWord b, TExceptionHandler exceptionHandler) throws TException
a
- The left operand.b
- The right operand.exceptionHandler
- The hander for any exceptional conditions which might be raised. If
the exceptionHandler is null, all exceptions will be ignored.
TException
TExceptionType.REGISTER_UNINITIALIZED
,
TExceptionType.OVERFLOW
public static TWord leftShift(TWord a, TWord b, TExceptionHandler exceptionHandler) throws TException
a
- The left operand.b
- The right operand.exceptionHandler
- The hander for any exceptional conditions which might be raised. If
the exceptionHandler is null, all exceptions will be ignored.
TException
TExceptionType.REGISTER_UNINITIALIZED
,
TExceptionType.SHIFT_OUT_OF_BOUNDS
public static TWord rightShift(TWord a, TWord b, TExceptionHandler exceptionHandler) throws TException
a
- The left operand.b
- The right operand.exceptionHandler
- The hander for any exceptional conditions which might be raised. If
the exceptionHandler is null, all exceptions will be ignored.
TException
TExceptionType.REGISTER_UNINITIALIZED
,
TExceptionType.SHIFT_OUT_OF_BOUNDS
public static boolean isHexDigit(char c)
c
- The character to test.
public static int hexDigitToInt(char c)
c
- The character to convert. If this character is not a hex digit, an
IllegalArgumentException will be thrown.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |