Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 4.34 KB | None | 0 0
  1. /*
  2.  * Created on 10 nov 2009
  3.  */
  4.  
  5. package interpreter.api;
  6.  
  7. import java.io.PrintStream;
  8.  
  9. public class ExecutionFrame
  10. {
  11.    public final ExecutionThread thread;
  12.    public BytecodeMethod        method;
  13.    public final String[]        instructions;
  14.  
  15.    public ExecutionFrame(BytecodeMethod method, ExecutionThread thread, int stacksize)
  16.    {
  17.       this(method, thread, new String[0], 0, stacksize);
  18.    }
  19.  
  20.    public ExecutionFrame(BytecodeMethod method, ExecutionThread thread, String[] instructions, int localCount, int stackSize)
  21.    {
  22.       this.method = method;
  23.       this.thread = thread;
  24.       this.instructions = instructions;
  25.  
  26.       this.thread.pushFrame(this);
  27.  
  28.       this.iStack = new int[stackSize];
  29.       this.iLocal = new int[localCount];
  30.    }
  31.  
  32.    //
  33.  
  34.    public void print(PrintStream out, String name)
  35.    {
  36.       out.println("----frame[" + name + "]---");
  37.       for (int i = 0; i < this.pStack; i++)
  38.          out.println(" stack[" + i + "]=" + this.iStack[i]);
  39.       for (int i = 0; i < this.iLocal.length; i++)
  40.          out.println(" local[" + i + "]=" + this.iLocal[i]);
  41.       out.println("----");
  42.    }
  43.  
  44.    public int instructionPointer;
  45.  
  46.    public final void $goto(int offset)
  47.    {
  48.       this.instructionPointer = offset;
  49.    }
  50.  
  51.    //
  52.  
  53.    private final int[] iStack;
  54.    private final int[] iLocal;
  55.    private int         pStack;
  56.  
  57.    public int stackSize()
  58.    {
  59.       return this.pStack;
  60.    }
  61.  
  62.    //
  63.  
  64.    public void pushInt(int val)
  65.    {
  66.       this.iStack[this.pStack++] = val;
  67.    }
  68.  
  69.    public int popInt()
  70.    {
  71.       return this.iStack[--this.pStack];
  72.    }
  73.  
  74.    //
  75.  
  76.    public void pushLong(long val)
  77.    {
  78.       int lo = (int) ((val >> 0 * 32) & 0xFFFFFFFFL);
  79.       int hi = (int) ((val >> 1 * 32) & 0xFFFFFFFFL);
  80.       this.pushInt(lo);
  81.       this.pushInt(hi);
  82.    }
  83.  
  84.    public long popLong()
  85.    {
  86.       int lo = this.popInt();
  87.       int hi = this.popInt();
  88.       return (((long) hi) << 32) | lo;
  89.    }
  90.  
  91.    //
  92.  
  93.    public void pushFloat(float val)
  94.    {
  95.       this.pushInt(Float.floatToRawIntBits(val));
  96.    }
  97.  
  98.    public float popFloat()
  99.    {
  100.       return Float.intBitsToFloat(this.popInt());
  101.    }
  102.  
  103.    //
  104.  
  105.    public void pushDouble(double val)
  106.    {
  107.       this.pushLong(Double.doubleToRawLongBits(val));
  108.    }
  109.  
  110.    public double popDouble()
  111.    {
  112.       return Double.longBitsToDouble(this.popLong());
  113.    }
  114.  
  115.    //
  116.  
  117.    public void pushReference(int pntr)
  118.    {
  119.       this.pushInt(pntr);
  120.    }
  121.  
  122.    public int popReference()
  123.    {
  124.       return this.popInt();
  125.    }
  126.  
  127.    // LOCAL
  128.  
  129.    public void storeInt(int offset, int val)
  130.    {
  131.       this.iLocal[offset] = val;
  132.    }
  133.  
  134.    public int loadInt(int offset)
  135.    {
  136.       return this.iLocal[offset];
  137.    }
  138.  
  139.    //
  140.  
  141.    public void storeLong(int offset, long val)
  142.    {
  143.       if ((offset & 1) != 0)
  144.          throw new IllegalStateException("misaligned long");
  145.       int lo = (int) ((val >> 0 * 32) & 0xFFFFFFFFL);
  146.       int hi = (int) ((val >> 1 * 32) & 0xFFFFFFFFL);
  147.       this.storeInt(offset + 0, lo);
  148.       this.storeInt(offset + 1, hi);
  149.    }
  150.  
  151.    public long loadLong(int offset)
  152.    {
  153.       if ((offset & 1) != 0)
  154.          throw new IllegalStateException("misaligned long");
  155.       int lo = this.loadInt(offset + 0);
  156.       int hi = this.loadInt(offset + 1);
  157.       return (((long) hi) << 32L) | lo;
  158.    }
  159.  
  160.    //
  161.  
  162.    public void storeFloat(int offset, float val)
  163.    {
  164.       this.storeInt(offset, Float.floatToRawIntBits(val));
  165.    }
  166.  
  167.    public float loadFloat(int offset)
  168.    {
  169.       return Float.intBitsToFloat(this.loadInt(offset));
  170.    }
  171.  
  172.    //
  173.  
  174.    public void storeDouble(int offset, double val)
  175.    {
  176.       if ((offset & 1) != 0)
  177.          throw new IllegalStateException("misaligned double");
  178.       this.storeLong(offset, Double.doubleToRawLongBits(val));
  179.    }
  180.  
  181.    public double loadDouble(int offset)
  182.    {
  183.       if ((offset & 1) != 0)
  184.          throw new IllegalStateException("misaligned double");
  185.       return Double.longBitsToDouble(this.loadLong(offset));
  186.    }
  187.  
  188.    //
  189.  
  190.    public void storeReference(int offset, int val)
  191.    {
  192.       this.storeInt(offset, val);
  193.    }
  194.  
  195.    public int loadReference(int offset)
  196.    {
  197.       return this.loadInt(offset);
  198.    }
  199.  
  200.    //
  201.  
  202.    public String toString()
  203.    {
  204.       if (this.method == null)
  205.          return "custom-frame";
  206.       return this.method.toIdentifier();
  207.    }
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement