package net.runelite.asm.attributes.code.instructions;

import net.runelite.asm.attributes.code.Instruction;
import net.runelite.asm.attributes.code.InstructionType;
import net.runelite.asm.attributes.code.Instructions;
import net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction;
import net.runelite.asm.execution.Frame;
import net.runelite.asm.execution.InstructionContext;
import net.runelite.asm.execution.Stack;
import net.runelite.asm.execution.StackContext;
import net.runelite.asm.pool.PoolEntry;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.runelite.asm.execution.Value;

public class SiPush extends Instruction implements PushConstantInstruction
{
	private short s;

	public SiPush(Instructions instructions, InstructionType type, int pc)
	{
		super(instructions, type, pc);
	}
	
	public SiPush(Instructions instructions, short value)
	{
		super(instructions, InstructionType.SIPUSH, -1);
		s = value;
	}
	
	@Override
	public void load(DataInputStream is) throws IOException
	{
		s = is.readShort();
		length += 2;
	}
	
	@Override
	public void write(DataOutputStream out) throws IOException
	{
		super.write(out);
		out.writeShort(s);
	}

	@Override
	public void execute(Frame frame)
	{
		InstructionContext ins = new InstructionContext(this, frame);
		Stack stack = frame.getStack();
		
		StackContext ctx = new StackContext(ins, int.class, new Value((int) s)); // sign extend
		stack.push(ctx);
		
		ins.push(ctx);
		
		frame.addInstructionContext(ins);
	}

	@Override
	public PoolEntry getConstant()
	{
		return new net.runelite.asm.pool.Integer(s);
	}

	@Override
	public Instruction setConstant(PoolEntry entry)
	{
		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
	}
}

@@ -974,16 +974,17 @@
 H, -1);%0A
+%0A
 %09%09s = va
@@ -988,16 +988,31 @@
  value;%0A
+%09%09length += 2;%0A
 %09%7D%0A%09%0A%09@O

Fix sipush length