diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/B2DCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/B2DCommand.java new file mode 100644 index 0000000..1ca0655 --- /dev/null +++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/B2DCommand.java @@ -0,0 +1,47 @@ +package org.jcnc.snow.vm.commands.type.conversion; + +import org.jcnc.snow.vm.interfaces.Command; +import org.jcnc.snow.vm.module.CallStack; +import org.jcnc.snow.vm.module.LocalVariableStore; +import org.jcnc.snow.vm.module.OperandStack; + +/** + * B2DCommand Opcode: Represents the type conversion operation from byte8 to double64 in the virtual machine. + *

This opcode is implemented by the {@link B2DCommand} class, which defines its specific execution logic.

+ * + *

Execution Steps:

+ *
    + *
  1. Pop the top byte8 value from the operand stack.
  2. + *
  3. Convert the byte8 value to a double64 value.
  4. + *
  5. Push the converted double64 value back onto the operand stack for subsequent operations.
  6. + *
+ * + *

This opcode is used to widen a byte8 value to a double64 type to ensure compatibility with integer-based operations.

+ */ +public class B2DCommand implements Command { + + /** + * Default constructor for creating an instance of B2DCommand. + */ + public B2DCommand() { + // Empty constructor + } + + /** + * Executes the byte8 to double64 conversion operation. + * + * @param parts The array of instruction parameters, which is not used in this operation. + * @param currentPC The current program counter, representing the instruction address. + * @param operandStack The operand stack of the virtual machine. + * @param localVariableStore The local variable store for managing method-local variables. + * @param callStack The call stack of the virtual machine. + * @return The updated program counter after execution. + */ + @Override + public int execute(String[] parts, int currentPC, OperandStack operandStack, + LocalVariableStore localVariableStore, CallStack callStack) { + double convertedValue = (byte) operandStack.pop(); + operandStack.push(convertedValue); + return currentPC + 1; + } +} diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/B2FCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/B2FCommand.java new file mode 100644 index 0000000..c61891b --- /dev/null +++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/B2FCommand.java @@ -0,0 +1,47 @@ +package org.jcnc.snow.vm.commands.type.conversion; + +import org.jcnc.snow.vm.interfaces.Command; +import org.jcnc.snow.vm.module.CallStack; +import org.jcnc.snow.vm.module.LocalVariableStore; +import org.jcnc.snow.vm.module.OperandStack; + +/** + * B2FCommand Opcode: Represents the type conversion operation from byte8 to float32 in the virtual machine. + *

This opcode is implemented by the {@link B2FCommand} class, which defines its specific execution logic.

+ * + *

Execution Steps:

+ *
    + *
  1. Pop the top byte8 value from the operand stack.
  2. + *
  3. Convert the byte8 value to a float32 value.
  4. + *
  5. Push the converted float32 value back onto the operand stack for subsequent operations.
  6. + *
+ * + *

This opcode is used to widen a byte8 value to a float32 type to ensure compatibility with integer-based operations.

+ */ +public class B2FCommand implements Command { + + /** + * Default constructor for creating an instance of B2FCommand. + */ + public B2FCommand() { + // Empty constructor + } + + /** + * Executes the byte8 to float32 conversion operation. + * + * @param parts The array of instruction parameters, which is not used in this operation. + * @param currentPC The current program counter, representing the instruction address. + * @param operandStack The operand stack of the virtual machine. + * @param localVariableStore The local variable store for managing method-local variables. + * @param callStack The call stack of the virtual machine. + * @return The updated program counter after execution. + */ + @Override + public int execute(String[] parts, int currentPC, OperandStack operandStack, + LocalVariableStore localVariableStore, CallStack callStack) { + float convertedValue = (byte) operandStack.pop(); + operandStack.push(convertedValue); + return currentPC + 1; + } +} diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/B2LCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/B2LCommand.java new file mode 100644 index 0000000..344b49d --- /dev/null +++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/B2LCommand.java @@ -0,0 +1,47 @@ +package org.jcnc.snow.vm.commands.type.conversion; + +import org.jcnc.snow.vm.interfaces.Command; +import org.jcnc.snow.vm.module.CallStack; +import org.jcnc.snow.vm.module.LocalVariableStore; +import org.jcnc.snow.vm.module.OperandStack; + +/** + * B2LCommand Opcode: Represents the type conversion operation from byte8 to long64 in the virtual machine. + *

This opcode is implemented by the {@link B2LCommand} class, which defines its specific execution logic.

+ * + *

Execution Steps:

+ *
    + *
  1. Pop the top byte8 value from the operand stack.
  2. + *
  3. Convert the byte8 value to a long64 value.
  4. + *
  5. Push the converted long64 value back onto the operand stack for subsequent operations.
  6. + *
+ * + *

This opcode is used to widen a byte8 value to a long64 type to ensure compatibility with integer-based operations.

+ */ +public class B2LCommand implements Command { + + /** + * Default constructor for creating an instance of B2LCommand. + */ + public B2LCommand() { + // Empty constructor + } + + /** + * Executes the byte8 to long64 conversion operation. + * + * @param parts The array of instruction parameters, which is not used in this operation. + * @param currentPC The current program counter, representing the instruction address. + * @param operandStack The operand stack of the virtual machine. + * @param localVariableStore The local variable store for managing method-local variables. + * @param callStack The call stack of the virtual machine. + * @return The updated program counter after execution. + */ + @Override + public int execute(String[] parts, int currentPC, OperandStack operandStack, + LocalVariableStore localVariableStore, CallStack callStack) { + long convertedValue = (byte) operandStack.pop(); + operandStack.push(convertedValue); + return currentPC + 1; + } +} diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/B2SCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/B2SCommand.java new file mode 100644 index 0000000..1f09ff9 --- /dev/null +++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/B2SCommand.java @@ -0,0 +1,47 @@ +package org.jcnc.snow.vm.commands.type.conversion; + +import org.jcnc.snow.vm.interfaces.Command; +import org.jcnc.snow.vm.module.CallStack; +import org.jcnc.snow.vm.module.LocalVariableStore; +import org.jcnc.snow.vm.module.OperandStack; + +/** + * B2SCommand Opcode: Represents the type conversion operation from byte8 to short16 in the virtual machine. + *

This opcode is implemented by the {@link B2SCommand} class, which defines its specific execution logic.

+ * + *

Execution Steps:

+ *
    + *
  1. Pop the top byte8 value from the operand stack.
  2. + *
  3. Convert the byte8 value to a short16 value.
  4. + *
  5. Push the converted short16 value back onto the operand stack for subsequent operations.
  6. + *
+ * + *

This opcode is used to widen a byte8 value to a short16 type to ensure compatibility with integer-based operations.

+ */ +public class B2SCommand implements Command { + + /** + * Default constructor for creating an instance of B2SCommand. + */ + public B2SCommand() { + // Empty constructor + } + + /** + * Executes the byte8 to short16 conversion operation. + * + * @param parts The array of instruction parameters, which is not used in this operation. + * @param currentPC The current program counter, representing the instruction address. + * @param operandStack The operand stack of the virtual machine. + * @param localVariableStore The local variable store for managing method-local variables. + * @param callStack The call stack of the virtual machine. + * @return The updated program counter after execution. + */ + @Override + public int execute(String[] parts, int currentPC, OperandStack operandStack, + LocalVariableStore localVariableStore, CallStack callStack) { + short convertedValue = (byte) operandStack.pop(); + operandStack.push(convertedValue); + return currentPC + 1; + } +}