EnglishРусский  

   ..

   common.c

   common.h

   gefile.h

   geload.c

   gesave.c

   types.h

   vm.c

   vm.h

The project is closed! You can look at a new scripting language. It is available on GitHub.
Also, try our open source cross-platform automation software.

Ads

Installer and installation software
Commercial and Freeware installers.

  1 #ifndef _VM_
  2 #define _VM_
  3 
  4    #ifdef __cplusplus               
  5       extern "C" {                 
  6    #endif // __cplusplus      
  7 
  8 #include "bytecode.h"
  9 
 10 #define   KERNEL_COUNT  1024  // The count of the VM kernel commands
 11 #define   VAR_SIZE      1024  // Stack limit size of variables
 12 
 13 
 14 
 15 /*-----------------------------------------------------------------------------
 16 * Summary: The types of objects of the VM.
 17 -----------------------------------------------------------------------------*/
 18 
 19 #define  OVM_NONE       0      // Not defined command
 20 #define  OVM_STACKCMD   0x01   // System command
 21 #define  OVM_PSEUDOCMD  0x02   // Pseudo System command
 22 #define  OVM_BYTECODE   0x03   // Byte-code
 23 #define  OVM_EXFUNC     0x04   // Executable function. It can be 'stdcall' or 
 24                                // 'cdecl' machine code function.
 25 #define  OVM_TYPE       0x05   // Type
 26 #define  OVM_GLOBAL     0x06   // Global variable
 27 #define  OVM_DEFINE     0x07   // Macros definitions
 28 #define  OVM_IMPORT     0x08   // Import functions from external files
 29 #define  OVM_RESOURCE   0x09   // Resources !!! must be realized in GE!
 30 #define  OVM_ALIAS      0x0A   // Alias (link) object
 31 
 32 /*-----------------------------------------------------------------------------
 33 * Summary: The flags of objects of the VM.
 34 -----------------------------------------------------------------------------*/
 35 
 36 // Common flags
 37 #define GHCOM_NAME      0x0001    // Имеется имя - объект импортируем
 38 #define GHCOM_PACK      0x0002     // Данные упакованы bwd
 39 
 40 // OVM_BYTECODE
 41 #define GHBC_ENTRY      0x000100    // Выполнить после загрузки всего байт-кода
 42 #define GHBC_MAIN       0x000200    // Выполнить если он загрузился последним с таким флагом
 43 #define GHBC_RESULT     0x000400    // Требуется дополнительный параметр тип - возвращаемое значение при вызове
 44 #define GHBC_TEXT       0x000800    // Байт-код является text функцией
 45 #define GHBC_METHOD     0x001000    // Байт-код является method
 46 #define GHBC_OPERATOR   0x002000    // Байт-код является operator
 47 #define GHBC_PROPERTY   0x004000    // Байт-код является property
 48 
 49 // OVM_EXFUNC
 50 #define GHEX_CDECL      0x010000    // Тип функции __cdecl
 51 #define GHEX_FLOAT      0x020000    // Возвращаемое значение double или float
 52 #define GHEX_SYSCALL    0x040000    // Вызов системной функции по номеру
 53 #define GHEX_IMPORT     0x080000    // Импортируемая функция - 
 54                                     // есть оригинальное имя и id parent файла
 55 
 56 // OVM_DEFINE
 57 #define GHDF_EXPORT     0x000100    // Экспортировать макросы
 58 #define GHDF_NAMEDEF    0x000200    // Макросы без $
 59 
 60 // OVM_IMPORT 
 61 #define GHIMP_LINK      0x000100    // Прилинкованная dll библиотека
 62 #define GHIMP_CDECL     0x000200    // Импорт __cdecl функций 
 63 #define GHIMP_EXE       0x000400    // Указан относительный путь по отношению к exe файлу
 64 
 65 
 66 // OVM_TYPE
 67 #define GHTY_INHERIT    0x000100    // Имеется наследование ( объект-родитель )
 68 #define GHTY_INDEX      0x000200    // Имеется index 
 69 #define GHTY_INITDEL    0x000400    // Имеется метод  init и deinit 
 70 #define GHTY_EXTFUNC    0x000800    // Имеется метод  oftype =%
 71 #define GHTY_ARRAY      0x001000    // Имеются методы array
 72 #define GHTY_PROTECTED  0x002000    // Protected type
 73 #define GHTY_STACK      0x010000    // Тип целиком размещается в стэке
 74 
 75 // RUNTIME flags
 76 #define GHRT_MAYCALL    0x01000000  // for OVM_STACKCMD OVM_BYTECODE OVM_EXFUNC
 77 #define GHRT_INIT       0x02000000  // Тип требует инициализации (возможно в подтипе)
 78 #define GHRT_DELETE     0x04000000  // Тип требует деинициализации ( возможно в подтипе)
 79 #define GHRT_LOADED     0x08000000  // The object was initialized in vm_execute
 80 #define GHRT_INCLUDED   0x10000000  // The object was proceed at the end of module compile
 81 #define GHRT_PRIVATE    0x20000000  // The private object 
 82 #define GHRT_ALIAS      0x40000000  // There is alias
 83 
 84 
 85 /*-----------------------------------------------------------------------------
 86 * Summary: The structure type of the object of the virtual machine. Each item
 87   of the virtual machine must begin with this structure.
 88 -----------------------------------------------------------------------------*/
 89 #pragma pack(push, 1)
 90 
 91 typedef struct
 92 {
 93    uint      size;       // The full size of this object
 94    ubyte     type;       // The type. [- vmtype -]
 95    uint      flag;       // The flags.
 96    pubyte    name;       // The object name.
 97    uint      id;         // Object Identifier in the VM. It equals the array 
 98                          // index.
 99    uint      nextname;   // The ID of the next object with the same name.
100 } vmobj, * pvmobj;
101 
102 #pragma pack(pop)
103 
104 
105 /*-----------------------------------------------------------------------------
106 * Summary: The structure of subtypes or variables.
107 -----------------------------------------------------------------------------*/
108 
109 typedef struct 
110 {
111    uint       type;     // идентификатор типа
112    uint       off;      // смещение данного поля или переменной
113                         // для переменной смещение в uint с alignment sizeof( uint )
114    pubyte     name;     // указатель на имя поля или переменной
115    uint       oftype;   // OF type.
116    ubyte      dim;      // Dimension.
117    ubyte      flag;     // VAR flags
118    ushort     data;     // Имееются данные инициализации
119    puint      ptr;      // Dimensions + Initializing Data 
120 } vartype, * pvartype;
121 
122 #define  FTYPE_INIT    0   // @init()
123 #define  FTYPE_DELETE  1   // @delete()
124 #define  FTYPE_OFTYPE  2   // @oftype()
125 #define  FTYPE_COLLECTION  3   // = %{}
126 #define  FTYPE_ARRAY       4   // @array(), @array(,), @array(,,) и т.д.
127 
128 
129 /*-----------------------------------------------------------------------------
130 * Summary: The structure type of the OVM_TYPE object of the VM.
131 -----------------------------------------------------------------------------*/
132 
133 typedef struct 
134 {
135    vmobj     vmo;      // vmobject
136    uint      size;     // the size of the type
137    uint      stsize;   // The count of uints in the stack.
138                        // double, long, ulong - 2
139    uint      inherit;  // Тип-родитель
140    vartype   index;    // Тип по умолчанию для элементов возвращаемых 
141                        // по методу index. По умолчанию это uint.
142    
143    uint      ftype[ MAX_MSR + 4 ];  // Type functions
144    uint      count;    // количество подтипов// - для STRUCT.
145    pvartype  children;   // Subtypes
146 } ovmtype, * povmtype;
147 
148 /*-----------------------------------------------------------------------------
149 * Summary: The structure type of the OVM_STACKCMD and OVM_BYTECODE object of the VM. It is used 
150   for embedded stack commands.
151 -----------------------------------------------------------------------------*/
152 #pragma pack(push, 1)
153 
154 typedef struct 
155 {
156    vmobj     vmo;      // Object of VM
157    pvartype  ret;
158    ubyte     dwret;      // The count of return uints.
159    ubyte     parcount;   // The count of parameters
160    pvartype  params;     // The parameters
161    ubyte     parsize;    // The summary size of parameters in uints.
162    pvoid     func;       // Proceeding function or the pointer to the byte-code
163 } vmfunc, * pvmfunc;
164 
165 #pragma pack(pop)
166 
167 /*-----------------------------------------------------------------------------
168 * Summary: The structure type of the OVM_STACKCMD object of the VM. It is used 
169   for embedded stack commands.
170 -----------------------------------------------------------------------------*/
171 
172 typedef struct 
173 {
174    vmfunc    vmf;        // Parameters description 
175    int       topshift;   // The shift (in uints) of the top of the stack
176    int       cmdshift;   // The shift (in uints) of the byte-code pointer.
177 } ovmstack, * povmstack;
178 
179 /*-----------------------------------------------------------------------------
180 * Summary: The structure type of the block of variables. 
181 -----------------------------------------------------------------------------*/
182 
183 typedef struct 
184 {
185    ushort    count;      // The number of variables of the block
186    ushort    first;      // The number of the first variable
187    uint      size;       // The summary size of varaiables in uints
188    uint      off;        // The offset of the block
189 } varset, * pvarset;
190 
191 /*-----------------------------------------------------------------------------
192 * Summary: The structure type of the OVM_BYTECODE object of the VM. 
193 -----------------------------------------------------------------------------*/
194 
195 typedef struct 
196 {
197    vmfunc    vmf;        // Parameters description 
198    pvartype  vars;       //
199    uint      varsize;    // The summary size of all variables in uints
200    ushort    setcount;   // Количество блоков локальных переменных
201    pvarset   sets;       // Указатель на структуры varset
202    uint      bcsize;     // Size of the byte-code
203 } ovmbcode, * povmbcode;
204 
205 /*-----------------------------------------------------------------------------
206 * Summary: The structure type of the OVM_EXFUNC object of the VM. 
207 -----------------------------------------------------------------------------*/
208 
209 typedef struct 
210 {
211    vmfunc    vmf;        // Parameters description 
212    pubyte    original;   // Original name of the function ( if GHEX_IMPORT )
213    uint      import;     // import parent id ( if GHEX_IMPORT )
214 } ovmfunc, * povmfunc;
215 
216 /*-----------------------------------------------------------------------------
217 * Summary: The structure type of the OVM_GLOBAL object of the VM. 
218 -----------------------------------------------------------------------------*/
219 typedef struct 
220 {
221    vmobj      vmo;         // The object of VM
222    pvartype   type;        // Type of global
223    pubyte     pval;        // Pointer to the value
224 } ovmglobal, * povmglobal;
225 
226 /*-----------------------------------------------------------------------------
227 * Summary: The structure type of the OVM_DEFINE object of the VM. 
228 -----------------------------------------------------------------------------*/
229 typedef struct 
230 {
231    vmobj      vmo;      // The object of VM
232    uint       count;    // Count of defines
233    pvartype   macros;   // Macros
234 } ovmdefine, * povmdefine;
235 
236 /*-----------------------------------------------------------------------------
237 * Summary: The structure type of the OVM_IMPORT object of the VM. 
238 -----------------------------------------------------------------------------*/
239 typedef struct 
240 {
241    vmobj      vmo;      // The object of VM
242    pubyte     filename; // The name of the file
243    uint       size;  // The size of DLL if GHIMP_LINK
244    pubyte     data;  // The body of DLL if GHIMP_LINK
245    pvoid      handle;   // The handle of the library
246 } ovmimport, * povmimport;
247 
248 /*-----------------------------------------------------------------------------
249 * Summary: The structure type of the OVM_ALIAS object of the VM. 
250 -----------------------------------------------------------------------------*/
251 typedef struct 
252 {
253    vmobj      vmo;      // The object of VM
254    uint       idlink;   // The id of linked object
255 } ovmalias, * povmalias;
256 
257 //--------------------------------------------------------------------------
258 
259 
260 #define  BCODE(x)  (( povmbcode )x->func)
261 
262 //--------------------------------------------------------------------------
263 
264 uint  STDCALL  vmres_addstr( pvmEngine pThis, pubyte ptr );
265 pstr  STDCALL  vmres_getstr( pvmEngine pThis, uint index );
266 
267 
268 #define  PCMD( y )  *(( puint )pThis->_vm.objtbl.data.data + (y))
269 
270 void       STDCALL vm_deinit( pvmEngine pThis );
271 void       STDCALL vm_init( pvmEngine pThis );
272 
273 
274 
275 pvmmanager STDCALL vmmng_new( pvmEngine pThis );
276 void       STDCALL vmmng_destroy( pvmEngine pThis );
277 pubyte     STDCALL vmmng_begin( pvmEngine pThis, uint size );
278 uint       STDCALL vmmng_end( pvmEngine pThis, pubyte end  );
279 
280 
281 
282    #ifdef __cplusplus              
283       }                            
284    #endif // __cplusplus
285 
286 #endif // _VM_
287 
288