/** ** $ Bit source code. - bit_interpreter.h - Wed 23 Apr 2008 05:16:12 PM PDT ** ** Copyright (C) 2007-2008 Debris and various contributors. ** Based on the work done by Salvatore Sanfilippo, David Betz, ** Andrew Fedoniouk, Chris Ross and others. ** All rights reserved. ** ** Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are met: ** ** o Redistributions of source code must retain the above copyright notice, this ** list of conditions and the following disclaimer. ** o Redistributions in binary form must reproduce the above copyright notice, ** this list of conditions and the following disclaimer in the documentation ** and/or other materials provided with the distribution. ** o Neither the name of the software nor the names of its contributors may ** be used to endorse or promote products derived from this software without ** specific prior written permission. ** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ** POSSIBILITY OF SUCH DAMAGE. **/ /** @define interpreter. **/ #ifndef _bit_interpreter_ #define _bit_interpreter_ /** @virtual machine opcodes. ** Bit uses a simple stack based virtual machine. The compiler generates opcodes ** for instructions parsed from the original source code and the interpreter ** traverses them, executing operations on the stack. **/ //// Jumps, branching. #define bit_op_jmt 0x01 // Branch on true value. #define bit_op_jmf 0x02 // Branch on false value. #define bit_op_jmp 0x03 // Branch unconditionally. //// Boolean values. #define bit_op_true 0x04 // Load value with true. #define bit_op_false 0x05 // Load value with nil. //// Arithmetic opcodes. #define bit_op_add 0x06 // Add two numeric expressions. #define bit_op_sub 0x07 // Subtract two numeric expressions. #define bit_op_mul 0x08 // Multiply two numeric expressions. #define bit_op_div 0x09 // Divide two numeric expressions. #define bit_op_rem 0x10 // Remainder of two numeric expressions. //// Bitwise operations. #define bit_op_and 0x11 // Bitwise and of top two stack entries. #define bit_op_or 0x12 // Bitwise or of top two stack entries. #define bit_op_xor 0x13 // Bitwise xor of top two stack entries. #define bit_op_not 0x14 // Bitwise not of top two stack entries. #define bit_op_shl 0x15 // Bitwise shift left top two stack entries. #define bit_op_shr 0x16 // Bitwise shift right top two stack entries. //// Comparison operations. #define bit_op_lt 0x17 // Less than. #define bit_op_le 0x18 // Less than or equal. #define bit_op_eq 0x19 // Equal. #define bit_op_ne 0x20 // Not equal. #define bit_op_ge 0x21 // Greater than or equal. #define bit_op_gt 0x22 // Greater than. //// Literals and variables. #define bit_op_lit 0x23 // Load literal. #define bit_op_gref 0x24 // Load a global variable value. #define bit_op_gset 0x25 // Set the value of a global variable. #define bit_op_grefp 0x26 // Get the value of an object property. #define bit_op_gsetp 0x27 // Set the value of an object property and return the value. //// Functions and procedures. #define bit_op_fret 0x28 // Return from interpreter. #define bit_op_fproc 0x29 // Execute a function and it's arguments. #define bit_op_fsend 0x30 // Send a message to an object. //// Environments. #define bit_op_eref 0x31 // Load an environment value. #define bit_op_eset 0x32 // Set an environment value. #define bit_op_epush 0x33 // Push an environment frame. #define bit_op_epop 0x34 // Pop an environment frame. //// Vectors. #define bit_op_vref 0x35 // Get an element of a vector. #define bit_op_vset 0x36 // Set an element of a vector. //// Stack manipulation. #define bit_op_push 0x37 // Push val onto stack. #define bit_op_drop 0x38 // Drop the top entry from the stack. #define bit_op_not 0x39 // Logical negate top of stack. #define bit_op_neg 0x40 // Negate top of stack. #define bit_op_inc 0x41 // Increment. #define bit_op_dec 0x42 // Decrement. #define bit_op_dup 0x43 // Duplicate the top entry on the stack. #define bit_op_ddup 0x44 // Duplicate top two elements on the stack. #define bit_op_over 0x45 // Duplicate the second entry on the stack. //// Object creation. #define bit_op_carg 0x46 // Create an argument frame. #define bit_op_cargrt 0x47 // Create an argument frame with rest argument. #define bit_op_cclosure 0x48 // Create a closure. #define bit_op_cframe 0x49 // Create an environment frame. #define bit_op_cobject 0x50 // Create a new object. #define bit_op_cvector 0x51 // Create a new vector. //// Misc facilities. #define bit_op_switch 0x52 // Switch dispatch. #define bit_op_argsge 0x53 // Argc greater than or equal to. #define bit_op_pushscope 0x54 // Push two copies of the current scope object. #define bit_op_throw 0x55 // Throw an exception. #endif