Torque3D Documentation / _generateds / codeInterpreter.h

codeInterpreter.h

Engine/source/console/codeInterpreter.h

More...

Classes:

class

Frame data for a foreach/foreach$ loop.

class

Information for an object iterator loop.

class

Information for a string iterator loop.

Public Enumerations

enum
OPCodeReturn {
  exitCode = -1
  success = 0
  breakContinue = 1
}

Detailed Description

Public Enumerations

OPCodeReturn

Enumerator

exitCode = -1
success = 0
breakContinue = 1
  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _CODEINTERPRETER_H_
 25#define _CODEINTERPRETER_H_
 26
 27#include "console/codeBlock.h"
 28#include "console/console.h"
 29#include "console/consoleInternal.h"
 30
 31/// Frame data for a foreach/foreach$ loop.
 32struct IterStackRecord
 33{
 34   /// If true, this is a foreach$ loop; if not, it's a foreach loop.
 35   bool mIsStringIter;
 36
 37   /// The iterator variable.
 38   Dictionary::Entry* mVariable;
 39
 40   /// Information for an object iterator loop.
 41   struct ObjectPos
 42   {
 43      /// The set being iterated over.
 44      SimSet* mSet;
 45
 46      /// Current index in the set.
 47      U32 mIndex;
 48   };
 49
 50   /// Information for a string iterator loop.
 51   struct StringPos
 52   {
 53      /// The raw string data on the string stack.
 54      StringStackPtr mString;
 55
 56      /// Current parsing position.
 57      U32 mIndex;
 58   };
 59
 60   union
 61   {
 62      ObjectPos mObj;
 63      StringPos mStr;
 64   } mData;
 65};
 66
 67enum OPCodeReturn
 68{
 69   exitCode = -1,
 70   success = 0,
 71   breakContinue = 1
 72};
 73
 74class CodeInterpreter
 75{
 76public:
 77   CodeInterpreter(CodeBlock *cb);
 78   ~CodeInterpreter();
 79
 80   ConsoleValueRef exec(U32 ip, 
 81                        StringTableEntry functionName,
 82                        Namespace *thisNamespace,
 83                        U32 argc, 
 84                        ConsoleValueRef *argv, 
 85                        bool noCalls, 
 86                        StringTableEntry packageName, 
 87                        S32 setFrame);
 88
 89   static void init();
 90
 91   // Methods
 92private:
 93   void parseArgs(U32 &ip);
 94
 95   /// Group op codes
 96   /// @{
 97
 98   OPCodeReturn op_func_decl(U32 &ip);
 99   OPCodeReturn op_create_object(U32 &ip);
100   OPCodeReturn op_add_object(U32 &ip);
101   OPCodeReturn op_end_object(U32 &ip);
102   OPCodeReturn op_finish_object(U32 &ip);
103   OPCodeReturn op_jmpiffnot(U32 &ip);
104   OPCodeReturn op_jmpifnot(U32 &ip);
105   OPCodeReturn op_jmpiff(U32 &ip);
106   OPCodeReturn op_jmpif(U32 &ip);
107   OPCodeReturn op_jmpifnot_np(U32 &ip);
108   OPCodeReturn op_jmpif_np(U32 &ip);
109   OPCodeReturn op_jmp(U32 &ip);
110   OPCodeReturn op_return_void(U32 &ip);
111   OPCodeReturn op_return(U32 &ip);
112   OPCodeReturn op_return_flt(U32 &ip);
113   OPCodeReturn op_return_uint(U32 &ip);
114   OPCodeReturn op_cmpeq(U32 &ip);
115   OPCodeReturn op_cmpgr(U32 &ip);
116   OPCodeReturn op_cmpge(U32 &ip);
117   OPCodeReturn op_cmplt(U32 &ip);
118   OPCodeReturn op_cmple(U32 &ip);
119   OPCodeReturn op_cmpne(U32 &ip);
120   OPCodeReturn op_xor(U32 &ip);
121   OPCodeReturn op_mod(U32 &ip);
122   OPCodeReturn op_bitand(U32 &ip);
123   OPCodeReturn op_bitor(U32 &ip);
124   OPCodeReturn op_not(U32 &ip);
125   OPCodeReturn op_notf(U32 &ip);
126   OPCodeReturn op_onescomplement(U32 &ip);
127   OPCodeReturn op_shr(U32 &ip);
128   OPCodeReturn op_shl(U32 &ip);
129   OPCodeReturn op_and(U32 &ip);
130   OPCodeReturn op_or(U32 &ip);
131   OPCodeReturn op_add(U32 &ip);
132   OPCodeReturn op_sub(U32 &ip);
133   OPCodeReturn op_mul(U32 &ip);
134   OPCodeReturn op_div(U32 &ip);
135   OPCodeReturn op_neg(U32 &ip);
136   OPCodeReturn op_inc(U32 &ip);
137   OPCodeReturn op_dec(U32 &ip);
138   OPCodeReturn op_setcurvar(U32 &ip);
139   OPCodeReturn op_setcurvar_create(U32 &ip);
140   OPCodeReturn op_setcurvar_array(U32 &ip);
141   OPCodeReturn op_setcurvar_array_varlookup(U32 &ip);
142   OPCodeReturn op_setcurvar_array_create(U32 &ip);
143   OPCodeReturn op_setcurvar_array_create_varlookup(U32 &ip);
144   OPCodeReturn op_loadvar_uint(U32 &ip);
145   OPCodeReturn op_loadvar_flt(U32 &ip);
146   OPCodeReturn op_loadvar_str(U32 &ip);
147   OPCodeReturn op_loadvar_var(U32 &ip);
148   OPCodeReturn op_savevar_uint(U32 &ip);
149   OPCodeReturn op_savevar_flt(U32 &ip);
150   OPCodeReturn op_savevar_str(U32 &ip);
151   OPCodeReturn op_savevar_var(U32 &ip);
152   OPCodeReturn op_setcurobject(U32 &ip);
153   OPCodeReturn op_setcurobject_internal(U32 &ip);
154   OPCodeReturn op_setcurobject_new(U32 &ip);
155   OPCodeReturn op_setcurfield(U32 &ip);
156   OPCodeReturn op_setcurfield_array(U32 &ip);
157   OPCodeReturn op_setcurfield_type(U32 &ip);
158   OPCodeReturn op_setcurfield_this(U32 &ip);
159   OPCodeReturn op_setcurfield_array_var(U32 &ip);
160   OPCodeReturn op_loadfield_uint(U32 &ip);
161   OPCodeReturn op_loadfield_flt(U32 &ip);
162   OPCodeReturn op_loadfield_str(U32 &ip);
163   OPCodeReturn op_savefield_uint(U32 &ip);
164   OPCodeReturn op_savefield_flt(U32 &ip);
165   OPCodeReturn op_savefield_str(U32 &ip);
166   OPCodeReturn op_str_to_uint(U32 &ip);
167   OPCodeReturn op_str_to_flt(U32 &ip);
168   OPCodeReturn op_str_to_none(U32 &ip);
169   OPCodeReturn op_flt_to_uint(U32 &ip);
170   OPCodeReturn op_flt_to_str(U32 &ip);
171   OPCodeReturn op_flt_to_none(U32 &ip);
172   OPCodeReturn op_uint_to_flt(U32 &ip);
173   OPCodeReturn op_uint_to_str(U32 &ip);
174   OPCodeReturn op_uint_to_none(U32 &ip);
175   OPCodeReturn op_copyvar_to_none(U32 &ip);
176   OPCodeReturn op_loadimmed_uint(U32 &ip);
177   OPCodeReturn op_loadimmed_flt(U32 &ip);
178   OPCodeReturn op_tag_to_str(U32 &ip);
179   OPCodeReturn op_loadimmed_str(U32 &ip);
180   OPCodeReturn op_docblock_str(U32 &ip);
181   OPCodeReturn op_loadimmed_ident(U32 &ip);
182   OPCodeReturn op_callfunc_resolve(U32 &ip);
183   OPCodeReturn op_callfunc(U32 &ip);
184   OPCodeReturn op_callfunc_pointer(U32 &ip);
185   OPCodeReturn op_callfunc_this(U32 &ip);
186   OPCodeReturn op_advance_str(U32 &ip);
187   OPCodeReturn op_advance_str_appendchar(U32 &ip);
188   OPCodeReturn op_advance_str_comma(U32 &ip);
189   OPCodeReturn op_advance_str_nul(U32 &ip);
190   OPCodeReturn op_rewind_str(U32 &ip);
191   OPCodeReturn op_terminate_rewind_str(U32 &ip);
192   OPCodeReturn op_compare_str(U32 &ip);
193   OPCodeReturn op_push(U32 &ip);
194   OPCodeReturn op_push_uint(U32 &ip);
195   OPCodeReturn op_push_flt(U32 &ip);
196   OPCodeReturn op_push_var(U32 &ip);
197   OPCodeReturn op_push_this(U32 &ip);
198   OPCodeReturn op_push_frame(U32 &ip);
199   OPCodeReturn op_assert(U32 &ip);
200   OPCodeReturn op_break(U32 &ip);
201   OPCodeReturn op_iter_begin_str(U32 &ip);
202   OPCodeReturn op_iter_begin(U32 &ip);
203   OPCodeReturn op_iter(U32 &ip);
204   OPCodeReturn op_iter_end(U32 &ip);
205   OPCodeReturn op_invalid(U32 &ip);
206
207   /// @}
208
209private:
210   CodeBlock *mCodeBlock;
211
212   /// Group exec arguments.
213   struct
214   {
215      StringTableEntry functionName;
216      Namespace *thisNamespace;
217      U32 argc;
218      ConsoleValueRef *argv;
219      bool noCalls;
220      StringTableEntry packageName;
221      S32 setFrame;
222   } mExec;
223
224   U32 mIterDepth;
225   F64 *mCurFloatTable;
226   char *mCurStringTable;
227   StringTableEntry mThisFunctionName;
228   bool mPopFrame;
229
230   // Add local object creation stack [7/9/2007 Black]
231   static const U32 objectCreationStackSize = 32;
232   U32 mObjectCreationStackIndex;
233   struct 
234   {
235      SimObject *newObject;
236      U32 failJump;
237   } mObjectCreationStack[objectCreationStackSize];
238
239   SimObject *mCurrentNewObject;
240   U32 mFailJump;
241   StringTableEntry mPrevField;
242   StringTableEntry mCurField;
243   SimObject *mPrevObject;
244   SimObject *mCurObject;
245   SimObject *mSaveObject;
246   SimObject *mThisObject;
247   Namespace::Entry *mNSEntry;
248   StringTableEntry mCurFNDocBlock;
249   StringTableEntry mCurNSDocBlock;
250   U32 mCallArgc;
251   ConsoleValueRef *mCallArgv;
252   CodeBlock *mSaveCodeBlock;
253
254   // note: anything returned is pushed to CSTK and will be invalidated on the next exec()
255   ConsoleValueRef mReturnValue;
256
257   U32 mCurrentInstruction;
258
259   static const S32 nsDocLength = 128;
260   char mNSDocBlockClass[nsDocLength];
261};
262
263#endif
264