--- /dev/null
+/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-\r
+ *\r
+ * The contents of this file are subject to the Netscape Public\r
+ * License Version 1.1 (the "License"); you may not use this file\r
+ * except in compliance with the License. You may obtain a copy of\r
+ * the License at http://www.mozilla.org/NPL/\r
+ *\r
+ * Software distributed under the License is distributed on an "AS\r
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr\r
+ * implied. See the License for the specific language governing\r
+ * rights and limitations under the License.\r
+ *\r
+ * The Original Code is Rhino code, released\r
+ * May 6, 1999.\r
+ *\r
+ * The Initial Developer of the Original Code is Netscape\r
+ * Communications Corporation. Portions created by Netscape are\r
+ * Copyright (C) 1997-1999 Netscape Communications Corporation. All\r
+ * Rights Reserved.\r
+ *\r
+ * Contributor(s): \r
+ * Roger Lawrence\r
+ *\r
+ * Alternatively, the contents of this file may be used under the\r
+ * terms of the GNU Public License (the "GPL"), in which case the\r
+ * provisions of the GPL are applicable instead of those above.\r
+ * If you wish to allow use of your version of this file only\r
+ * under the terms of the GPL and not to allow others to use your\r
+ * version of this file under the NPL, indicate your decision by\r
+ * deleting the provisions above and replace them with the notice\r
+ * and other provisions required by the GPL. If you do not delete\r
+ * the provisions above, a recipient may use your version of this\r
+ * file under either the NPL or the GPL.\r
+ */\r
+\r
+package org.mozilla.javascript;\r
+\r
+public class Label {\r
+ \r
+ private static final int FIXUPTABLE_SIZE = 8;\r
+\r
+ private static final boolean DEBUG = true;\r
+\r
+ public Label()\r
+ {\r
+ itsPC = -1;\r
+ }\r
+\r
+ public short getPC()\r
+ {\r
+ return itsPC;\r
+ }\r
+ \r
+ public void fixGotos(byte theCodeBuffer[])\r
+ {\r
+ if (DEBUG) {\r
+ if ((itsPC == -1) && (itsFixupTable != null))\r
+ throw new RuntimeException("Unlocated label");\r
+ }\r
+ if (itsFixupTable != null) {\r
+ for (int i = 0; i < itsFixupTableTop; i++) {\r
+ int fixupSite = itsFixupTable[i];\r
+ // -1 to get delta from instruction start\r
+ short offset = (short)(itsPC - (fixupSite - 1));\r
+ theCodeBuffer[fixupSite++] = (byte)(offset >> 8);\r
+ theCodeBuffer[fixupSite] = (byte)offset;\r
+ }\r
+ }\r
+ itsFixupTable = null;\r
+ }\r
+\r
+ public void setPC(short thePC)\r
+ {\r
+ if (DEBUG) {\r
+ if ((itsPC != -1) && (itsPC != thePC)) {\r
+ throw new RuntimeException("Duplicate label");\r
+ }\r
+ }\r
+\r
+ itsPC = thePC;\r
+ }\r
+\r
+ public void addFixup(int fixupSite)\r
+ {\r
+ if (itsFixupTable == null) {\r
+ itsFixupTableTop = 1;\r
+ itsFixupTable = new int[FIXUPTABLE_SIZE];\r
+ itsFixupTable[0] = fixupSite; \r
+ }\r
+ else {\r
+ if (itsFixupTableTop == itsFixupTable.length) {\r
+ int oldLength = itsFixupTable.length;\r
+ int newTable[] = new int[oldLength + FIXUPTABLE_SIZE];\r
+ System.arraycopy(itsFixupTable, 0, newTable, 0, oldLength);\r
+ itsFixupTable = newTable;\r
+ }\r
+ itsFixupTable[itsFixupTableTop++] = fixupSite; \r
+ }\r
+ }\r
+\r
+ private short itsPC = -1;\r
+ private int itsFixupTable[];\r
+ private int itsFixupTableTop;\r
+\r
+}\r
+\r