1 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
8 * Constants for the various JavaScript ByteCode operations.
10 * Each instruction is an opcode and an optional literal literal;
11 * some Tokens are also valid; see Tokens.java
15 /** push the literal onto the stack */
16 public static final byte LITERAL = -2;
18 /** push a new array onto the stack with length equal to the literal */
19 public static final byte ARRAY = -3;
21 /** push an empty object onto the stack */
22 public static final byte OBJECT = -4;
24 /** create a new instance; literal is a reference to the corresponding ForthBlock */
25 public static final byte NEWFUNCTION = -5;
27 /** if given a non-null argument declare its argument in the current scope and push
28 it to the stack, else, declares the element on the top of the stack and leaves it
30 //public static final byte DECLARE = -6;
32 /** push a reference to the current scope onto the stack */
33 // FIXME: Document this
34 public static final byte GLOBALSCOPE = -7;
36 /** if given a null literal pop two elements off the stack; push stack[-1].get(stack[top])
37 else pop one element off the stack, push stack[top].get(literal) */
38 public static final byte GET = -8;
40 /** push stack[-1].get(stack[top]) */
41 public static final byte GET_PRESERVE = -9;
43 /** pop two elements off the stack; stack[-2].put(stack[-1], stack[top]); push stack[top] */
44 public static final byte PUT = -10;
46 /** literal is a relative address; pop stacktop and jump if the value is true */
47 public static final byte JT = -11;
49 /** literal is a relative address; pop stacktop and jump if the value is false */
50 public static final byte JF = -12;
52 /** literal is a relative address; jump to it */
53 public static final byte JMP = -13;
55 /** discard the top stack element */
56 static public final byte POP = -14;
58 /** pop element; call stack[top](stack[-n], stack[-n+1]...) where n is the number of args to the function */
59 public static final byte CALL = -15;
61 /** pop an element; push a JS.JSArray containing the keys of the popped element */
62 public static final byte PUSHKEYS = -16;
64 /** push the top element down so that (arg) elements are on top of it; all other elements retain ordering */
65 public static final byte SWAP = -17;
67 /** execute the bytecode block pointed to by the literal in a fresh scope with parentScope==THIS */
68 public static final byte NEWSCOPE = -18;
70 /** execute the bytecode block pointed to by the literal in a fresh scope with parentScope==THIS */
71 public static final byte OLDSCOPE = -19;
73 /** push a copy of the top stack element */
74 public static final byte DUP = -20;
76 /** a NOP; confers a label upon the following instruction */
77 public static final byte LABEL = -21;
79 /** execute the ForthBlock pointed to by the literal until BREAK encountered; push TRUE onto the stack for the first iteration
80 * and FALSE for all subsequent iterations */
81 public static final byte LOOP = -22;
83 /** similar effect a a GET followed by a CALL */
84 public static final byte CALLMETHOD = -23;
86 /** finish a finally block and carry out whatever instruction initiated the finally block */
87 public static final byte FINALLY_DONE = -24;
89 /** finish a finally block and carry out whatever instruction initiated the finally block */
90 public static final byte MAKE_GRAMMAR = -25;
92 // FIXME: Document these and NEWSCOPE/OLDSCOPE/TOPSCOPE changes
93 public static final byte SCOPEGET = -26;
94 public static final byte SCOPEPUT = -27;
96 public static final String[] bytecodeToString = new String[] {
97 "", "", "LITERAL", "ARRAY", "OBJECT", "NEWFUNCTION", "DECLARE", "GLOBALSCOPE",
98 "GET", "GET_PRESERVE", "PUT", "JT", "JF", "JMP", "POP", "CALL", "PUSHKEYS",
99 "SWAP", "NEWSCOPE", "OLDSCOPE", "DUP", "LABEL", "LOOP", "CALLMETHOD",
100 "FINALLY_DONE", "MAKE_GRAMMAR", "SCOPEGET", "SCOPEPUT"