Properly root CopyStruct/CopyArray.
1 /* vim: set ts=4 sw=4 tw=99 et:
3 * Copyright (C) 2012 David Anderson
5 * This file is part of JITCraft.
7 * JITCraft is free software: you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License as published by the Free
9 * Software Foundation, either version 3 of the License, or (at your option)
12 * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with
17 * JITCraft. If not, see http://www.gnu.org/licenses/.
20 // NAME NUMBER TEXT LENGTH USES DEFS
24 // F = 32-bit IEEE-754 float
25 // O = object reference
28 OPDEF(OP_NOP, 0, "nop", 1, 0, 0)
30 // Pushes a signed integer immediate onto the stack.
31 OPDEF(OP_INT, 1, "int", 5, 0, 1)
33 // Returns from the current routine, propagating the value at the top of the
34 // stack to the caller.
35 OPDEF(OP_RETURN, 2, "return", 1, 1, 0)
37 // Stack transitions for these comparison ops:
40 // if (lhs COMPARE rhs)
41 // goto target (immediate, relative to the beginning of the jump instruction)
42 OPDEF(OP_JL, 3, "jl", 5, 2, 0)
43 OPDEF(OP_JLE, 4, "jle", 5, 2, 0)
44 OPDEF(OP_JG, 5, "jg", 5, 2, 0)
45 OPDEF(OP_JGE, 6, "jge", 5, 2, 0)
46 OPDEF(OP_JEQ, 7, "jeq", 5, 2, 0)
47 OPDEF(OP_JNE, 8, "jne", 5, 2, 0)
50 // if (value == [true, false])
52 OPDEF(OP_JT, 9, "jt", 5, 1, 0)
53 OPDEF(OP_JF, 10, "jf", 5, 1, 0)
55 OPDEF(OP_JL_F, 11, "jl.f", 5, 2, 0)
56 OPDEF(OP_JLE_F, 12, "jle.f", 5, 2, 0)
57 OPDEF(OP_JG_F, 13, "jg.f", 5, 2, 0)
58 OPDEF(OP_JGE_F, 14, "jge.f", 5, 2, 0)
59 OPDEF(OP_JEQ_F, 15, "jeq.f", 5, 2, 0)
60 OPDEF(OP_JNE_F, 16, "jne.f", 5, 2, 0)
61 OPDEF(OP_JT_F, 17, "jt.f", 5, 1, 0)
62 OPDEF(OP_JF_F, 18, "jf.f", 5, 1, 0)
64 // Unconditional jump.
65 OPDEF(OP_JUMP, 19, "jump", 5, 0, 0)
67 // Gets or sets the value of a local variable onto the stack. The local
68 // variable is given by an immediate index.
69 OPDEF(OP_GETLOCAL, 20, "getlocal", 5, 0, 1)
70 OPDEF(OP_SETLOCAL, 21, "setlocal", 5, 1, 1)
72 // Stack transitions for these binary operators:
76 OPDEF(OP_ADD, 22, "add", 1, 2, 1)
77 OPDEF(OP_SUB, 23, "sub", 1, 2, 1)
78 OPDEF(OP_MUL, 24, "mul", 1, 2, 1)
79 OPDEF(OP_DIV, 25, "div", 1, 2, 1)
80 OPDEF(OP_MOD, 26, "mod", 1, 2, 1)
82 OPDEF(OP_LT, 27, "lt", 1, 2, 1)
83 OPDEF(OP_LE, 28, "le", 1, 2, 1)
84 OPDEF(OP_GE, 29, "ge", 1, 2, 1)
85 OPDEF(OP_GT, 30, "gt", 1, 2, 1)
86 OPDEF(OP_EQ, 31, "eq", 1, 2, 1)
87 OPDEF(OP_NE, 32, "ne", 1, 2, 1)
89 OPDEF(OP_NOT, 33, "not", 1, 1, 1)
90 OPDEF(OP_NEG, 34, "neg", 1, 1, 1)
92 OPDEF(OP_POP, 35, "pop", 1, 1, 0)
94 // Unconditional terminator placed at the end of code. If a function returns
95 // void, this acts as a RETURNVOID. Otherwise, it must be unreachable.
96 OPDEF(OP_STOP, 36, "stop", 1, 0, 0)
98 // Call a function with N arguments. The target function must be the last item
100 OPDEF(OP_CALL, 37, "call", 1, -1, 1)
102 // Similar to GET/LOCAL, except for arguments.
103 OPDEF(OP_GETARG, 38, "getarg", 5, 0, 1)
104 OPDEF(OP_SETARG, 39, "setarg", 5, 1, 1)
106 // Allocate an array. The HeapTenure is stored as a byte following pc. The
107 // ArrayMap to use is specified as an index into the script's Map table.
110 // [u8 op] [u32 index]
111 OPDEF(OP_NEWARRAY, 40, "newarray", 6, 0, 1)
113 // Performs an array-to-array assignment.
118 OPDEF(OP_COPYARRAY, 41, "arraycopy", 1, 2, 1)
120 // Reads or writes an integer element to an unsafe array.
125 OPDEF(OP_GETELEM, 42, "getelem", 1, 2, 1)
126 OPDEF(OP_SETELEM, 43, "setelem", 1, 3, 1)
128 // Pushes a 32-bit IEEE-754 floating point immediate onto the stack.
129 OPDEF(OP_FLOAT, 44, "float", 5, 0, 1)
131 // Converts an integer to a 32-bit IEEE-754 floating point immediate.
132 OPDEF(OP_CVT_I2F, 45, "cvt.i2f", 1, 1, 1)
134 // Stack transitions for these binary operators:
138 OPDEF(OP_ADD_F, 46, "add.f", 1, 2, 1)
139 OPDEF(OP_SUB_F, 47, "sub.f", 1, 2, 1)
140 OPDEF(OP_MUL_F, 48, "mul.f", 1, 2, 1)
141 OPDEF(OP_DIV_F, 49, "div.f", 1, 2, 1)
143 OPDEF(OP_LT_F, 50, "lt.f", 1, 2, 1)
144 OPDEF(OP_LE_F, 51, "le.f", 1, 2, 1)
145 OPDEF(OP_GE_F, 52, "ge.f", 1, 2, 1)
146 OPDEF(OP_GT_F, 53, "gt.f", 1, 2, 1)
147 OPDEF(OP_EQ_F, 54, "eq.f", 1, 2, 1)
148 OPDEF(OP_NE_F, 55, "ne.f", 1, 2, 1)
150 OPDEF(OP_NOT_F, 56, "not.f", 1, 1, 1)
151 OPDEF(OP_NEG_F, 57, "neg.f", 1, 1, 1)
153 // Bitwise operators.
154 OPDEF(OP_SHL, 58, "shl", 1, 2, 1)
155 OPDEF(OP_SHR, 59, "shr", 1, 2, 1)
156 OPDEF(OP_USHR, 60, "ushr", 1, 2, 1)
157 OPDEF(OP_BITAND, 61, "bitand", 1, 2, 1)
158 OPDEF(OP_BITOR, 62, "bitor", 1, 2, 1)
159 OPDEF(OP_BITXOR, 63, "bitxor", 1, 2, 1)
160 OPDEF(OP_BITNOT, 64, "bitnot", 1, 1, 1)
162 // Saves or restores the position of the LIFO heap to/from a local slot.
163 OPDEF(OP_SAVELIFO, 65, "savelifo", 5, 0, 0)
164 OPDEF(OP_UNWINDLIFO, 66, "unwindlifo", 5, 0, 0)
166 // Composes a variable reference to a stack slot or argument.
167 OPDEF(OP_VARREF_LIFO, 67, "varref.lifo", 5, 0, 1)
168 OPDEF(OP_ARGREF_LIFO, 68, "argref.lifo", 5, 0, 1)
169 OPDEF(OP_SLOTREF_LIFO, 69, "slotref.lifo", 1, 1, 1)
170 OPDEF(OP_ARRAYREF_LIFO, 70, "arrayref.lifo",1, 2, 1)
171 OPDEF(OP_GETREF_I, 71, "getref.i", 1, 1, 1)
172 OPDEF(OP_SETREF_I, 72, "setref.i", 1, 2, 1)
173 OPDEF(OP_GETREF_F, 73, "getref.f", 1, 1, 1)
174 OPDEF(OP_SETREF_F, 74, "setref.f", 1, 2, 1)
176 // Pushes an object reference onto the stack.
177 OPDEF(OP_OBJECT, 75, "object", 5, 0, 1)
179 // Duplicates the top item on the stack.
180 OPDEF(OP_DUP, 76, "dup", 1, 1, 2)
182 // Duplicates the top two items on the stack.
183 OPDEF(OP_DUP2, 77, "dup2", 1, 2, 4)
185 // Swaps the two items at the top of the stack.
186 OPDEF(OP_SWAP, 78, "swap", 1, 2, 2)
188 // Roll operation is the same as Forth. It steals a value on the stack,
189 // shifting all stack values down, and then places the stolen value back at
190 // the top of the stack.
196 OPDEF(OP_ROLL3, 79, "roll3", 1, 3, 3)
198 // Pick operation is the same as Forth. It pushes a copy of a slot at a
202 OPDEF(OP_PICK2, 80, "pick2", 1, 2, 3)
203 OPDEF(OP_PICK3, 81, "pick3", 1, 3, 4)
205 // Calls a native function. During the course of calling a native, arguments
206 // on the stack are re-pushed to match the cell-based native calling
207 // convention expected by ISourcePawnEngine.
209 // Unlike the normal CALL instruction, natives take truly variadic arguments
210 // and so we must specify the number of arguments. The format is:
212 // [u8 Opcode] [u32 Index] [u32 ArgCount]
214 OPDEF(OP_CALLNATIVE, 82, "callnative", 9, -1, 1)
216 // Returns from a function that does return a value.
217 OPDEF(OP_RETURNVOID, 83, "returnvoid", 1, 0, 0)
219 // Loads the module of the running function.
220 OPDEF(OP_MODULE, 84, "module", 1, 0, 1)
222 // Loads a function from a module object. The operand is the slot number
224 OPDEF(OP_GETMODULE_FN, 85, "getmodule.fn", 5, 1, 1)
226 // Opcodes for accessing an environment slot in the global scope.
227 OPDEF(OP_SETGLOBAL_I, 86, "setglobal.i", 5, 1, 1)
228 OPDEF(OP_SETGLOBAL_F, 87, "setglobal.f", 5, 1, 1)
229 OPDEF(OP_SETGLOBAL_O, 88, "setglobal.o", 5, 1, 1)
230 OPDEF(OP_GETGLOBAL_I, 89, "getglobal.i", 5, 0, 1)
231 OPDEF(OP_GETGLOBAL_F, 90, "getglobal.f", 5, 0, 1)
232 OPDEF(OP_GETGLOBAL_O, 91, "getglobal.o", 5, 0, 1)
234 // Reinterprets a 32-bit integer as a float, or vice-versa.
235 OPDEF(OP_BITS_I2F, 92, "bits.i2f", 1, 1, 1)
236 OPDEF(OP_BITS_F2I, 93, "bits.f2i", 1, 1, 1)
238 // Pushes a boolean value.
239 OPDEF(OP_TRUE, 94, "true", 1, 0, 1)
240 OPDEF(OP_FALSE, 95, "false", 1, 0, 1)
242 // Allocate a struct. The HeapTenure is stored as a byte following pc. The
243 // StructMap to use is specified as an index into the script's Map table.
246 // [u8 op] [u32 index]
247 OPDEF(OP_NEWSTRUCT, 96, "newstruct", 6, 0, 1)
249 // Performs a struct-to-struct assignment.
254 OPDEF(OP_COPYSTRUCT, 97, "structcopy", 1, 2, 1)
256 // Sets or gets a property in a struct. The index of the field is specified as
257 // a 32-bit integer. Note that these opcodes follow a new style of deriving
258 // their types at runtime.
259 OPDEF(OP_GETFIELD, 98, "getfield", 5, 1, 1)
260 OPDEF(OP_SETFIELD, 99, "setfield", 5, 2, 1)
262 OPDEF(OP_FIELDREF_LIFO, 100, "fieldref.lifo", 5, 1, 1)
265 // [u8 op] [i32 low] [i32 high] [u32 jump] [u32 jumps...]
266 OPDEF(OP_TABLESWITCH, 101, "tableswitch", 9, 1, 0)