5dc2aff6c6aa3360dbc313d551ada0040e7732a2
[org.ibex.core.git] / src / org / xwt / js / ByteCodes.java
1 // Copyright 2003 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     /** pop a string off the stack and declare it in the current scope */
25     public static final byte DECLARE = -6;       
26
27     /** push a reference to the current scope onto the stack */
28     public static final byte TOPSCOPE = -7;
29
30     /** pop two elements off the stack; push stack[-1].get(stack[top]) */
31     public static final byte GET = -8;           
32
33     /** push stack[-1].get(stack[top]) */
34     public static final byte GET_PRESERVE = -9; 
35
36     /** pop two elements off the stack; stack[-2].put(stack[-1], stack[top]); push stack[top] */
37     public static final byte PUT = -10;           
38
39     /** literal is a relative address; pop stacktop and jump if the value is true */
40     public static final byte JT = -11;           
41
42     /** literal is a relative address; pop stacktop and jump if the value is false */
43     public static final byte JF = -12;           
44
45     /** literal is a relative address; jump to it */
46     public static final byte JMP = -13;          
47
48     /** discard the top stack element */
49     static public final byte POP = -14;          
50
51     /** pop two elements; call stack[-1](stack[top]) where stacktop is a JS.JS.Array */
52     public static final byte CALL = -15;         
53
54     /** pop an element; push a JS.JS.Array containing the keys of the popped element */
55     public static final byte PUSHKEYS = -16;     
56
57     /** swap the top two elements on the stack */
58     public static final byte SWAP = -17;         
59
60     /** execute the ForthBlock pointed to by the literal in a fresh scope with parentScope==THIS */
61     public static final byte NEWSCOPE = -18;        
62
63     /** execute the ForthBlock pointed to by the literal in a fresh scope with parentScope==THIS */
64     public static final byte OLDSCOPE = -19;
65
66     /** push a copy of the top stack element */
67     public static final byte DUP = -20;          
68
69     /** a NOP; confers a label upon the following instruction */
70     public static final byte LABEL = -21;          
71
72     /** execute the ForthBlock pointed to by the literal until BREAK encountered; push TRUE onto the stack for the first iteration
73      *  and FALSE for all subsequent iterations */
74     public static final byte LOOP = -22;        
75      
76     /** pop three elements off the stack; method arguments, method name, and an object to call the method on, then calls the method 
77         Has a similar effect a a GET followed by a CALL */
78     public static final byte CALLMETHOD = -23;
79
80     /** finish a finally block and carry out whatever instruction initiated the finally block */
81     public static final byte FINALLY_DONE = -24;
82     
83     public static final String[] bytecodeToString = new String[] {
84         "", "", "LITERAL", "ARRAY", "OBJECT", "NEWFUNCTION", "DECLARE", "TOPSCOPE",
85         "GET", "GET_PRESERVE", "PUT", "JT", "JF", "JMP", "POP", "CALL", "PUSHKEYS",
86         "SWAP", "NEWSCOPE", "OLDSCOPE", "DUP", "LABEL", "LOOP", "CALLMETHOD",
87         "FINALLY_DONE"
88     };
89 }