edu.princeton.toy.lang
public class TWord extends java.lang.Object
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:
Modifier and Type | Field and Description |
---|---|
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 java.lang.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).
|
Modifier and Type | Method and Description |
---|---|
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.
|
static java.lang.String |
commentLine(java.lang.String line)
takes a line that has an instruction and inserts a comment into the line
preserving what ever user comments there are.
|
boolean |
equals(java.lang.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 |
isCommand(java.lang.String cmd)
checks if the given parameter is a valid TOY instruction
|
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 boolean |
isPseudoCode(java.lang.String str)
Checks if the given string is a valid TOY pseudocode
|
static TWord |
leftShift(TWord a,
TWord b,
TExceptionHandler exceptionHandler)
Implements the logical-left-shift operator for the TWord type.
|
static TWord |
parseWord(java.lang.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.
|
java.lang.String |
toBinaryString(boolean distinguishUninitialized)
Returns the binary representation of this TWord.
|
java.lang.String |
toDecimalString(boolean distinguishUninitialized)
Returns the decimal representation of this TWord.
|
java.lang.String |
toFormattedBinaryString(boolean distinguishUninitialized)
Returns the formatted binary representation of this TWord in which every four bits are
separated by a space.
|
java.lang.String |
toHexString(boolean distinguishUninitialized)
Returns the hexidecimal representation of this TWord.
|
java.lang.String |
toPseudoCodeString(boolean distinguishUninitialized)
Returns the pseudo-code form of the TWord.
|
java.lang.String |
toString()
Returns the detailed representation of this TWord.
|
java.lang.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.
|
public static final int BIT_COUNT
public static final char[] HEX_DIGITS
public static final java.lang.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
public static boolean isCommand(java.lang.String cmd)
public static java.lang.String commentLine(java.lang.String line)
public static boolean isPseudoCode(java.lang.String str)
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(java.lang.String string, int radix) throws java.lang.NumberFormatException
string
- The string to parse.radix
- The base of the number being parsed (probably 2, 10, or 16).java.lang.NumberFormatException
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- The object being compared to this TWord.public java.lang.String toBinaryString(boolean distinguishUninitialized)
distinguishUninitialized
- Wheter or not to return a string of question marks if this
TWord is UNINITIALIZED_VALUE.public java.lang.String toFormattedBinaryString(boolean distinguishUninitialized)
distinguishUninitialized
- Wheter or not to return a string of question marks if this
TWord is UNINITIALIZED_VALUE.public java.lang.String toDecimalString(boolean distinguishUninitialized)
distinguishUninitialized
- Wheter or not to return a string of question marks if this
TWord is UNINITIALIZED_VALUE.public java.lang.String toHexString(boolean distinguishUninitialized)
distinguishUninitialized
- Wheter or not to return a string of question marks if this
TWord is UNINITIALIZED_VALUE.public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toString(boolean distinguishUninitialized)
distinguishUninitialized
- Wheter or not to return a string of question marks if this
TWord is UNINITIALIZED_VALUE.public java.lang.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.