2003/11/03 06:32:54
[org.ibex.core.git] / src / org / xwt / js / CompiledFunctionImpl.java
1 // Copyright 2003 Adam Megacz, see the COPYING file for licensing [GPL]
2 package org.xwt.js;
3
4 import org.xwt.util.*;
5 import java.io.*;
6
7 /** a JavaScript function, compiled into bytecode */
8 class CompiledFunctionImpl extends JS.Obj implements ByteCodes, Tokens {
9
10     // Fields and Accessors ///////////////////////////////////////////////
11
12     /** the number of formal arguments */
13     int numFormalArgs = 20;
14
15     /** the source code file that this block was drawn from */
16      String sourceName;
17     public String getSourceName() throws JS.Exn { return sourceName; }
18     
19     /** the line numbers */
20      int[] line = new int[10];
21
22     /** the first line of this script */
23     private int firstLine = -1;
24
25     /** the instructions */
26      int[] op = new int[10];
27
28     /** the arguments to the instructions */
29      Object[] arg = new Object[10];
30
31     /** the number of instruction/argument pairs */
32      int size = 0;
33     int size() { return size; }
34
35     /** the scope in which this function was declared; by default this function is called in a fresh subscope of the parentScope */
36     JS.Scope parentScope;
37
38     // Constructors ////////////////////////////////////////////////////////
39
40     private CompiledFunctionImpl cloneWithNewParentScope(JS.Scope s) throws IOException {
41         CompiledFunctionImpl ret = new JS.CompiledFunction(sourceName, firstLine, null, s);
42         // Reuse the same op, arg, line, and size variables for the new "instance" of the function
43         // NOTE: Neither *this* function nor the new function should be modified after this call
44         ret.op = this.op;
45         ret.arg = this.arg;
46         ret.line = this.line;
47         ret.size = this.size;
48         ret.numFormalArgs = this.numFormalArgs;
49         return ret;
50     }
51
52     protected CompiledFunctionImpl(String sourceName, int firstLine, Reader sourceCode, JS.Scope parentScope) throws IOException {
53         this.sourceName = sourceName;
54         this.firstLine = firstLine;
55         this.parentScope = parentScope;
56         if (sourceCode == null) return;
57         Parser p = new Parser(sourceCode, sourceName, firstLine);
58         while(true) {
59             int s = size();
60             p.parseStatement(this, null);
61             if (s == size()) break;
62         }
63         add(-1, LITERAL, null); 
64         add(-1, RETURN);
65     }
66     
67
68
69     // Adding and Altering Bytecodes ///////////////////////////////////////////////////
70
71     int get(int pos) { return op[pos]; }
72     Object getArg(int pos) { return arg[pos]; }
73     void set(int pos, int op_, Object arg_) { op[pos] = op_; arg[pos] = arg_; }
74     void set(int pos, Object arg_) { arg[pos] = arg_; }
75     int pop() { size--; arg[size] = null; return op[size]; }
76     void paste(CompiledFunctionImpl other) { for(int i=0; i<other.size; i++) add(other.line[i], other.op[i], other.arg[i]); }
77     CompiledFunctionImpl add(int line, int op_) { return add(line, op_, null); }
78     CompiledFunctionImpl add(int line, int op_, Object arg_) {
79         if (size == op.length - 1) {
80             int[] line2 = new int[op.length * 2]; System.arraycopy(this.line, 0, line2, 0, op.length); this.line = line2;
81             Object[] arg2 = new Object[op.length * 2]; System.arraycopy(arg, 0, arg2, 0, arg.length); arg = arg2;
82             int[] op2 = new int[op.length * 2]; System.arraycopy(op, 0, op2, 0, op.length); op = op2;
83         }
84         this.line[size] = line;
85         op[size] = op_;
86         arg[size] = arg_;
87         size++;
88         return this;
89     }
90     
91     public static int getLine(Context cx) {
92         if(cx.pc < 0 || cx.pc >= ((CompiledFunctionImpl)cx.f).size) return -1;
93         return ((CompiledFunctionImpl)cx.f).line[cx.pc];
94     }
95
96
97     // Invoking the Bytecode ///////////////////////////////////////////////////////
98
99     /** returns false if the thread has been paused */
100     static Object eval(final Context cx, Object pushFirst) throws JS.Exn {
101         cx.stack.push(pushFirst);
102         OUTER: for(;; cx.pc++) {
103         try {
104             if (cx.f == null) return cx.stack.pop();
105             if (cx.pc >= ((CompiledFunctionImpl)cx.f).size) return cx.stack.pop();
106             String label = null;
107             int curOP = cx.f.op[cx.pc];
108             Object curArg = cx.f.arg[cx.pc];
109             Object returnedFromJava = null;
110             boolean checkReturnedFromJava = false;
111             if(curOP == FINALLY_DONE) {
112                 FinallyData fd = (FinallyData) cx.stack.pop();
113                 if(fd == null) continue OUTER; // NOP
114                 curOP = fd.op;
115                 curArg = fd.arg;
116             }
117             switch(curOP) {
118             case LITERAL: cx.stack.push(curArg); break;
119             case OBJECT: cx.stack.push(new JS.Obj()); break;
120             case ARRAY: cx.stack.push(new JS.Array(JS.toNumber(curArg).intValue())); break;
121             case DECLARE: cx.scope.declare((String)(curArg==null ? cx.stack.peek() : curArg)); if(curArg != null) cx.stack.push(curArg); break;
122             case TOPSCOPE: cx.stack.push(cx.scope); break;
123             case JT: if (JS.toBoolean(cx.stack.pop())) cx.pc += JS.toNumber(curArg).intValue() - 1; break;
124             case JF: if (!JS.toBoolean(cx.stack.pop())) cx.pc += JS.toNumber(curArg).intValue() - 1; break;
125             case JMP: cx.pc += JS.toNumber(curArg).intValue() - 1; break;
126             case POP: cx.stack.pop(); break;
127             case SWAP: { Object o1 = cx.stack.pop(); Object o2 = cx.stack.pop(); cx.stack.push(o1); cx.stack.push(o2); break; }
128             case DUP: cx.stack.push(cx.stack.peek()); break;
129             case NEWSCOPE: cx.scope = new JS.Scope(cx.scope); break;
130             case OLDSCOPE: cx.scope = cx.scope.getParentScope(); break;
131             case ASSERT: if (!JS.toBoolean(cx.stack.pop())) throw je("assertion failed"); break;
132             case BITNOT: cx.stack.push(new Long(~JS.toLong(cx.stack.pop()))); break;
133             case BANG: cx.stack.push(new Boolean(!JS.toBoolean(cx.stack.pop()))); break;
134
135             case TYPEOF: {
136                 Object o = cx.stack.pop();
137                 if (o == null) cx.stack.push(null);
138                 else if (o instanceof JS) cx.stack.push(((JS)o).typeName());
139                 else if (o instanceof String) cx.stack.push("string");
140                 else if (o instanceof Number) cx.stack.push("number");
141                 else if (o instanceof Boolean) cx.stack.push("boolean");
142                 else cx.stack.push("unknown");
143                 break;
144             }
145
146             case NEWFUNCTION: {
147                 try {
148                     cx.stack.push(((CompiledFunctionImpl)curArg).cloneWithNewParentScope(cx.scope));
149                 } catch (IOException e) {
150                     throw new Error("this should never happen");
151                 }
152                 break;
153             }
154
155             case PUSHKEYS: {
156                 Object o = cx.stack.peek();
157                 Object[] keys = ((JS)o).keys();
158                 JS.Array a = new JS.Array();
159                 a.setSize(keys.length);
160                 for(int j=0; j<keys.length; j++) a.setElementAt(keys[j], j);
161                 cx.stack.push(a);
162                 break;
163             }
164
165             case LABEL: break;
166             case LOOP: {
167                 cx.stack.push(new LoopMarker(cx.pc, cx.pc > 0 && cx.f.op[cx.pc - 1] == LABEL ? (String)cx.f.arg[cx.pc - 1] : (String)null, cx.scope));
168                 cx.stack.push(Boolean.TRUE);
169                 break;
170             }
171
172             case BREAK:
173             case CONTINUE:
174                 while(cx.stack.size() > 0) {
175                     Object o = cx.stack.pop();
176                     if (o instanceof CallMarker) ee("break or continue not within a loop");
177                     if (o instanceof TryMarker) {
178                         if(((TryMarker)o).finallyLoc < 0) continue; // no finally block, keep going
179                         cx.stack.push(new FinallyData(curOP, curArg));
180                         cx.scope = ((TryMarker)o).scope;
181                         cx.pc = ((TryMarker)o).finallyLoc - 1;
182                         continue OUTER;
183                     }
184                     if (o instanceof LoopMarker) {
185                         if (curArg == null || curArg.equals(((LoopMarker)o).label)) {
186                             int loopInstructionLocation = ((LoopMarker)o).location;
187                             int endOfLoop = ((Integer)cx.f.arg[loopInstructionLocation]).intValue() + loopInstructionLocation;
188                             cx.scope = ((LoopMarker)o).scope;
189                             if (curOP == CONTINUE) { cx.stack.push(o); cx.stack.push(Boolean.FALSE); }
190                             cx.pc = curOP == BREAK ? endOfLoop - 1 : loopInstructionLocation;
191                             continue OUTER;
192                         }
193                     }
194                 }
195                 throw new Error("CONTINUE/BREAK invoked but couldn't find a LoopMarker at " + ((CompiledFunctionImpl)cx.f).sourceName + ":" + getLine(cx));
196
197             case TRY: {
198                 int[] jmps = (int[]) curArg;
199                 // jmps[0] is how far away the catch block is, jmps[1] is how far away the finally block is
200                 // each can be < 0 if the specified block does not exist
201                 cx.stack.push(new TryMarker(jmps[0] < 0 ? -1 : cx.pc + jmps[0], jmps[1] < 0 ? -1 : cx.pc + jmps[1], cx.scope));
202                 break;
203             }
204
205             case RETURN: {
206                 Object retval = cx.stack.pop();
207                 while(cx.stack.size() > 0) {
208                     Object o = cx.stack.pop();
209                     if (o instanceof TryMarker) {
210                         if(((TryMarker)o).finallyLoc < 0) continue;
211                         cx.stack.push(retval); 
212                         cx.stack.push(new FinallyData(RETURN));
213                         cx.scope = ((TryMarker)o).scope;
214                         cx.pc = ((TryMarker)o).finallyLoc - 1;
215                         continue OUTER;
216                     }
217                     if (o instanceof CallMarker) {
218                         cx.scope = ((CallMarker)o).scope;
219                         cx.pc = ((CallMarker)o).pc;
220                         cx.f = (CompiledFunction)((CallMarker)o).f;
221                         cx.stack.push(retval);
222                         continue OUTER;
223                     }
224                 }
225                 throw new Error("error: RETURN invoked but couldn't find a CallMarker!");
226             }
227
228             case PUT: {
229                 Object val = cx.stack.pop();
230                 Object key = cx.stack.pop();
231                 Object target = cx.stack.peek();
232                 if (target == null)
233                     throw je("tried to put a value to the " + key + " property on the null value");
234                 if (!(target instanceof JS))
235                     throw je("tried to put a value to the " + key + " property on a " + target.getClass().getName());
236                 if (key == null)
237                     throw je("tried to assign \"" + (val==null?"(null)":val.toString()) + "\" to the null key");
238                 returnedFromJava = ((JS)target).put(key, val);
239                 if (returnedFromJava != null) {
240                     checkReturnedFromJava = true;
241                 } else {
242                     cx.stack.push(val);
243                 }
244                 break;
245             }
246
247             case GET:
248             case GET_PRESERVE: {
249                 Object o, v;
250                 if (curOP == GET) {
251                     v = curArg == null ? cx.stack.pop() : curArg;
252                     o = cx.stack.pop();
253                 } else {
254                     v = cx.stack.pop();
255                     o = cx.stack.peek();
256                     cx.stack.push(v);
257                 }
258                 Object ret = null;
259                 if (o == null) throw je("tried to get property \"" + v + "\" from the null value");
260                 if (v == null) throw je("tried to get the null key from " + o);
261                 if (o instanceof String || o instanceof Number || o instanceof Boolean)
262                     ret = Internal.getFromPrimitive(o,v);
263                 else if (o instanceof JS) {
264                     returnedFromJava = ((JS)o).get(v);
265                     checkReturnedFromJava = true;
266                     break;
267                 } else 
268                     throw je("tried to get property " + v + " from a " + o.getClass().getName());
269                 cx.stack.push(ret);
270                 break;
271             }
272             
273             case CALLMETHOD:
274             case CALL:
275             case CALL_REVERSED:
276             {
277                 JS.Array arguments = new JS.Array();
278                 int numArgs = JS.toNumber(curArg).intValue();
279                 arguments.setSize(numArgs);
280                 Object o = null;
281                 if (curOP == CALL_REVERSED) o = cx.stack.pop();
282                 for(int j=numArgs - 1; j >= 0; j--) arguments.setElementAt(cx.stack.pop(), j);
283                 if (curOP != CALL_REVERSED) o = cx.stack.pop();
284                 if(o == null) throw je("attempted to call null");
285                 Object ret;
286
287                 if(curOP == CALLMETHOD) {
288                     Object method = o;
289                     o = cx.stack.pop();
290                     if(o instanceof String || o instanceof Number || o instanceof Boolean) {
291                         ret = Internal.callMethodOnPrimitive(o,method,arguments);
292                         cx.stack.push(ret);
293                         cx.pc += 2;  // skip the GET and CALL
294                         break;
295                     } else if (o instanceof JS && ((JS)o).callMethod(method, arguments, true) == Boolean.TRUE) {
296                         returnedFromJava = ((JS)o).callMethod(method, arguments, false);
297                         checkReturnedFromJava = true;
298                         cx.pc += 2;  // skip the GET and CALL
299                         break;
300                     } else {
301                         // put the args back on the stack and let the GET followed by CALL happen
302                         for(int j=0; j<numArgs; j++) cx.stack.push(arguments.elementAt(j));
303                         cx.stack.push(o);
304                         cx.stack.push(method);
305                         break;
306                     }
307                 }
308
309                 if (o instanceof CompiledFunctionImpl) {
310                     cx.stack.push(new CallMarker(cx));
311                     cx.stack.push(arguments);
312                     cx.f = (CompiledFunction)o;
313                     cx.scope = new FunctionScope("unknown", cx.f.parentScope);
314                     cx.pc = -1;
315                     break;
316                     
317                 } else {
318                     returnedFromJava = ((JS.Callable)o).call(arguments);
319                     checkReturnedFromJava = true;
320                     break;
321                 }
322             }
323
324             case THROW: {
325                 Object o = cx.stack.pop();
326                 if(o instanceof JS.Exn) throw (JS.Exn)o;
327                 throw new JS.Exn(o);
328             }
329
330             case INC: case DEC: {
331                 boolean isPrefix = JS.toBoolean(curArg);
332                 Object key = cx.stack.pop();
333                 JS obj = (JS)cx.stack.pop();
334                 Number num = JS.toNumber(obj.get(key));
335                 Number val = new Double(curOP == INC ? num.doubleValue() + 1.0 : num.doubleValue() - 1.0);
336                 obj.put(key, val);
337                 cx.stack.push(isPrefix ? val : num);
338                 break;
339             }
340             
341             case ASSIGN_SUB: case ASSIGN_ADD: {
342                 Object val = cx.stack.pop();
343                 Object old = cx.stack.pop();
344                 Object key = cx.stack.pop();
345                 Object obj = cx.stack.peek();
346                 if (val instanceof CompiledFunction) {
347                     if (obj instanceof JS.Scope) {
348                         JS.Scope parent = (JS.Scope)obj;
349                         while(parent.getParentScope() != null) parent = parent.getParentScope();
350                         if (parent instanceof org.xwt.Box) {
351                             if (curOP == ASSIGN_ADD) {
352                                 ((org.xwt.Box)parent).addTrap(key, val);
353                             } else {
354                                 ((org.xwt.Box)parent).delTrap(key, val);
355                             }
356                             // skip over the "normal" implementation of +=/-=
357                             cx.pc += ((Integer)curArg).intValue() - 1;
358                             break;
359                         }
360                     }
361                 }
362                 // use the "normal" implementation
363                 cx.stack.push(key);
364                 cx.stack.push(old);
365                 cx.stack.push(val);
366                 break;
367             }
368
369             case ADD: {
370                 int count = ((Number)curArg).intValue();
371                 if(count < 2) throw new Error("this should never happen");
372                 if(count == 2) {
373                     // common case
374                     Object right = cx.stack.pop();
375                     Object left = cx.stack.pop();
376                     if(left instanceof String || right instanceof String) cx.stack.push(JS.toString(left).concat(JS.toString(right)));
377                     else cx.stack.push(new Double(JS.toDouble(left) + JS.toDouble(right)));
378                 } else {
379                     Object[] args = new Object[count];
380                     while(--count >= 0) args[count] = cx.stack.pop();
381                     if(args[0] instanceof String) {
382                         StringBuffer sb = new StringBuffer(64);
383                         for(int i=0;i<args.length;i++) sb.append(JS.toString(args[i]));
384                         cx.stack.push(sb.toString());
385                     } else {
386                         int numStrings = 0;
387                         for(int i=0;i<args.length;i++) if(args[i] instanceof String) numStrings++;
388                         if(numStrings == 0) {
389                             double d = 0.0;
390                             for(int i=0;i<args.length;i++) d += JS.toDouble(args[i]);
391                             cx.stack.push(new Double(d));
392                         } else {
393                             int i=0;
394                             StringBuffer sb = new StringBuffer(64);
395                             if(!(args[0] instanceof String || args[1] instanceof String)) {
396                                 double d=0.0;
397                                 do {
398                                     d += JS.toDouble(args[i++]);
399                                 } while(!(args[i] instanceof String));
400                                 sb.append(JS.toString(new Double(d)));
401                             }
402                             while(i < args.length) sb.append(JS.toString(args[i++]));
403                             cx.stack.push(sb.toString());
404                         }
405                     }
406                 }
407                 break;
408             }
409
410             default: {
411                 Object right = cx.stack.pop();
412                 Object left = cx.stack.pop();
413                 switch(curOP) {
414                         
415                 case BITOR: cx.stack.push(new Long(JS.toLong(left) | JS.toLong(right))); break;
416                 case BITXOR: cx.stack.push(new Long(JS.toLong(left) ^ JS.toLong(right))); break;
417                 case BITAND: cx.stack.push(new Long(JS.toLong(left) & JS.toLong(right))); break;
418
419                 case SUB: cx.stack.push(new Double(JS.toDouble(left) - JS.toDouble(right))); break;
420                 case MUL: cx.stack.push(new Double(JS.toDouble(left) * JS.toDouble(right))); break;
421                 case DIV: cx.stack.push(new Double(JS.toDouble(left) / JS.toDouble(right))); break;
422                 case MOD: cx.stack.push(new Double(JS.toDouble(left) % JS.toDouble(right))); break;
423                         
424                 case LSH: cx.stack.push(new Long(JS.toLong(left) << JS.toLong(right))); break;
425                 case RSH: cx.stack.push(new Long(JS.toLong(left) >> JS.toLong(right))); break;
426                 case URSH: cx.stack.push(new Long(JS.toLong(left) >>> JS.toLong(right))); break;
427                         
428                 case LT: case LE: case GT: case GE: {
429                     if (left == null) left = new Integer(0);
430                     if (right == null) right = new Integer(0);
431                     int result = 0;
432                     if (left instanceof String || right instanceof String) {
433                         result = left.toString().compareTo(right.toString());
434                     } else {
435                         result = (int)java.lang.Math.ceil(JS.toDouble(left) - JS.toDouble(right));
436                     }
437                     cx.stack.push(new Boolean((curOP == LT && result < 0) || (curOP == LE && result <= 0) ||
438                                        (curOP == GT && result > 0) || (curOP == GE && result >= 0)));
439                     break;
440                 }
441                     
442                 case EQ:
443                 case NE: {
444                     Object l = left;
445                     Object r = right;
446                     boolean ret;
447                     if (l == null) { Object tmp = r; r = l; l = tmp; }
448                     if (l == null && r == null) ret = true;
449                     else if (r == null) ret = false; // l != null, so its false
450                     else if (l instanceof Boolean) ret = new Boolean(JS.toBoolean(r)).equals(l);
451                     else if (l instanceof Number) ret = JS.toNumber(r).doubleValue() == JS.toNumber(l).doubleValue();
452                     else if (l instanceof String) ret = r != null && l.equals(r.toString());
453                     else ret = l.equals(r);
454                     cx.stack.push(new Boolean(curOP == EQ ? ret : !ret)); break;
455                 }
456
457                 default: throw new Error("unknown opcode " + curOP);
458                 } }
459             }
460
461             // handle special directions returned from Java callouts
462             // ideally we would do this with exceptions, but they're *very* slow in gcj
463             if (checkReturnedFromJava) {
464                 checkReturnedFromJava = false;
465                 if (returnedFromJava == Context.pause) {
466                     cx.pc++;
467                     return Context.pause;
468                 } else if (returnedFromJava instanceof TailCall) {
469                     cx.stack.push(new CallMarker(cx));
470                     cx.stack.push(((JS.TailCall)returnedFromJava).args);
471                     cx.f = ((JS.TailCall)returnedFromJava).func;
472                     cx.scope = new CompiledFunctionImpl.FunctionScope("unknown", cx.f.parentScope);
473                     cx.pc = -1;
474                 } else {
475                     cx.stack.push(returnedFromJava);
476                 }
477                 continue OUTER;
478             }
479
480
481         } catch(JS.Exn e) {
482             while(cx.stack.size() > 0) {
483                 Object o = cx.stack.pop();
484                 if (o instanceof CatchMarker || o instanceof TryMarker) {
485                     boolean inCatch = o instanceof CatchMarker;
486                     if(inCatch) {
487                         o = cx.stack.pop();
488                         if(((TryMarker)o).finallyLoc < 0) continue; // no finally block, keep going
489                     }
490                     if(!inCatch && ((TryMarker)o).catchLoc >= 0) {
491                         // run the catch block, this will implicitly run the finally block, if it exists
492                         cx.stack.push(o);
493                         cx.stack.push(catchMarker);
494                         cx.stack.push(e.getObject());
495                         cx.scope = ((TryMarker)o).scope;
496                         cx.pc = ((TryMarker)o).catchLoc - 1;
497                         continue OUTER;
498                     } else {
499                         cx.stack.push(e);
500                         cx.stack.push(new FinallyData(THROW));
501                         cx.scope = ((TryMarker)o).scope;
502                         cx.pc = ((TryMarker)o).finallyLoc - 1;
503                         continue OUTER;
504                     }
505                 }
506                 // no handler found within this func
507                 if(o instanceof CallMarker) throw e;
508             }
509             throw e;
510         } // end try/catch
511         } // end for
512     }
513
514     // Debugging //////////////////////////////////////////////////////////////////////
515
516     public String toString() {
517         StringBuffer sb = new StringBuffer(1024);
518         sb.append("\n" + sourceName + ": " + firstLine + "\n");
519         for (int i=0; i < size; i++) {
520             sb.append(i);
521             sb.append(": ");
522             if (op[i] < 0)
523                 sb.append(bytecodeToString[-op[i]]);
524             else
525                 sb.append(codeToString[op[i]]);
526             sb.append(" ");
527             sb.append(arg[i] == null ? "(no arg)" : arg[i]);
528             if((op[i] == JF || op[i] == JT || op[i] == JMP) && arg[i] != null && arg[i] instanceof Number) {
529                 sb.append(" jump to ").append(i+((Number) arg[i]).intValue());
530             } else  if(op[i] == TRY) {
531                 int[] jmps = (int[]) arg[i];
532                 sb.append(" catch: ").append(jmps[0] < 0 ? "No catch block" : ""+(i+jmps[0]));
533                 sb.append(" finally: ").append(jmps[1] < 0 ? "No finally block" : ""+(i+jmps[1]));
534             }
535             sb.append("\n");
536         }
537         return sb.toString();
538     } 
539
540     // Exception Stuff ////////////////////////////////////////////////////////////////
541
542     static class EvaluatorException extends RuntimeException { public EvaluatorException(String s) { super(s); } }
543     static EvaluatorException ee(String s) {
544         throw new EvaluatorException(JS.Context.getSourceName() + ":" + JS.Context.getLine() + " " + s);
545     }
546     static JS.Exn je(String s) {
547         throw new JS.Exn(JS.Context.getSourceName() + ":" + JS.Context.getLine() + " " + s);
548     }
549
550     // FunctionScope /////////////////////////////////////////////////////////////////
551
552     static class FunctionScope extends JS.Scope {
553         String sourceName;
554         public FunctionScope(String sourceName, Scope parentScope) { super(parentScope); this.sourceName = sourceName; }
555         public String getSourceName() { return sourceName; }
556     }
557
558
559     // Markers //////////////////////////////////////////////////////////////////////
560
561     public static class CallMarker {
562         int pc;
563         Scope scope;
564         CompiledFunctionImpl f;
565         public CallMarker(Context cx) { pc = cx.pc + 1; scope = cx.scope; f = cx.f; }
566     }
567     
568     public static class CatchMarker { public CatchMarker() { } }
569     private static CatchMarker catchMarker = new CatchMarker();
570     
571     public static class LoopMarker {
572         public int location;
573         public String label;
574         public JS.Scope scope;
575         public LoopMarker(int location, String label, JS.Scope scope) {
576             this.location = location;
577             this.label = label;
578             this.scope = scope;
579         }
580     }
581     public static class TryMarker {
582         public int catchLoc;
583         public int finallyLoc;
584         public JS.Scope scope;
585         public TryMarker(int catchLoc, int finallyLoc, JS.Scope scope) {
586             this.catchLoc = catchLoc;
587             this.finallyLoc = finallyLoc;
588             this.scope = scope;
589         }
590     }
591     public static class FinallyData {
592         public int op;
593         public Object arg;
594         public FinallyData(int op, Object arg) { this.op = op; this.arg = arg; }
595         public FinallyData(int op) { this(op,null); }
596     }
597 }
598
599 /** this class exists solely to work around a GCJ bug */
600 abstract class JSCallable extends JS.Callable {
601         public abstract Object call(JS.Array args) throws JS.Exn;
602 }