EnglishРусский  

   ..

   vm.c

   vm.h

   vm-a.h

   vmload.c

   vmload.h

   vmres.c

   vmres.h

   vmrun.c

   vmrun.h

   vmrun-a.c

   vmtype.c

   vmtype.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.

source\src\vm\vm-a.h
  1 /******************************************************************************
  2 *
  3 * Copyright (C) 2006, The Gentee Group. All rights reserved. 
  4 * This file is part of the Gentee open source project - http://www.gentee.com. 
  5 * 
  6 * THIS FILE IS PROVIDED UNDER THE TERMS OF THE GENTEE LICENSE ("AGREEMENT"). 
  7 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE CONSTITUTES RECIPIENTS 
  8 * ACCEPTANCE OF THE AGREEMENT.
  9 *
 10 * ID: vm 18.10.06 0.0.A.
 11 *
 12 * Author: Alexey Krivonogov ( gentee )
 13 *
 14 * Summary: Functions, structures and defines of the Gentee virtual machine.
 15 * 
 16 ******************************************************************************/
 17 
 18 #ifndef _VM_
 19 #define _VM_
 20 
 21    #ifdef __cplusplus               
 22       extern "C" {                 
 23    #endif // __cplusplus      
 24 
 25 #include "../common/hash.h"
 26 #include "../common/msg.h"
 27 #include "../common/collection.h"
 28 #include "../bytecode/cmdlist.h"
 29 
 30 #define   KERNEL_COUNT  1024  // The count of the VM kernel commands
 31 #define   VAR_SIZE      1024  // Stack limit size of variables
 32 
 33 #ifdef GASM  // Stack shifts
 34    #define  SSI1 (-1)
 35    #define  SSI2 (-2)
 36    #define  SSI3 (-3)
 37    #define  SSI4 (-4)
 38    #define  SSL1 (-1)  // shift long
 39    #define  SSL2 (-3)
 40    #define  SSAE  -=
 41    #define  SSSE  +=
 42    #define  SSA   -
 43    #define  SSS   +
 44    #define  SSAA  --
 45    #define  SSSS  ++
 46 #else
 47    #define  SSI1 1
 48    #define  SSI2 2
 49    #define  SSI3 3
 50    #define  SSI4 4
 51    #define  SSL1 2  // shift long
 52    #define  SSL2 4
 53    #define  SSAE  +=
 54    #define  SSSE  -=
 55    #define  SSA   +
 56    #define  SSS   -
 57    #define  SSAA  ++
 58    #define  SSSS  --
 59 #endif
 60 
 61 /*-----------------------------------------------------------------------------
 62 *
 63 * ID: gehead 19.10.06 0.0.A.
 64 * 
 65 * Summary: The structure type of the virtual machine.
 66 *  
 67 -----------------------------------------------------------------------------*/
 68 
 69 typedef struct
 70 {
 71    pvoid   ptr;     // The memory pointer
 72    pubyte  top;     // The free pointer
 73    pubyte  end;     // The end pointer
 74    pvoid   next;    // The next vmmanager
 75 } vmmanager, * pvmmanager;
 76 
 77 typedef struct
 78 {
 79    arr   objtbl;    // The table of the objects of the current VM.
 80    hash  objname;   // The table of the names of objects of the current VM.
 81 //   uint  stacksize; // The stack size
 82    uint  count;     // The count of the objects
 83    pvmmanager   pmng;  // The current vmmanager
 84    collect  resource;  // Resources
 85 
 86    uint  ipack;      // 1 if the current loading object is packed
 87    uint  isize;      // The input size of the current loading object
 88    uint  icnv;       // converting shift;
 89    uint  loadmode;   // 0 - if loading from GE otherwise loading from G
 90    uint  countinit;  // The count of the initialized id
 91    uint  pos;        // Pos for run-time error compiling
 92    uint  irescnv;    // shift for converting resources CResload
 93 } vm, * pvm;
 94 
 95 /*-----------------------------------------------------------------------------
 96 *
 97 * ID: vmtype! 19.10.06 0.0.A.
 98 * 
 99 * Summary: The types of objects of the VM.
100 *  
101 -----------------------------------------------------------------------------*/
102 
103 #define  OVM_NONE       0      // Not defined command
104 #define  OVM_STACKCMD   0x01   // System command
105 #define  OVM_PSEUDOCMD  0x02   // Pseudo System command
106 #define  OVM_BYTECODE   0x03   // Byte-code
107 #define  OVM_EXFUNC     0x04   // Executable function. It can be 'stdcall' or 
108                                // 'cdecl' machine code function.
109 #define  OVM_TYPE       0x05   // Type
110 #define  OVM_GLOBAL     0x06   // Global variable
111 #define  OVM_DEFINE     0x07   // Macros definitions
112 #define  OVM_IMPORT     0x08   // Import functions from external files
113 #define  OVM_RESOURCE   0x09   // Resources !!! must be realized in GE!
114 #define  OVM_ALIAS      0x0A   // Alias (link) object
115 
116 /*-----------------------------------------------------------------------------
117 *
118 * ID: vmflags 19.10.06 0.0.A.
119 * 
120 * Summary: The flags of objects of the VM.
121 *  
122 -----------------------------------------------------------------------------*/
123 
124 // Common flags
125 #define GHCOM_NAME      0x0001    // Имеется имя - объект импортируем
126 //#define GHCOM_ALLOC     0x0002    // Указано количество отводимой памяти
127 #define GHCOM_PACK      0x0002     // Данные упакованы bwd
128 
129 // OVM_BYTECODE
130 #define GHBC_ENTRY      0x000100    // Выполнить после загрузки всего байт-кода
131 #define GHBC_MAIN       0x000200    // Выполнить если он загрузился последним с таким флагом
132 #define GHBC_RESULT     0x000400    // Требуется дополнительный параметр тип - возвращаемое значение при вызове
133 #define GHBC_TEXT       0x000800    // Байт-код является text функцией
134 #define GHBC_METHOD     0x001000    // Байт-код является method
135 #define GHBC_OPERATOR   0x002000    // Байт-код является operator
136 #define GHBC_PROPERTY   0x004000    // Байт-код является property
137 
138 // OVM_EXFUNC
139 #define GHEX_CDECL      0x010000    // Тип функции __cdecl
140 #define GHEX_FLOAT      0x020000    // Возвращаемое значение double или float
141 #define GHEX_SYSCALL    0x040000    // Вызов системной функции по номеру
142 #define GHEX_IMPORT     0x080000    // Импортируемая функция - 
143                                     // есть оригинальное имя и id parent файла
144 
145 // OVM_DEFINE
146 #define GHDF_EXPORT     0x000100    // Экспортировать макросы
147 #define GHDF_NAMEDEF    0x000200    // Макросы без $
148 
149 // OVM_IMPORT 
150 #define GHIMP_LINK      0x000100    // Прилинкованная dll библиотека
151 #define GHIMP_CDECL     0x000200    // Импорт __cdecl функций 
152 #define GHIMP_EXE       0x000400    // Указан относительный путь по отношению к exe файлу
153 
154 // OVM_GLOBAL
155 //#define GHGL_DATA       0x000100    // Есть данные инициализации
156 
157 // OVM_TYPE
158 #define GHTY_INHERIT    0x000100    // Имеется наследование ( объект-родитель )
159 #define GHTY_INDEX      0x000200    // Имеется index 
160 #define GHTY_INITDEL    0x000400    // Имеется метод  init и deinit 
161 #define GHTY_EXTFUNC    0x000800    // Имеется метод  oftype =%
162 #define GHTY_ARRAY      0x001000    // Имеются методы array
163 #define GHTY_PROTECTED  0x002000    // Protected type
164 #define GHTY_STACK      0x010000    // Тип целиком размещается в стэке
165 
166 // RUNTIME flags
167 #define GHRT_MAYCALL    0x01000000  // for OVM_STACKCMD OVM_BYTECODE OVM_EXFUNC
168 #define GHRT_INIT       0x02000000  // Тип требует инициализации (возможно в подтипе)
169 #define GHRT_DELETE     0x04000000  // Тип требует деинициализации ( возможно в подтипе)
170 #define GHRT_LOADED     0x08000000  // The object was initialized in vm_execute
171 #define GHRT_INCLUDED   0x10000000  // The object was proceed at the end of module compile
172 #define GHRT_PRIVATE    0x20000000  // The private object 
173 #define GHRT_ALIAS      0x40000000  // There is alias
174 #define GHRT_SKIP       0x80000000  // Skip object for GE 
175 
176 /*-----------------------------------------------------------------------------
177 *
178 * ID: vmaddflags 19.10.06 0.0.A.
179 * 
180 * Summary: The flags for vm_addobj.
181 *  
182 -----------------------------------------------------------------------------*/
183 
184 //#define VMADD_CRC       0x0001  // CRC control
185 
186 /*-----------------------------------------------------------------------------
187 *
188 * ID: vmobj 19.10.06 0.0.A.
189 * 
190 * Summary: The structure type of the object of the virtual machine. Each item
191   of the virtual machine must begin with this structure.
192 *  
193 -----------------------------------------------------------------------------*/
194 #pragma pack(push, 1)
195 
196 typedef struct
197 {
198    uint      size;       // The full size of this object
199    ubyte     type;       // The type. [- vmtype -]
200    uint      flag;       // The flags.
201    pubyte    name;       // The object name.
202    uint      id;         // Object Identifier in the VM. It equals the array 
203                          // index.
204    uint      nextname;   // The ID of the next object with the same name.
205 } vmobj, * pvmobj;
206 
207 #pragma pack(pop)
208 
209 /*-----------------------------------------------------------------------------
210 *
211 * ID: exttype 19.10.06 0.0.A.
212 * 
213 * Summary: The structure of subtypes.
214 *  
215 -----------------------------------------------------------------------------*/
216 
217 /*-----------------------------------------------------------------------------
218 *
219 * ID: subtype 19.10.06 0.0.A.
220 * 
221 * Summary: The structure of subtypes or variables.
222 *  
223 -----------------------------------------------------------------------------*/
224 #pragma pack(push, 1)
225 
226 typedef struct 
227 {
228    uint       type;     // идентификатор типа
229    uint       off;      // смещение данного поля или переменной
230                         // для переменной смещение в uint с alignment sizeof( uint )
231    pubyte     name;     // указатель на имя поля или переменной
232    uint       oftype;   // OF type.
233    ubyte      flag;     // VAR flags
234    ubyte      dim;      // Dimension.
235    ushort     data;     // Имееются данные инициализации
236    puint      ptr;      // Dimensions + Initializing Data 
237 } vartype, * pvartype;
238 
239 #pragma pack(pop)
240 
241 #define  FTYPE_INIT    0   // @init()
242 #define  FTYPE_DELETE  1   // @delete()
243 #define  FTYPE_OFTYPE  2   // @oftype()
244 #define  FTYPE_COLLECTION  3   // = %{}
245 #define  FTYPE_ARRAY       4   // @array(), @array(,), @array(,,) и т.д.
246 
247 
248 /*-----------------------------------------------------------------------------
249 *
250 * ID: ovmtype 19.10.06 0.0.A.
251 * 
252 * Summary: The structure type of the OVM_TYPE object of the VM.
253 *  
254 -----------------------------------------------------------------------------*/
255 
256 typedef struct 
257 {
258    vmobj     vmo;      // vmobject
259    uint      size;     // the size of the type
260    uint      stsize;   // The count of uints in the stack.
261                        // double, long, ulong - 2
262    uint      inherit;  // Тип-родитель
263    vartype   index;    // Тип по умолчанию для элементов возвращаемых 
264                        // по методу index. По умолчанию это uint.
265    
266    uint      ftype[ MAX_MSR + 4 ];  // Type functions
267    uint      count;    // количество подтипов// - для STRUCT.
268    pvartype  children;   // Subtypes
269 } ovmtype, * povmtype;
270 
271 /*-----------------------------------------------------------------------------
272 *
273 * ID: var 19.10.06 0.0.A.
274 * 
275 * Summary: The type for parameters and local variables
276 *  
277 -----------------------------------------------------------------------------*/
278 
279 /*
280    Parameters and variables
281 
282    При вызове функции
283      Идут передаваемые параметры.
284    
285    puint  // The pointer to local variables. Локальные переменные могут 
286           // располагаться в стэке, а могут в отдельном memory block.
287           // if varsize > 1024 -> отдельный memory
288    uint   [setcount]  // признаки инициализировано ли каждое из множеств 
289           // локальных переменных
290 */
291 
292 /*-----------------------------------------------------------------------------
293 *
294 * ID: vmfunc 19.10.06 0.0.A.
295 * 
296 * Summary: The structure type of the OVM_STACKCMD and OVM_BYTECODE object of the VM. It is used 
297   for embedded stack commands.
298 *  
299 -----------------------------------------------------------------------------*/
300 #pragma pack(push, 1)
301 
302 typedef struct 
303 {
304    vmobj     vmo;      // Object of VM
305    pvartype  ret;
306    ubyte     dwret;      // The count of return uints.
307    ubyte     parcount;   // The count of parameters
308    pvartype  params;     // The parameters
309    ubyte     parsize;    // The summary size of parameters in uints.
310    pvoid     func;       // Proceeding function or the pointer to the byte-code
311 } vmfunc, * pvmfunc;
312 
313 #pragma pack(pop)
314 
315 /*-----------------------------------------------------------------------------
316 *
317 * ID: ovmstack 19.10.06 0.0.A.
318 * 
319 * Summary: The structure type of the OVM_STACKCMD object of the VM. It is used 
320   for embedded stack commands.
321 *  
322 -----------------------------------------------------------------------------*/
323 
324 typedef struct 
325 {
326    vmfunc    vmf;        // Parameters description 
327    int       topshift;   // The shift (in uints) of the top of the stack
328    int       cmdshift;   // The shift (in uints) of the byte-code pointer.
329 } ovmstack, * povmstack;
330 
331 /*-----------------------------------------------------------------------------
332 *
333 * ID: varb 19.10.06 0.0.A.
334 * 
335 * Summary: The structure type of the block of variables. 
336 *  
337 -----------------------------------------------------------------------------*/
338 
339 typedef struct 
340 {
341    ushort    count;      // The number of variables of the block
342    ushort    first;      // The number of the first variable
343    uint      size;       // The summary size of varaiables in uints
344    uint      off;        // The offset of the block
345 } varset, * pvarset;
346 
347 /*-----------------------------------------------------------------------------
348 *
349 * ID: ovmbcode 19.10.06 0.0.A.
350 * 
351 * Summary: The structure type of the OVM_BYTECODE object of the VM. 
352 *  
353 -----------------------------------------------------------------------------*/
354 
355 typedef struct 
356 {
357    vmfunc    vmf;        // Parameters description 
358 //   ushort    varcount;   // The number of local variables
359    pvartype  vars;       //
360    uint      varsize;    // The summary size of all variables in uints
361    ushort    setcount;   // Количество блоков локальных переменных
362    pvarset   sets;       // Указатель на структуры varset
363    uint      bcsize;     // Size of the byte-code
364 } ovmbcode, * povmbcode;
365 
366 /*-----------------------------------------------------------------------------
367 *
368 * ID: ovmfunc 19.10.06 0.0.A.
369 * 
370 * Summary: The structure type of the OVM_EXFUNC object of the VM. 
371 *  
372 -----------------------------------------------------------------------------*/
373 
374 typedef struct 
375 {
376    vmfunc    vmf;        // Parameters description 
377    pubyte    original;   // Original name of the function ( if GHEX_IMPORT )
378    uint      import;     // import parent id ( if GHEX_IMPORT )
379 } ovmfunc, * povmfunc;
380 
381 /*-----------------------------------------------------------------------------
382 *
383 * ID: ovmglobal 19.10.06 0.0.A.
384 * 
385 * Summary: The structure type of the OVM_GLOBAL object of the VM. 
386 *  
387 -----------------------------------------------------------------------------*/
388 typedef struct 
389 {
390    vmobj      vmo;         // The object of VM
391    pvartype   type;        // Type of global
392    pubyte     pval;        // Pointer to the value
393 } ovmglobal, * povmglobal;
394 
395 /*-----------------------------------------------------------------------------
396 *
397 * ID: ovmdefine 19.10.06 0.0.A.
398 * 
399 * Summary: The structure type of the OVM_DEFINE object of the VM. 
400 *  
401 -----------------------------------------------------------------------------*/
402 typedef struct 
403 {
404    vmobj      vmo;      // The object of VM
405    uint       count;    // Count of defines
406    pvartype   macros;   // Macros
407 } ovmdefine, * povmdefine;
408 
409 /*-----------------------------------------------------------------------------
410 *
411 * ID: ovmimport 19.10.06 0.0.A.
412 * 
413 * Summary: The structure type of the OVM_IMPORT object of the VM. 
414 *  
415 -----------------------------------------------------------------------------*/
416 typedef struct 
417 {
418    vmobj      vmo;      // The object of VM
419    pubyte     filename; // The name of the file
420    uint       size;  // The size of DLL if GHIMP_LINK
421    pubyte     data;  // The body of DLL if GHIMP_LINK
422    pvoid      handle;   // The handle of the library
423 } ovmimport, * povmimport;
424 
425 /*-----------------------------------------------------------------------------
426 *
427 * ID: ovmalias 06.07.07 0.0.A.
428 * 
429 * Summary: The structure type of the OVM_ALIAS object of the VM. 
430 *  
431 -----------------------------------------------------------------------------*/
432 typedef struct 
433 {
434    vmobj      vmo;      // The object of VM
435    uint       idlink;   // The id of linked object
436 } ovmalias, * povmalias;
437 
438 // Flags for vm_getid
439 #define GETID_METHOD   0x01  // search method
440 #define GETID_OPERATOR 0x02  // search operator
441 #define GETID_OFTYPE   0x04  // params + oftype in collection
442 
443 //--------------------------------------------------------------------------
444 
445 extern vm    _vm;
446 extern pvm   _pvm;
447 
448 #define  PCMD( y )  *(( puint )_vm.objtbl.data.data + (y))
449 
450 void       STDCALL vm_deinit( void );
451 void       STDCALL vm_init( void );
452 pvmfunc    STDCALL vm_find( pubyte name, uint count, puint pars );
453 uint       STDCALL vm_execute( uint main );
454 void       STDCALL vm_clearname( uint id );
455 uint       STDCALL vm_getid( pstr name, uint flags, pcollect colpars );
456 
457    #ifdef __cplusplus              
458       }                            
459    #endif // __cplusplus
460 
461 #endif // _VM_
462 
463