func (frame *Frame) executeComparison(op comparisonOp) { stack := frame.OperandStack() v2 := stack.Pop() v1 := stack.Pop() result := false switch op { case if_icmpeq: result = v1 == v2 case if_icmpne: result = v1 != v2 // more cases... } if result { frame.NextPC = frame.Thread().PC() + op.offset } }
func (frame *Frame) InvokeMethod(method *heap.Method) { // Create new frame and push onto stack newFrame := newFrame(frame.thread, method) frame.thread.PushFrame(newFrame) // Copy arguments from current frame to new frame params := method.GetParameterTypes() argSlotCount := len(params) stack := frame.OperandStack() newStack := newFrame.OperandStack() for i := argSlotCount - 1; i >= 0; i-- { arg := stack.Pop() newStack.Push(arg, params[i]) } }This example shows a method invocation that creates a new frame and pushes it onto the stack. It utilizes the Frame type to access the thread and operand stack, and the OperandStack type to copy arguments from the old frame's stack to the new frame's stack. Overall, the github.com/zxh0/jvm.go/jvmgo/rtda package provides useful types and functions for implementing a JVM stack and executing method invocations.