1 /****************************************************************************** 2 Copyright (c) 1992, 1995, 1996 Xerox Corporation. All rights reserved. 3 Portions of this code were written by Stephen White, aka ghond. 4 Use and copying of this software and preparation of derivative works based 5 upon this software are permitted. Any distribution of this software or 6 derivative works must comply with all applicable United States export 7 control laws. This software is made available AS IS, and Xerox Corporation 8 makes no warranty about the software, its performance or its conformity to 9 any specification. Any person obtaining a copy of this software is requested 10 to send their name and post office or electronic mail address to: 11 Pavel Curtis 12 Xerox PARC 13 3333 Coyote Hill Rd. 14 Palo Alto, CA 94304 15 Pavel@Xerox.Com 16 *****************************************************************************/ 17 18 #ifndef Opcode_h 19 #define Opcode_h 1 20 21 #include "options.h" 22 23 #define NUM_READY_VARS 32 24 25 enum Extended_Opcode { 26 EOP_RANGESET, EOP_LENGTH, 27 EOP_PUSH_LABEL, EOP_END_CATCH, EOP_END_EXCEPT, EOP_END_FINALLY, 28 EOP_CONTINUE, 29 30 /* ops after this point cost one tick */ 31 EOP_CATCH, EOP_TRY_EXCEPT, EOP_TRY_FINALLY, 32 EOP_WHILE_ID, EOP_EXIT, EOP_EXIT_ID, 33 EOP_SCATTER, EOP_EXP, 34 35 Last_Extended_Opcode = 255 36 }; 37 38 enum Opcode { 39 40 /* control/statement constructs with 1 tick: */ 41 OP_IF, OP_WHILE, OP_EIF, OP_FORK, OP_FORK_WITH_ID, OP_FOR_LIST, 42 OP_FOR_RANGE, 43 44 /* expr-related opcodes with 1 tick: */ 45 OP_INDEXSET, OP_PUSH_GET_PROP, OP_GET_PROP, OP_CALL_VERB, OP_PUT_PROP, 46 OP_BI_FUNC_CALL, OP_IF_QUES, OP_REF, OP_RANGE_REF, 47 48 /* arglist-related opcodes with 1 tick: */ 49 OP_MAKE_SINGLETON_LIST, OP_CHECK_LIST_FOR_SPLICE, 50 51 /* arith binary ops -- 1 tick: */ 52 OP_MULT, OP_DIV, OP_MOD, OP_ADD, OP_MINUS, 53 54 /* comparison binary ops -- 1 tick: */ 55 OP_EQ, OP_NE, OP_LT, OP_LE, OP_GT, OP_GE, OP_IN, 56 57 /* logic binary ops -- 1 tick: */ 58 OP_AND, OP_OR, 59 60 /* unary ops -- 1 tick: */ 61 OP_UNARY_MINUS, OP_NOT, 62 63 /* assignments, 1 tick: */ 64 OP_PUT, 65 OP_G_PUT = OP_PUT + NUM_READY_VARS, 66 67 /* variable references, no tick: */ 68 OP_PUSH, 69 OP_G_PUSH = OP_PUSH + NUM_READY_VARS, 70 71 #ifdef BYTECODE_REDUCE_REF 72 /* final variable references, no tick: */ 73 OP_PUSH_CLEAR, 74 OP_G_PUSH_CLEAR = OP_PUSH_CLEAR + NUM_READY_VARS, 75 #endif /* BYTECODE_REDUCE_REF */ 76 77 /* expr-related opcodes with no tick: */ 78 OP_IMM, OP_MAKE_EMPTY_LIST, OP_LIST_ADD_TAIL, OP_LIST_APPEND, 79 OP_PUSH_REF, OP_PUT_TEMP, OP_PUSH_TEMP, 80 81 /* control/statement constructs with no ticks: */ 82 OP_JUMP, OP_RETURN, OP_RETURN0, OP_DONE, OP_POP, 83 84 OP_EXTENDED, /* Used to add more opcodes */ 85 86 OPTIM_NUM_START, 87 /* storage optimized imm-numbers can occupy 113-255, for 143 of them */ 88 Last_Opcode = 255 89 }; 90 91 #define OPTIM_NUM_LOW -10 92 #define OPTIM_NUM_HI (Last_Opcode - OPTIM_NUM_START + OPTIM_NUM_LOW) 93 94 #define IS_PUSH_n(o) ((o) >= (unsigned) OP_PUSH \ 95 && (o) < (unsigned) OP_G_PUSH) 96 #ifdef BYTECODE_REDUCE_REF 97 #define IS_PUSH_CLEAR_n(o) ((o) >= (unsigned) OP_PUSH_CLEAR \ 98 && (o) < (unsigned) OP_G_PUSH_CLEAR) 99 #define PUSH_CLEAR_n_INDEX(o) ((o) - OP_PUSH_CLEAR) 100 #endif /* BYTECODE_REDUCE_REF */ 101 #define IS_PUT_n(o) ((o) >= (unsigned) OP_PUT \ 102 && (o) < (unsigned) OP_G_PUT) 103 #define PUSH_n_INDEX(o) ((o) - OP_PUSH) 104 #define PUT_n_INDEX(o) ((o) - OP_PUT) 105 106 #define IS_OPTIM_NUM_OPCODE(o) ((o) >= (unsigned) OPTIM_NUM_START) 107 #define OPCODE_TO_OPTIM_NUM(o) ((o) - OPTIM_NUM_START + OPTIM_NUM_LOW) 108 109 #define OPTIM_NUM_TO_OPCODE(i) (OPTIM_NUM_START + (i) - OPTIM_NUM_LOW) 110 #define IN_OPTIM_NUM_RANGE(i) ((i) >= OPTIM_NUM_LOW && (i) <= OPTIM_NUM_HI) 111 112 /* ARITH_COMP_BIN_OP does not include AND, OR */ 113 #define IS_ARITH_COMP_BIN_OP(o) ((o) >= (unsigned) OP_MULT \ 114 && (o) <= (unsigned) OP_IN) 115 116 /* whether the opcode needs one tick */ 117 #define COUNT_TICK(o) ((o) <= OP_G_PUT) 118 #define COUNT_EOP_TICK(eo) ((eo) >= EOP_CATCH) 119 120 typedef enum Opcode Opcode; 121 typedef enum Extended_Opcode Extended_Opcode; 122 123 #endif 124 125 /* 126 * $Log: opcode.h,v $ 127 * Revision 1.3 1998/12/14 13:18:40 nop 128 * Merge UNSAFE_OPTS (ref fixups); fix Log tag placement to fit CVS whims 129 * 130 * Revision 1.2.2.1 1997/09/09 07:01:17 bjj 131 * Change bytecode generation so that x=f(x) calls f() without holding a ref 132 * to the value of x in the variable slot. See the options.h comment for 133 * BYTECODE_REDUCE_REF for more details. 134 * 135 * This checkin also makes x[y]=z (OP_INDEXSET) take advantage of that (that 136 * new code is not conditional and still works either way). 137 * 138 * Revision 1.2 1997/03/03 04:19:13 nop 139 * GNU Indent normalization 140 * 141 * Revision 1.1.1.1 1997/03/03 03:45:04 nop 142 * LambdaMOO 1.8.0p5 143 * 144 * Revision 2.3 1996/02/08 06:18:03 pavel 145 * Removed unused NUM_BUILTIN_NAMES constant. Rearranged EOPs to support tick 146 * counting and added COUNT_EOP_TICK(). Added EOP_EXP, EOP_WHILE_ID, 147 * EOP_EXIT, and EOP_EXIT_ID. Updated copyright notice for 1996. 148 * Release 1.8.0beta1. 149 * 150 * Revision 2.2 1996/01/16 07:22:07 pavel 151 * Added EOP_SCATTER. Release 1.8.0alpha6. 152 * 153 * Revision 2.1 1995/12/31 03:13:27 pavel 154 * Added EOP_LENGTH. Release 1.8.0alpha4. 155 * 156 * Revision 2.0 1995/11/30 04:53:27 pavel 157 * New baseline version, corresponding to release 1.8.0alpha1. 158 * 159 * Revision 1.4 1992/10/23 23:03:47 pavel 160 * Added copyright notice. 161 * 162 * Revision 1.3 1992/10/17 20:48:34 pavel 163 * Added some (unsigned) casts to placate over-protective compilers. 164 * Removed unused IS_EXPR_OP macro. 165 * 166 * Revision 1.2 1992/08/28 23:19:33 pjames 167 * Added Extended_Opcode enumeration, and OP_RANGESET. 168 * Replaced LABEL with OP_EXTENDED. 169 * 170 * Revision 1.1 1992/07/20 23:23:12 pavel 171 * Initial RCS-controlled version. 172 */ 173