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

  1. I just started implementing Classes and objects creation when I realized Harbour is not managing statics variables yet (Harbour recognizes them but does not generate the proper pcode for them).
  2.  
  3. So I would like to make an introduction to statics variables management as it is a sophisticated system that Harbour is going to implement.
  4.  
  5. It is something publically known that Clipper statics variables are located at the bottom of the data segment. This has caused all kind of troubles. This is why when I designed Five I did it in a way that could not cause any trouble in the future.
  6.  
  7. In Harbour all statics variables (and I mean on all PRGs) are stored in just one Harbour array (a Clipper language array), this guaranties that we may have as many statics variables as desired without limits (just limited by the available memory). This aStatics array is not visible from the application (PRG level). 
  8.  
  9. Basically what happens when a function is called and that function uses static variables, is that the stack sets a pointer to that array section where our statics are, so from that moment on, accessing a static1, static2, ... is accessing some elements on that array:
  10.  
  11.     static1 = statics[ statics_base_for_this_function + 1 ]
  12.  
  13.     ...
  14.  
  15.     staticn = statics[ statics_base_for_this_function + n ]
  16.  
  17. In order to implement this we just use two new pcode opcodes: _STATICS, _SFRAME
  18.  
  19. _STATICS makes the global statics array grow enough to hold our new defined statics:
  20.  
  21.    _STATICS <n> -->  ASize( aStatics, Len( aStatics ) + <n> ) 
  22.  
  23.    _SFRAME --> tell the stack from what location into aStatics are ours.
  24.  
  25. _STATICS is just called once from an entire PRG from an init function named _INITSTATICS (STATICS$ and SINIT in Clipper). That function stores on a tricky place (its own function pointer in the symbol table!) our statics base, and later on _SFRAME simply takes it from there and set it in the stack. That _INITSTATICS function will perform whatever initialization our global statics may have defined in that PRG).
  26.  
  27. You are going to see the code for all these. I just wanted to provide a clear idea about how Harbour does its magic :-)
  28.  
  29.  
  30. Antonio  
  31.