From b30b6aeaaa166414839063f2b26503c22dd44466 Mon Sep 17 00:00:00 2001 From: Luke Date: Mon, 21 Jul 2025 17:26:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=BC=95=E7=94=A8?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E6=8E=A7=E5=88=B6=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 R_PUSH、R_LOAD 和 R_STORE 指令,用于处理对象引用类型 - 这些指令分别用于推送、加载和存储对象引用到操作栈或本地变量表 --- .../org/jcnc/snow/vm/engine/VMOpCode.java | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java b/src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java index 8e1a880..c333e34 100644 --- a/src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java +++ b/src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java @@ -1,5 +1,8 @@ package org.jcnc.snow.vm.engine; +import org.jcnc.snow.vm.commands.ref.control.RLoadCommand; +import org.jcnc.snow.vm.commands.ref.control.RPushCommand; +import org.jcnc.snow.vm.commands.ref.control.RStoreCommand; import org.jcnc.snow.vm.commands.system.control.SyscallCommand; import org.jcnc.snow.vm.commands.type.control.byte8.*; import org.jcnc.snow.vm.commands.type.control.double64.*; @@ -2483,6 +2486,74 @@ public class VMOpCode { // endregion Double64 // endregion Conversion + // region Reference Control (0x00E0-0x00EF) + /** + * R_PUSH Opcode: Represents an operation that pushes an object reference (such as a String or any reference type) + * onto the operand stack. + *

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

+ * + *

Execution Steps:

+ *
    + *
  1. Parses the object reference literal (e.g., a string) from the instruction parameters.
  2. + *
  3. Creates or interprets the reference as an object instance if necessary.
  4. + *
  5. Pushes the reference object onto the operand stack.
  6. + *
  7. Increments the program counter (PC) to proceed with the next sequential instruction.
  8. + *
+ * + *

This opcode is commonly used for:

+ * + */ + public static final int R_PUSH = 0x00E0; + /** + * R_LOAD Opcode: Represents an operation that loads an object reference from the local variable table + * and pushes it onto the operand stack. + *

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

+ * + *

Execution Steps:

+ *
    + *
  1. Parses the target slot index from the instruction parameters.
  2. + *
  3. Retrieves the reference object stored at the specified slot in the local variable table + * of the current stack frame.
  4. + *
  5. Pushes the retrieved reference onto the operand stack.
  6. + *
  7. Increments the program counter (PC) to proceed with the next sequential instruction.
  8. + *
+ * + *

This opcode is commonly used for:

+ * + */ + public static final int R_LOAD = 0x00E1; + /** + * R_STORE Opcode: Represents an operation that pops an object reference from the top of the operand stack + * and stores it into the local variable table at the specified slot index. + *

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

+ * + *

Execution Steps:

+ *
    + *
  1. Parses the target slot index from the instruction parameters.
  2. + *
  3. Pops the top reference object from the operand stack.
  4. + *
  5. Stores the popped reference object into the specified slot in the local variable table + * of the current stack frame.
  6. + *
  7. Increments the program counter (PC) to proceed with the next sequential instruction.
  8. + *
+ * + *

This opcode is commonly used for:

+ * + */ + public static final int R_STORE = 0x00E2; + // endregion + // region Stack Control (0x0100-0x01FF) /** * POP Opcode: Represents a stack operation that removes the top element from the operand stack.