home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / harbb30g.zip / DOC / vm.txt < prev    next >
Text File  |  1999-06-02  |  15KB  |  311 lines

  1. The Harbour virtual machine (VM)
  2.  
  3. Question :
  4.  
  5.   If a VM description is desirable, how should it be structured? (I
  6. propose plain text, with two main sections: VM description, Opcodes. The
  7. "Opcodes" section would describe every opcode: mnemonic, code, operands,
  8. description. I think I can maintain this section.)
  9.  
  10. Answer :
  11.  
  12. The VM is formed by the main execution loop and several subsystems, each of
  13. which could be theoretically replaced, supposing that you respect the
  14. interface of each subsystem.
  15.  
  16. The main execution loop is defined in the C function named VirtualMachine(),
  17. which receives two parameters: the pcode instructions to execute and the
  18. local symbol table (a portion of the OBJs (static) symbol table) used by
  19. that pcode: (please review pcode.h for the currently implemented pcode
  20. opcodes)
  21.  
  22. VM( pcode, local symbols )
  23.  
  24. The VM may invoke the VM (itself) again. This let the Clipper language to
  25. access Clipper functions and methods and external C language functions again
  26. and again. The VM organizes these multiple accesses in a ordered and full
  27. controlled way and implements services to access these multiple execution
  28. levels (ProcName(), ProcLine(), debugging, and stack variables access).
  29.  
  30. The VM subsystems are continuously used by the main execution loop. Lets
  31. review these VM subsystems:
  32.  
  33. The startup: Controls the initialization of the different VM subsystems and
  34. it is invoked at the beginning of the application. It also controls the
  35. exiting of the application.
  36.  
  37. The stack: The VM does not use the stack of the computer directly, it uses
  38. instead its own stack for manipulating values (parameters, returned values,
  39. and symbols) as a hardware stack does.
  40.  
  41. The static symbol table: Created by the compiler at compile time (and
  42. grouped by the linker on OBJs), this subsystem is responsible for an
  43. immediate access to functions location and it is highly related to the
  44. dynamic symbol table at runtime. It contains many duplicated symbols that
  45. will be optimized by the dynamic symbol table.
  46.  
  47. The dynamic symbol table: Dynamically generated from the startup subsystem
  48. at the beginning of the application. It organizes in an efficient way the
  49. static symbol table creating an alphabetical index that allows a dicotomic
  50. search of symbols. This subsystem is responsible for quick access to symbols
  51. (functions, variables, fields and workareas aliases).
  52.  
  53. The static and public variables: Responsible for storing public and static
  54. variables.
  55.  
  56. The memory: Responsible for allocating, reallocating, locking, unlocking and
  57. freeing memory.
  58.  
  59. The extend system: Defines the interface (_parc(), ..., _retc() ) from low
  60. level (C language) to high level (Clipper language). This subsystem is
  61. responsible for connecting in a proper way C language functions to the
  62. entire application.
  63.  
  64. Multidimensional arrays: This subsystem allows the creation of arrays, and
  65. the services to manipulate these arrays in all ways. The arrays are
  66. extensively used by the Clipper language and also they are the foundation of
  67. the Objects (Objects are just arrays related to a specific Class).
  68.  
  69. The Objects engine: Responsible for the creation of Classes and Objects. It
  70. also defines the way to access a specific Class method to be invoked by the
  71. VM and provides all kind of Classes information that may be requested at
  72. runtime.
  73.  
  74. The macro subsystem: it implements a reduced compiler that may be used at
  75. runtime to generate pcode to be used by the application. In fact it is a
  76. portion of the harbour yacc specifications.
  77.  
  78. The workareas subsystem: Responsible for databases management. It defines
  79. the locations where the used workareas will be stored and provides all the
  80. functions to access those workareas. It also implements the interface to the
  81. replaceable database drivers.
  82.  
  83. Question :
  84.  
  85.   Will Harbour opcodes mimic the Clipper ones? (will there be a 1:1
  86. relation between them?) If so, are Clipper opcodes described somewhere?
  87.  
  88. Answer:
  89.  
  90.                    Clipper language pcode opcodes
  91.     DEFINE        NAME             VALOR     BYTES
  92.     #define       NOP              0x00      1
  93.     #define       PUSHC            0x01      3 + literal
  94.     #define       PUSHN            0x05      3
  95.     #define       POPF             0x06      3
  96.     #define       POPM             0x07      3
  97.     #define       POPQF            0x08      3
  98.     #define       PUSHA            0x09      3
  99.     #define       PUSHF            0x0A      3
  100.     #define       PUSHM            0x0B      3
  101.     #define       PUSHMR           0x0C      3
  102.     #define       PUSHP            0x0D      3
  103.     #define       PUSHQF           0x0E      3
  104.     #define       PUSHV            0x0F      3
  105.     #define       SFRAME           0x10      3
  106.     #define       SINIT            0x11      3
  107.     #define       SYMBOL           0x12      3
  108.     #define       SYMF             0x13      3
  109.     #define       BEGIN_SEQ        0x19      3
  110.     #define       JDBG             0x1A      3
  111.     #define       JF               0x1B      3
  112.     #define       JFPT             0x1C      3
  113.     #define       JISW             0x1D      3
  114.     #define       JMP              0x1E      3
  115.     #define       JNEI             0x1F      3
  116.     #define       JT               0x20      3
  117.     #define       JTPF             0x21      3
  118.     #define       PUSHBL           0x23      3
  119.     #define       ARRAYATI         0x24      3
  120.     #define       ARRAYPUTI        0x25      3
  121.     #define       CALL             0x26      3
  122.     #define       DO               0x27      3
  123.     #define       FRAME            0x28      3
  124.     #define       FUNC             0x29      3
  125.     #define       LINE             0x2A      3
  126.     #define       MAKEA            0x2B      3
  127.     #define       MAKELA           0x2C      3
  128.     #define       PARAMS           0x2D      3
  129.     #define       POPFL            0x2E      3
  130.     #define       POPL             0x2F      3
  131.     #define       POPS             0x30      3
  132.     #define       PRIVATES         0x31      3
  133.     #define       PUBLICS          0x33      3
  134.     #define       PUSHFL           0x34      3
  135.     #define       PUSHFLR          0x35      3
  136.     #define       PUSHI            0x36      3
  137.     #define       PUSHL            0x37      3
  138.     #define       PUSHLR           0x38      3
  139.     #define       PUSHS            0x39      3
  140.     #define       PUSHSR           0x3A      3
  141.     #define       PUSHW            0x3B      3
  142.     #define       SEND             0x3C      3
  143.     #define       XBLOCK           0x3D      3
  144.     #define       MPOPF            0x4A      5
  145.     #define       MPOPM            0x4B      5
  146.     #define       MPOPQF           0x4C      5
  147.     #define       MPUSHA           0x4D      5
  148.     #define       MPUSHF           0x4E      5
  149.     #define       MPUSHM           0x4F      5
  150.     #define       MPUSHMR          0x50      5
  151.     #define       MPUSHP           0x51      5
  152.     #define       MPUSHQF          0x52      5
  153.     #define       MPUSHV           0x53      5
  154.     #define       MSYMBOL          0x54      5
  155.     #define       MSYMF            0x55      5
  156.     #define       ABS              0x56      1
  157.     #define       AND              0x57      1
  158.     #define       ARRAYAT          0x58      1
  159.     #define       ARRAYPUT         0x59      1
  160.     #define       BREAK            0x5A      1
  161.     #define       DEC              0x5B      1
  162.     #define       DIVIDE           0x5C      1
  163.     #define       DOOP             0x5D      1
  164.     #define       EEQ              0x5E      1
  165.     #define       ENDBLOCK         0x5F      1
  166.     #define       ENDPROC          0x60      1
  167.     #define       END_SEQ          0x61      1
  168.     #define       EQ               0x62      1
  169.     #define       EVENTS           0x63      1
  170.     #define       FALSE            0x64      1
  171.     #define       GE               0x65      1
  172.     #define       GT               0x66      1
  173.     #define       INC              0x67      1
  174.     #define       LE               0x68      1
  175.     #define       LT               0x69      1
  176.     #define       MINUS            0x6A      1
  177.     #define       MULT             0x6B      1
  178.     #define       NE               0x6C      1
  179.     #define       NEGATE           0x6E      1
  180.     #define       NOP2             0x6F      1
  181.     #define       NOT              0x70      1
  182.     #define       NULL             0x71      1
  183.     #define       ONE1             0x72      1
  184.     #define       OR               0x73      1
  185.     #define       PCOUNT           0x74      1
  186.     #define       PLUS             0x75      1
  187.     #define       POP              0x76      1
  188.     #define       PUSHRV           0x77      1
  189.     #define       QSELF            0x78      1
  190.     #define       SAVE_RET         0x79      1
  191.     #define       TRUE             0x7A      1
  192.     #define       UNDEF            0x7B      1
  193.     #define       ZER0             0x7C      1
  194.     #define       ZZBLOCK          0x7D      1
  195.     #define       AXPRIN           0x7E      1
  196.     #define       AXPROUT          0x7F      1
  197.     #define       BOF              0x80      1
  198.     #define       DELETED          0x81      1
  199.     #define       EOF              0x82      1
  200.     #define       FCOUNT           0x83      1
  201.     #define       FIELDNAME        0x84      1
  202.     #define       FLOCK            0x85      1
  203.     #define       FOUND            0x86      1
  204.     #define       FSELECT0         0x87      1
  205.     #define       FSELECT1         0x88      1
  206.     #define       LASTREC          0x89      1
  207.     #define       LOCK             0x8A      1
  208.     #define       RECNO            0x8B      1
  209.     #define       BNAMES           0x8C      1
  210.     #define       LNAMES           0x8D      1
  211.     #define       SNAMES           0x8E      1
  212.     #define       SRCNAME          0x8F      1
  213.     #define       TYPE             0x90      1
  214.     #define       WAVE             0x91      1
  215.     #define       WAVEA            0x92      1
  216.     #define       WAVEF            0x93      1
  217.     #define       WAVEL            0x94      1
  218.     #define       WAVEP            0x95      1
  219.     #define       WAVEPOP          0x96      1
  220.     #define       WAVEPOPF         0x97      1
  221.     #define       WAVEPOPQ         0x98      1
  222.     #define       WAVEQ            0x99      1
  223.     #define       WSYMBOL          0x9A      1
  224.     #define       AADD             0x9B      1
  225.     #define       ASC              0x9C      1
  226.     #define       AT               0x9D      1
  227.     #define       CDOW             0x9E      1
  228.     #define       CHR              0x9F      1
  229.     #define       CMONTH           0xA0      1
  230.     #define       CTOD             0xA1      1
  231.     #define       DATE             0xA2      1
  232.     #define       DAY              0xA3      1
  233.     #define       DOW              0xA4      1
  234.     #define       DTOC             0xA5      1
  235.     #define       DTOS             0xA6      1
  236.     #define       EMPTY            0xA7      1
  237.     #define       QEXP             0xA8      1
  238.     #define       EXPON            0xA9      1
  239.     #define       INSTR            0xAA      1
  240.     #define       INT              0xAB      1
  241.     #define       LEFT             0xAC      1
  242.     #define       LEN              0xAD      1
  243.     #define       LOGQ             0xAE      1
  244.     #define       LOWER            0xAF      1
  245.     #define       LTRIM            0xB0      1
  246.     #define       MAX              0xB1      1
  247.     #define       MIN              0xB2      1
  248.     #define       MODULUS          0xB3      1
  249.     #define       MONTH            0xB4      1
  250.     #define       REPLICATE        0xB5      1
  251.     #define       ROUND            0xB6      1
  252.     #define       SECONDS          0xB7      1
  253.     #define       SPACE            0xB8      1
  254.     #define       QSQRT            0xB9      1
  255.     #define       STR1             0xBA      1
  256.     #define       STR2             0xBB      1
  257.     #define       STR3             0xBC      1
  258.     #define       SUB2             0xBD      1
  259.     #define       SUB3             0xBE      1
  260.     #define       TIME             0xBF      1
  261.     #define       TRIM             0xC0      1
  262.     #define       UPPER            0xC1      1
  263.     #define       VAL              0xC2      1
  264.     #define       VALTYPE          0xC3      1
  265.     #define       WORD             0xC4      1
  266.     #define       YEAR             0xC5      1
  267.     #define       TRANS            0xC6      1
  268.     #define       COL              0xC7      1
  269.     #define       DEVPOS           0xC8      1
  270.     #define       INKEY0           0xC9      1
  271.     #define       INKEY1           0xCA      1
  272.     #define       PCOL             0xCB      1
  273.     #define       PROW             0xCC      1
  274.     #define       ROW              0xCD      1
  275.     #define       SETPOS           0xCE      1
  276.     #define       SETPOSBS         0xCF      1
  277.  
  278. Harbour will not implement all of them as we want to provide the highest
  279. freedom to programers to extend and modify Harbour as needed. In example:
  280. Clipper language uses opcodes for: Row(), Col(), Upper(), Space(),
  281. Replicate(), InKey(), Year(), Month(), etc... where we may just call a
  282. standard C function, that uses the standard extend system and that may be
  283. easily modified. So Harbour will use much less opcodes than the Clipper
  284. language. This will also help to have a simpler and easier to maintain
  285. compiler and VM.
  286.  
  287. Question :
  288.  
  289.   I see that, for example, Harbour have an opcode named "PUSHWORD"(06),
  290. while Valkyre calls it "PUSHW"(3B): Different names, different codes.
  291. Isn't it desirable that Harbour pCode be binary-compatible with Clipper? I
  292. mean, by doing so, Harbour VM could interpret Clipper pCode and
  293. vice-versa.
  294.  
  295. Answer :
  296.  
  297. Harbour opcodes are defined at pcode.h. We are trying to use a very easy to
  298. remember mnemonics, so PUSHWORD seems easier than PUSHW. The opcodes values
  299. are meaningless as they are just used by a C language switch sentence (in
  300. fact there is a powerfull optimization which it is to use the pcode opcodes
  301. themselves as an index to a VM functions pointers array, so VM execution
  302. speed may increase. Clipper uses it).
  303.  
  304. We are not fully implementing the Clipper language OBJs model (i.e. to
  305. provide identifiers names length higher than 10 chars) so Harbour OBJs will
  306. not be supported by Clipper and viceversa.
  307.  
  308. sorry for such a long message :-)
  309.  
  310. Antonio
  311.