Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Created on 10 nov 2009
- */
- package interpreter.api;
- import java.io.PrintStream;
- public class ExecutionFrame
- {
- public final ExecutionThread thread;
- public BytecodeMethod method;
- public final String[] instructions;
- public ExecutionFrame(BytecodeMethod method, ExecutionThread thread, int stacksize)
- {
- this(method, thread, new String[0], 0, stacksize);
- }
- public ExecutionFrame(BytecodeMethod method, ExecutionThread thread, String[] instructions, int localCount, int stackSize)
- {
- this.method = method;
- this.thread = thread;
- this.instructions = instructions;
- this.thread.pushFrame(this);
- this.iStack = new int[stackSize];
- this.iLocal = new int[localCount];
- }
- //
- public void print(PrintStream out, String name)
- {
- out.println("----frame[" + name + "]---");
- for (int i = 0; i < this.pStack; i++)
- out.println(" stack[" + i + "]=" + this.iStack[i]);
- for (int i = 0; i < this.iLocal.length; i++)
- out.println(" local[" + i + "]=" + this.iLocal[i]);
- out.println("----");
- }
- public int instructionPointer;
- public final void $goto(int offset)
- {
- this.instructionPointer = offset;
- }
- //
- private final int[] iStack;
- private final int[] iLocal;
- private int pStack;
- public int stackSize()
- {
- return this.pStack;
- }
- //
- public void pushInt(int val)
- {
- this.iStack[this.pStack++] = val;
- }
- public int popInt()
- {
- return this.iStack[--this.pStack];
- }
- //
- public void pushLong(long val)
- {
- int lo = (int) ((val >> 0 * 32) & 0xFFFFFFFFL);
- int hi = (int) ((val >> 1 * 32) & 0xFFFFFFFFL);
- this.pushInt(lo);
- this.pushInt(hi);
- }
- public long popLong()
- {
- int lo = this.popInt();
- int hi = this.popInt();
- return (((long) hi) << 32) | lo;
- }
- //
- public void pushFloat(float val)
- {
- this.pushInt(Float.floatToRawIntBits(val));
- }
- public float popFloat()
- {
- return Float.intBitsToFloat(this.popInt());
- }
- //
- public void pushDouble(double val)
- {
- this.pushLong(Double.doubleToRawLongBits(val));
- }
- public double popDouble()
- {
- return Double.longBitsToDouble(this.popLong());
- }
- //
- public void pushReference(int pntr)
- {
- this.pushInt(pntr);
- }
- public int popReference()
- {
- return this.popInt();
- }
- // LOCAL
- public void storeInt(int offset, int val)
- {
- this.iLocal[offset] = val;
- }
- public int loadInt(int offset)
- {
- return this.iLocal[offset];
- }
- //
- public void storeLong(int offset, long val)
- {
- if ((offset & 1) != 0)
- throw new IllegalStateException("misaligned long");
- int lo = (int) ((val >> 0 * 32) & 0xFFFFFFFFL);
- int hi = (int) ((val >> 1 * 32) & 0xFFFFFFFFL);
- this.storeInt(offset + 0, lo);
- this.storeInt(offset + 1, hi);
- }
- public long loadLong(int offset)
- {
- if ((offset & 1) != 0)
- throw new IllegalStateException("misaligned long");
- int lo = this.loadInt(offset + 0);
- int hi = this.loadInt(offset + 1);
- return (((long) hi) << 32L) | lo;
- }
- //
- public void storeFloat(int offset, float val)
- {
- this.storeInt(offset, Float.floatToRawIntBits(val));
- }
- public float loadFloat(int offset)
- {
- return Float.intBitsToFloat(this.loadInt(offset));
- }
- //
- public void storeDouble(int offset, double val)
- {
- if ((offset & 1) != 0)
- throw new IllegalStateException("misaligned double");
- this.storeLong(offset, Double.doubleToRawLongBits(val));
- }
- public double loadDouble(int offset)
- {
- if ((offset & 1) != 0)
- throw new IllegalStateException("misaligned double");
- return Double.longBitsToDouble(this.loadLong(offset));
- }
- //
- public void storeReference(int offset, int val)
- {
- this.storeInt(offset, val);
- }
- public int loadReference(int offset)
- {
- return this.loadInt(offset);
- }
- //
- public String toString()
- {
- if (this.method == null)
- return "custom-frame";
- return this.method.toIdentifier();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement