EnglishРусский  

   ..

   vm.c

   vm.h

   vmload.c

   vmload.h

   vmres.c

   vmres.h

   vmrun.c

   vmrun.h

   vmtype.c

   vmtype.h

Ads

Perfect Automation tool
All-In-One: Script editor, Launcher, Scheduler, Keyboard & Mouse Recorder. Try now!

CreateInstall
Freeware and commercial installers.

Cell Phone Batteries
Batteries Plus offers batteries for laptop, camcorder, cell phone, camera.

Gentee needs your help!
How to advertise with us
 
laptop battery

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