fix: byte、short 运算后会变为 int 的问题

This commit is contained in:
zhangxun 2025-06-26 20:39:54 +08:00
parent c17ccc7540
commit c03761ed61
10 changed files with 12 additions and 12 deletions

View File

@ -50,7 +50,7 @@ public class BAddCommand implements Command {
byte a = (byte) operandStack.pop(); byte a = (byte) operandStack.pop();
// Perform the addition and push the result back onto the stack // Perform the addition and push the result back onto the stack
operandStack.push(a + b); operandStack.push((byte)(a + b));
// Return the updated program counter (next instruction) // Return the updated program counter (next instruction)
return currentPC + 1; return currentPC + 1;

View File

@ -56,7 +56,7 @@ public class BDivCommand implements Command {
} }
// Perform the division and push the result back onto the stack // Perform the division and push the result back onto the stack
operandStack.push(a / b); operandStack.push((byte)(a / b));
// Return the updated program counter (next instruction) // Return the updated program counter (next instruction)
return currentPC + 1; return currentPC + 1;

View File

@ -50,7 +50,7 @@ public class BModCommand implements Command {
byte a = (byte) operandStack.pop(); byte a = (byte) operandStack.pop();
// Perform the modulus operation and push the result back onto the stack // Perform the modulus operation and push the result back onto the stack
operandStack.push(a % b); operandStack.push((byte)(a % b));
// Return the updated program counter (next instruction) // Return the updated program counter (next instruction)
return currentPC + 1; return currentPC + 1;

View File

@ -50,7 +50,7 @@ public class BMulCommand implements Command {
byte a = (byte) operandStack.pop(); byte a = (byte) operandStack.pop();
// Perform the multiplication and push the result back onto the stack // Perform the multiplication and push the result back onto the stack
operandStack.push(a * b); operandStack.push((byte)(a * b));
// Return the updated program counter (next instruction) // Return the updated program counter (next instruction)
return currentPC + 1; return currentPC + 1;

View File

@ -50,7 +50,7 @@ public class BSubCommand implements Command {
byte a = (byte) operandStack.pop(); byte a = (byte) operandStack.pop();
// Perform the subtraction and push the result back onto the stack // Perform the subtraction and push the result back onto the stack
operandStack.push(a - b); operandStack.push((byte)(a - b));
// Return the updated program counter (next instruction) // Return the updated program counter (next instruction)
return currentPC + 1; return currentPC + 1;

View File

@ -46,11 +46,11 @@ public class SAddCommand implements Command {
@Override @Override
public int execute(String[] parts, int currentPC, OperandStack operandStack, LocalVariableStore localVariableStore, CallStack callStack) { public int execute(String[] parts, int currentPC, OperandStack operandStack, LocalVariableStore localVariableStore, CallStack callStack) {
// Pop the top two operands from the stack // Pop the top two operands from the stack
Short b = (Short) operandStack.pop(); short b = (short) operandStack.pop();
Short a = (Short) operandStack.pop(); short a = (short) operandStack.pop();
// Perform the addition and push the result back onto the stack // Perform the addition and push the result back onto the stack
operandStack.push(a + b); operandStack.push((short)(a + b));
// Return the updated program counter (next instruction) // Return the updated program counter (next instruction)
return currentPC + 1; return currentPC + 1;

View File

@ -56,7 +56,7 @@ public class SDivCommand implements Command {
} }
// Perform the division and push the result back onto the stack // Perform the division and push the result back onto the stack
operandStack.push(a / b); operandStack.push((short)(a / b));
// Return the updated program counter (next instruction) // Return the updated program counter (next instruction)
return currentPC + 1; return currentPC + 1;

View File

@ -50,7 +50,7 @@ public class SModCommand implements Command {
short a = (short) operandStack.pop(); short a = (short) operandStack.pop();
// Perform the modulus operation and push the result back onto the stack // Perform the modulus operation and push the result back onto the stack
operandStack.push(a % b); operandStack.push((short)(a % b));
// Return the updated program counter (next instruction) // Return the updated program counter (next instruction)
return currentPC + 1; return currentPC + 1;

View File

@ -50,7 +50,7 @@ public class SMulCommand implements Command {
short a = (short) operandStack.pop(); short a = (short) operandStack.pop();
// Perform the multiplication and push the result back onto the stack // Perform the multiplication and push the result back onto the stack
operandStack.push(a * b); operandStack.push((short)(a * b));
// Return the updated program counter (next instruction) // Return the updated program counter (next instruction)
return currentPC + 1; return currentPC + 1;

View File

@ -50,7 +50,7 @@ public class SSubCommand implements Command {
short a = (short) operandStack.pop(); short a = (short) operandStack.pop();
// Perform the subtraction and push the result back onto the stack // Perform the subtraction and push the result back onto the stack
operandStack.push(a - b); operandStack.push((short)(a - b));
// Return the updated program counter (next instruction) // Return the updated program counter (next instruction)
return currentPC + 1; return currentPC + 1;