From 4f0ad45ecad4b2901477350bfd38d7dad7c4aaa3 Mon Sep 17 00:00:00 2001 From: Luke Date: Sat, 28 Jun 2025 00:17:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20SnowVM=20=E6=94=AF=E6=8C=81=20B=5FOR?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vm/commands/bitwise/byte8/BOrCommand.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/main/java/org/jcnc/snow/vm/commands/bitwise/byte8/BOrCommand.java diff --git a/src/main/java/org/jcnc/snow/vm/commands/bitwise/byte8/BOrCommand.java b/src/main/java/org/jcnc/snow/vm/commands/bitwise/byte8/BOrCommand.java new file mode 100644 index 0000000..4902ae7 --- /dev/null +++ b/src/main/java/org/jcnc/snow/vm/commands/bitwise/byte8/BOrCommand.java @@ -0,0 +1,56 @@ +package org.jcnc.snow.vm.commands.bitwise.byte8; + +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; + +/** + * The {@code BOrCommand} class implements the {@link Command} interface and represents the byte8 bitwise OR (`|`) operation command. + * This class performs a byte8 bitwise OR operation in the virtual machine by popping the top two values from the stack, + * computing their OR, and then pushing the result back onto the stack. It is a basic operation command within the virtual machine. + * + *

Operation details:

+ * + */ +public class BOrCommand implements Command { + /** + * Default constructor for creating an instance of {@code BOrCommand}. + * This constructor is empty as no specific initialization is required. + */ + public BOrCommand() { + // Empty constructor + } + + /** + * Executes the virtual machine instruction's operation. + * + * @param parts The array of instruction parameters, which usually includes the operator and related arguments. + * @param currentPC The current program counter-value, indicating the address of the instruction being executed. + * @param operandStack The virtual machine's operand stack manager, responsible for performing stack operations. + * @param localVariableStore The local variable store, typically used to manage method-local variables. + * @param callStack The virtual machine's call stack, which keeps track of method invocations. + * @return The updated program counter-value, typically {@code currentPC + 1}, unless a control flow instruction is executed. + * @throws IllegalStateException if there are not enough operands on the stack to perform the operation. + */ + @Override + public int execute(String[] parts, int currentPC, OperandStack operandStack, LocalVariableStore localVariableStore, CallStack callStack) { + // Ensure the stack has at least two operands + if (operandStack.size() < 2) { + throw new IllegalStateException("Not enough operands on the stack for BOR operation."); + } + + // Pop the top two operands from the stack + final byte b = (byte) operandStack.pop(); + final byte a = (byte) operandStack.pop(); + + // Perform the byte8 bitwise OR operation and push the result back onto the stack + operandStack.push(a | b); + + return currentPC + 1; + } +} \ No newline at end of file