Class Value

java.lang.Object
io.matita08.value.Value
Direct Known Subclasses:
DoubleValue, SingleValue, UndefinedDoubleValue, UndefinedSingleValue

public abstract class Value extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    Singleton instance representing an undefined single value.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract Value
    add(Value v2)
    Performs addition with another value.
    static Value
    create(int n)
    Creates a new single value with the specified numeric value.
    static Value
    create(int n, boolean signed)
    Creates a new single value with the specified numeric value and sign interpretation.
    boolean
    equals(int n)
    Checks if this value equals the specified numeric value.
    int
    get()
    Gets the numeric value as an integer.
    static Value
    Creates a new undefined single value.
    static Value
    Creates a new undefined address-sized value.
    abstract int
    Gets the value interpreted as a signed integer.
    abstract int
    Gets the value interpreted as an unsigned integer.
    boolean
    Checks if this value is in an undefined state.
    abstract Value
    mul(Value v2)
    Performs multiplication with another value.
    abstract Value
    set(int n)
    Sets this value to the specified numeric value.
    void
    Sets this value to match another value.
    abstract Value
    sub(Value v2)
    Performs subtraction with another value.
    Returns a string representation of this value.
    static String
    Returns the string representation of an unset/undefined value.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • nullValue

      public static final UndefinedSingleValue 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

      public static Value 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

      public static Value 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

      public static Value create(int n)
      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

      public static Value create(int n, boolean signed)
      Creates a new single value with the specified numeric value and sign interpretation.
      Parameters:
      n - the numeric value to wrap
      signed - 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

      public abstract Value set(int n)
      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

      public void set(Value v)
      Sets this value to match another value. The default implementation extracts the numeric value and calls set(int). Subclasses may override this for more sophisticated value copying.
      Parameters:
      v - the value to copy from
    • add

      public abstract Value add(Value v2)
      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

      public abstract Value sub(Value v2)
      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

      public abstract Value mul(Value v2)
      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

      public String toString()
      Returns a string representation of this value. The representation uses the radix specified by Constants.getRadix() and may show special indicators for undefined values.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this value
    • get

      public int get()
      Gets the numeric value as an integer. The default implementation delegates to getUnsigned().
      Returns:
      the numeric value as an integer
    • unset

      public static String 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