Package io.matita08.value
Class Value
java.lang.Object
io.matita08.value.Value
- Direct Known Subclasses:
DoubleValue,SingleValue,UndefinedDoubleValue,UndefinedSingleValue
Abstract base class representing a value in the CPU simulator.
This class defines the common interface for all value types used throughout
the simulation, including single values, double values, and undefined values.
The Value hierarchy supports different value representations:
- SingleValue: Standard single-word values with optional sign interpretation
- DoubleValue: Multi-word values for larger address spaces or extended precision
- UndefinedSingleValue: Uninitialized single values with random behavior
- UndefinedDoubleValue: Uninitialized double values with random behavior
All values support arithmetic operations, conversion between signed/unsigned representations, and proper handling of undefined states. The class provides factory methods for creating appropriate value types based on the current CPU configuration.
Undefined values simulate the behavior of uninitialized memory or registers, returning random values when accessed to help identify programming errors.
- Since:
- 1.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final UndefinedSingleValueSingleton instance representing an undefined single value. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract ValuePerforms addition with another value.static Valuecreate(int n) Creates a new single value with the specified numeric value.static Valuecreate(int n, boolean signed) Creates a new single value with the specified numeric value and sign interpretation.booleanequals(int n) Checks if this value equals the specified numeric value.intget()Gets the numeric value as an integer.static ValuegetNew()Creates a new undefined single value.static ValueCreates a new undefined address-sized value.abstract intGets the value interpreted as a signed integer.abstract intGets the value interpreted as an unsigned integer.booleanChecks if this value is in an undefined state.abstract ValuePerforms multiplication with another value.abstract Valueset(int n) Sets this value to the specified numeric value.voidSets this value to match another value.abstract ValuePerforms subtraction with another value.toString()Returns a string representation of this value.static Stringunset()Returns the string representation of an unset/undefined value.
-
Field Details
-
nullValue
Singleton instance representing an undefined single value. This constant is used as a prototype for creating new undefined values.
-
-
Constructor Details
-
Value
public Value()
-
-
Method Details
-
getNew
Creates a new undefined single value. The returned value will exhibit random behavior when accessed, simulating uninitialized memory.- Returns:
- a new undefined single value instance
-
getNewAddress
Creates a new undefined address-sized value. The size and structure depend on the current address size configuration. For single-word addresses, returns a DoubleValue with one undefined component. For multi-word addresses, returns a DoubleValue with multiple undefined components.- Returns:
- a new undefined address-sized value
- See Also:
-
create
Creates a new single value with the specified numeric value. The value is treated as unsigned by default.- Parameters:
n- the numeric value to wrap- Returns:
- a new SingleValue containing the specified number
-
create
Creates a new single value with the specified numeric value and sign interpretation.- Parameters:
n- the numeric value to wrapsigned- true if the value should be interpreted as signed, false for unsigned- Returns:
- a new SingleValue with the specified value and sign interpretation
-
isUndefined
public boolean isUndefined()Checks if this value is in an undefined state. Undefined values represent uninitialized memory or registers.- Returns:
- true if this value is undefined, false for concrete values
-
set
Sets this value to the specified numeric value. The behavior depends on the concrete value type - some types may return a new instance while others modify the current instance.- Parameters:
n- the new numeric value- Returns:
- the value instance (may be this instance or a new one)
-
set
Sets this value to match another value. The default implementation extracts the numeric value and callsset(int). Subclasses may override this for more sophisticated value copying.- Parameters:
v- the value to copy from
-
add
Performs addition with another value. The operation is performed using the appropriate numeric representation and may handle sign extension or overflow based on the value types involved.- Parameters:
v2- the value to add to this value- Returns:
- a new value containing the sum
-
sub
Performs subtraction with another value. The operation is performed using the appropriate numeric representation and may handle sign extension or underflow based on the value types involved.- Parameters:
v2- the value to subtract from this value- Returns:
- a new value containing the difference
-
mul
Performs multiplication with another value. The operation is performed using the appropriate numeric representation and may handle overflow based on the value types involved.- Parameters:
v2- the value to multiply with this value- Returns:
- a new value containing the product
-
toString
Returns a string representation of this value. The representation uses the radix specified byConstants.getRadix()and may show special indicators for undefined values. -
get
public int get()Gets the numeric value as an integer. The default implementation delegates togetUnsigned().- Returns:
- the numeric value as an integer
-
unset
Returns the string representation of an unset/undefined value. This is used for display purposes when a value hasn't been initialized.- Returns:
- the string "?" representing an undefined value
-
getSigned
public abstract int getSigned()Gets the value interpreted as a signed integer. The sign interpretation depends on the value type and configuration.- Returns:
- the value as a signed integer
-
getUnsigned
public abstract int getUnsigned()Gets the value interpreted as an unsigned integer. All negative representations are treated as positive values.- Returns:
- the value as an unsigned integer
-
equals
public boolean equals(int n) Checks if this value equals the specified numeric value. The comparison is performed against both signed and unsigned interpretations to handle cases where the same bit pattern can represent different values.- Parameters:
n- the numeric value to compare against- Returns:
- true if either the signed or unsigned interpretation matches the specified value
-