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