Class SVM_CONVERT


public class SVM_CONVERT extends SVM_Instruction

SVM-INSTRUCTION: CONVERT fromType toType

Runtime Stack
   ..., tos →
   ..., result

The 'tos' is popped off the Runtime stack.
The 'result' is calculated by converting tos 'toType'.
Then the 'result' is pushed onto the Runtime Stack.

Not all conversions are valid, see the table below. An attempt to perform an invalid conversion is an error.

The conversion performed will in some cases be illegal because of the actual value;

Conversion from a GADDR to OADDR (AADDR) means: take the object address (attribute address) part of the general address and return as result. An object address OADDR may be converted to a general address GADDR. In that case the object address is extended with an empty attribute address and the pair comprises the result.

REAL (LREAL) to INT conversion is performed after the rule: INT = entier( REAL + 0.5 ).

                            L         A    O    G    P    R
   to:  B    C         R    R    S    A    A    A    A    A
        O    H    I    E    E    I    D    D    D    D    D
        O    A    N    A    A    Z    D    D    D    D    D
 from:  L    R    T    L    L    E    R    R    R    R    R
 BOOL   .
 CHAR        .    +
 INT         ?    .    ?    ?
 REAL             ?    .    ?
 LREAL            ?    ?    .
 SIZE                            .
 AADDR                                .
 OADDR                                     .    +
 GADDR                                +    +    .
 PADDR                                               .
 RADDR                                                    .

                       Table of legal conversions


 	. - always a legal conversion, but a null operation

 	+ - always legal and exact

 	? - the legality depends on the actual value being converted.
 		Loss of accuracy is not considered an error when converting
 		from integer values to real values. In other cases execution
 		time checks may have to be inserted in order to avoid loss of
 		information due to truncation.

 	blank - always illegal.

Link to GitHub: Source File.

Author:
S-Port: Definition of S-code, Øystein Myhre Andersen
  • Field Details

    • fromType

      private final int fromType
      The fromType
    • toType

      private final int toType
      The toType
  • Constructor Details

    • SVM_CONVERT

      public SVM_CONVERT(int fromType, int toType)
      Construct a new SVM_CONVERT instruction
      Parameters:
      fromType - the fromType
      toType - the toType
  • Method Details

    • execute

      public void execute()
      Description copied from class: SVM_Instruction
      Execute this SVM instruction
      Overrides:
      execute in class SVM_Instruction
    • convValue

      private static Value convValue(Value fromValue, int fromtype, int totype)
      Convert a Value
      Parameters:
      fromValue - the Value to convert
      fromtype - the fromType
      totype - the toType
      Returns:
      the converted Value
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • write

      public void write(AttributeOutputStream oupt) throws IOException
      Description copied from class: SVM_Instruction
      Write this SVM instruction to the given output.
      Overrides:
      write in class SVM_Instruction
      Parameters:
      oupt - the output stream
      Throws:
      IOException - if IOException occur
    • read

      public static SVM_Instruction read(AttributeInputStream inpt) throws IOException
      Reads an SVM_CONVERT instruction from the given input.
      Parameters:
      inpt - the input stream
      Returns:
      the SVM_CONVERT instruction read
      Throws:
      IOException - if IOException occur