// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) space 
// Source File Name:   CodeArray.java

package lt.monarch.jasm;

import java.io.DataOutputStream;
import java.io.IOException;

public class CodeArray
{

    public void append(int i)
    {
        if (size >= code.length)
        {
            byte abyte0[] = new byte[size + 20];
            System.arraycopy(code, 0, abyte0, 0, size);
            code = abyte0;
        }
        code[size++] = (byte)(i & 0xff);
    }

    public void appendInt(int i)
    {
        append(i >> 8);
        append(i & 0xff);
    }

    public void reserveStack(int i)
    {
        currentStackLoad += i;
        if (currentStackLoad > maxStack)
            maxStack = currentStackLoad;
    }

    public void reserveLocal(int i)
    {
        currentLocalLoad += i;
        if (currentLocalLoad > maxLocals)
            maxLocals = currentLocalLoad;
    }

    public void reserveArguments(int i)
    {
        currentArguments += i;
    }

    public void freeStack(int i)
    {
        currentStackLoad -= i;
    }

    public void freeLocal(int i)
    {
        currentLocalLoad -= i;
    }

    public void removeArguments(int i)
    {
        currentArguments -= i;
    }

    public void resetArguments()
    {
        currentArguments = 0;
    }

    void writeTo(DataOutputStream dataoutputstream)
        throws IOException
    {
        dataoutputstream.writeInt(size + 12);
        dataoutputstream.writeShort(maxStack);
        dataoutputstream.writeShort(maxLocals + currentArguments);
        dataoutputstream.writeInt(size);
        dataoutputstream.write(code, 0, size);
        dataoutputstream.writeShort(0);
        dataoutputstream.writeShort(0);
    }

    public CodeArray()
    {
        maxStack = 0;
        maxLocals = 0;
        currentStackLoad = 0;
        currentLocalLoad = 0;
        currentArguments = 0;
        code = new byte[20];
        size = 0;
    }

    final int growth = 20;
    byte code[];
    int size;
    int maxStack;
    int maxLocals;
    int currentStackLoad;
    int currentLocalLoad;
    int currentArguments;
}
