moved back to old acc
[vox.git] / src / core / opcodes.hpp
blob8e0b8937b58a7ef1d0a6e3d23789225470212ac8
2 #ifndef _VXOPCODES_H_
3 #define _VXOPCODES_H_
5 #include "pcheader.hpp"
7 #define MAX_FUNC_STACKSIZE 0xFF
8 #define MAX_LITERALS ((VXInteger)0x7FFFFFFF)
9 #define NEW_SLVX_OT_ATTRIBUTES_FLAG 0x01
10 #define NEW_SLVX_OT_STATIC_FLAG 0x02
12 #define _FINISH(howmuchtojump) \
14 jump = howmuchtojump; \
15 return true; \
18 #define _RET_ON_FAIL(exp) { if(!exp) return false; }
22 enum BitWiseOP
24 BW_AND = 0,
25 BW_OR = 2,
26 BW_XOR = 3,
27 BW_SHIFTL = 4,
28 BW_SHIFTR = 5,
29 BW_USHIFTR = 6
32 enum CmpOP
34 CMP_G = 0,
35 CMP_GE = 2,
36 CMP_L = 3,
37 CMP_LE = 4,
38 CMP_3W = 5
41 enum NewObjectType
43 NVX_OT_TABLE = 0,
44 NVX_OT_ARRAY = 1,
45 NVX_OT_CLASS = 2
48 enum AppendArrayType
50 AAT_STACK = 0,
51 AAT_LITERAL = 1,
52 AAT_INT = 2,
53 AAT_FLOAT = 3,
54 AAT_BOOL = 4
57 enum VXOpcode
59 _OP_LINE= 0x00,
60 _OP_LOAD= 0x01,
61 _OP_LOADINT= 0x02,
62 _OP_LOADFLOAT= 0x03,
63 _OP_DLOAD= 0x04,
64 _OP_TAILCALL= 0x05,
65 _OP_CALL= 0x06,
66 _OP_PREPCALL= 0x07,
67 _OP_PREPCALLK= 0x08,
68 _OP_GETK= 0x09,
69 _OP_MOVE= 0x0A,
70 _OP_NEWSLOT= 0x0B,
71 _OP_DELETE= 0x0C,
72 _OP_SET= 0x0D,
73 _OP_GET= 0x0E,
74 _OP_EQ= 0x0F,
75 _OP_NE= 0x10,
76 _OP_ADD= 0x11,
77 _OP_SUB= 0x12,
78 _OP_MUL= 0x13,
79 _OP_DIV= 0x14,
80 _OP_MOD= 0x15,
81 _OP_BITW= 0x16,
82 _OP_RETURN= 0x17,
83 _OP_LOADNULLS= 0x18,
84 _OP_LOADROOT= 0x19,
85 _OP_LOADBOOL= 0x1A,
86 _OP_DMOVE= 0x1B,
87 _OP_JMP= 0x1C,
88 _OP_JCMP= 0x1D,
89 _OP_JZ= 0x1E,
90 _OP_SETOUTER= 0x1F,
91 _OP_GETOUTER= 0x20,
92 _OP_NEWOBJ= 0x21,
93 _OP_APPENDARRAY= 0x22,
94 _OP_COMPARITH= 0x23,
95 _OP_INC= 0x24,
96 _OP_INCL= 0x25,
97 _OP_PINC= 0x26,
98 _OP_PINCL= 0x27,
99 _OP_CMP= 0x28,
100 _OP_EXISTS= 0x29,
101 _OP_INSTANCEOF= 0x2A,
102 _OP_AND= 0x2B,
103 _OP_OR= 0x2C,
104 _OP_NEG= 0x2D,
105 _OP_NOT= 0x2E,
106 _OP_BWNOT= 0x2F,
107 _OP_CLOSURE= 0x30,
108 _OP_YIELD= 0x31,
109 _OP_RESUME= 0x32,
110 _OP_FOREACH= 0x33,
111 _OP_POSTFOREACH= 0x34,
112 _OP_CLONE= 0x35,
113 _OP_TYPEOF= 0x36,
114 _OP_PUSHTRAP= 0x37,
115 _OP_POPTRAP= 0x38,
116 _OP_THROW= 0x39,
117 _OP_NEWSLOTA= 0x3A,
118 _OP_GETBASE= 0x3B,
119 _OP_CLOSE= 0x3C
122 struct VXInstructionDesc
124 const char *name;
127 struct VXInstruction
129 VXInstruction()
133 VXInstruction(VXOpcode _op,VXInteger a0=0,VXInteger a1=0,VXInteger a2=0,VXInteger a3=0)
135 op = _op;
136 _arg0 = (unsigned char)a0;
137 _arg1 = (VXInteger)a1;
138 _arg2 = (unsigned char)a2;
139 _arg3 = (unsigned char)a3;
142 VXInteger _arg1;
143 unsigned char op;
144 unsigned char _arg0;
145 unsigned char _arg2;
146 unsigned char _arg3;
149 typedef VXVector<VXInstruction> VXInstructionVec;
152 void FindOuter(VXState* v, VXObject &target, VXObject *stackindex);
153 void RelocateOuters(VXState* v);
154 void CloseOuters(VXState* v, VXObject *stackindex);
156 bool CallMetaMethod(VXState* v,
157 VXObject &closure,
158 VXMetaMethod mm,
159 VXInteger nparams,
160 VXObject &outres);
162 bool ArithMetaMethod(VXState* v,
163 VXInteger op,
164 const VXObject &o1,
165 const VXObject &o2,
166 VXObject &dest);
168 bool Return(VXState* v,
169 VXInteger _arg0,
170 VXInteger _arg1,
171 VXObject &retval);
172 //new stuff
173 bool ARITH_OP(VXState* v,
174 VXUnsignedInteger op,
175 VXObject &trg,
176 const VXObject &o1,
177 const VXObject &o2);
179 bool BW_OP(VXState* v,
180 VXUnsignedInteger op,
181 VXObject &trg,
182 const VXObject &o1,
183 const VXObject &o2);
185 bool NEG_OP(VXState* v,
186 VXObject &trg,
187 const VXObject &o1);
189 bool CMP_OP(VXState* v,
190 VXInteger op,
191 const VXObject &o1,
192 const VXObject &o2,
193 VXObject &res);
195 bool CLOSURE_OP(VXState* v,
196 VXObject &target,
197 VXFuncProtoObj *func);
199 bool CLASS_OP(VXState* v,
200 VXObject &target,
201 VXInteger base,
202 VXInteger attrs);
203 //return true if the loop is finished
205 bool FOREACH_OP(VXState* v,
206 VXObject &o1,
207 VXObject &o2,
208 VXObject &o3,
209 VXObject &o4,
210 VXInteger arg_2,
211 int exitpos,
212 int &jump);
214 bool PLOCAL_INC(VXState* v,
215 VXInteger op,
216 VXObject &target,
217 VXObject &a,
218 VXObject &incr);
220 bool DerefInc(VXState* v,
221 VXInteger op,
222 VXObject &target,
223 VXObject &self,
224 VXObject &key,
225 VXObject &incr,
226 bool postfix,
227 VXInteger arg0);
231 #endif // _VXOPCODES_H_