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