// Copyright 2000-2005 the Contributors, as shown in the revision logs. // Licensed under the Apache Public Source License 2.0 ("the License"). // You may not use this file except in compliance with the License. package org.ibex.js; /** * Constants for the various JavaScript ByteCode operations. * * Each instruction is an opcode and an optional literal literal; * some Tokens are also valid; see Tokens.java */ interface ByteCodes { /** push the literal onto the stack */ public static final byte LITERAL = -2; /** push a new array onto the stack with length equal to the literal */ public static final byte ARRAY = -3; /** push an empty object onto the stack */ public static final byte OBJECT = -4; /** create a new instance; literal is a reference to the corresponding ForthBlock */ public static final byte NEWFUNCTION = -5; /** if given a non-null argument declare its argument in the current scope and push it to the stack, else, declares the element on the top of the stack and leaves it there */ //public static final byte DECLARE = -6; /** push a reference to the current scope onto the stack */ public static final byte GLOBALSCOPE = -7; /** if given a null literal pop two elements off the stack; push stack[-1].get(stack[top]) else pop one element off the stack, push stack[top].get(literal) */ public static final byte GET = -8; /** push stack[-1].get(stack[top]) */ public static final byte GET_PRESERVE = -9; /** pop two elements off the stack; stack[-2].put(stack[-1], stack[top]); push stack[top] */ public static final byte PUT = -10; /** literal is a relative address; pop stacktop and jump if the value is true */ public static final byte JT = -11; /** literal is a relative address; pop stacktop and jump if the value is false */ public static final byte JF = -12; /** literal is a relative address; jump to it */ public static final byte JMP = -13; /** discard the top stack element */ static public final byte POP = -14; /** pop element; call stack[top](stack[-n], stack[-n+1]...) where n is the number of args to the function */ public static final byte CALL = -15; /** pop an element; push a JS.JSArray containing the keys of the popped element */ public static final byte PUSHKEYS = -16; /** push the top element down so that (arg) elements are on top of it; all other elements retain ordering */ public static final byte SWAP = -17; /** execute the bytecode block pointed to by the literal in a fresh scope with parentScope==THIS */ public static final byte NEWSCOPE = -18; /** execute the bytecode block pointed to by the literal in a fresh scope with parentScope==THIS */ public static final byte OLDSCOPE = -19; /** push a copy of the top stack element */ public static final byte DUP = -20; /** a NOP; confers a label upon the following instruction */ public static final byte LABEL = -21; /** execute the ForthBlock pointed to by the literal until BREAK encountered; push TRUE onto the stack for the first iteration * and FALSE for all subsequent iterations */ public static final byte LOOP = -22; /** similar effect a a GET followed by a CALL */ public static final byte CALLMETHOD = -23; /** finish a finally block and carry out whatever instruction initiated the finally block */ public static final byte FINALLY_DONE = -24; /** finish a finally block and carry out whatever instruction initiated the finally block */ public static final byte MAKE_GRAMMAR = -25; // FEATURE: Document these and NEWSCOPE/OLDSCOPE/TOPSCOPE changes public static final byte SCOPEGET = -26; public static final byte SCOPEPUT = -27; public static final String[] bytecodeToString = new String[] { "", "", "LITERAL", "ARRAY", "OBJECT", "NEWFUNCTION", "DECLARE", "GLOBALSCOPE", "GET", "GET_PRESERVE", "PUT", "JT", "JF", "JMP", "POP", "CALL", "PUSHKEYS", "SWAP", "NEWSCOPE", "OLDSCOPE", "DUP", "LABEL", "LOOP", "CALLMETHOD", "FINALLY_DONE", "MAKE_GRAMMAR", "SCOPEGET", "SCOPEPUT" }; }