Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. ..Open = 0
  2.  
  3. ; When some procedure is not finished with 'endp' macro,
  4. ; "Unexpected end of file" error, occur without any info, where is error.
  5. ; in this case, comment followind 2 rows and uncomment next two.
  6. ; proc_used and endp_used are optimized versions of the macroses.
  7. ; proc_debug and endp_debug are debug versions. When you use debug
  8. ; versions, error message will show you where is missing 'endp'.
  9. ;
  10. ; Don't forget to recompile with *_used versions, to get optimised
  11. ; binary with all not used procedure excluded.
  12.  
  13. macro RestoreEx [name]
  14. {
  15.    macro rstr#name _% RESTORE name %_
  16.    macro rstr _% %_
  17.    rstr#name
  18.    purge rstr,rstr#name
  19. }
  20.  
  21. _% fix {
  22. %_ fix }
  23. restore fix RestoreEx
  24.  
  25.  
  26. proc fix proc_used
  27. endp fix endp_used
  28. ;proc fix proc_debug
  29. ;endp fix endp_debug
  30.  
  31. macro proc_used name,[arg] {                  ; define procedure
  32. common
  33.   proc_args fix arg
  34. ;  if ~ used name
  35. ;    if ~..ShowSkipped eq OFF
  36. ;      display 1,'Procedure skiped: ',`name, $0d, $0a
  37. ;    end if
  38. ;  else
  39.   if used name
  40.     name:
  41.     virtual at ebp+8
  42.       if ~ arg eq
  43.         forward
  44.           local ..arg
  45.           ..arg dd ?
  46.           arg equ ..arg
  47.         common
  48.       end if
  49.       ..ret = $ - (ebp+8)
  50.     end virtual
  51.     local ..dynamic_data,..dynamic_size
  52.     dynamic_data equ ..dynamic_data
  53.     dynamic_size equ ..dynamic_size
  54.     virtual at ebp - dynamic_size
  55.       dynamic_data:
  56. }
  57.  
  58.  
  59. macro proc_debug name,[arg] {                  ; define procedure
  60. common
  61.   proc_args fix arg
  62.   if ..Open > 0
  63.     Error! Missing 'endp' before procedure `name
  64.   end if
  65.  
  66.   ..Open = ..Open+1
  67.  
  68.   name:
  69.   virtual at ebp+8
  70.     if ~ arg eq
  71.       forward
  72.         local ..arg
  73.         ..arg dd ?
  74.         arg equ ..arg
  75.       common
  76.     end if
  77.     ..ret = $ - (ebp+8)
  78.   end virtual
  79.   local ..dynamic_data,..dynamic_size
  80.   dynamic_data equ ..dynamic_data
  81.   dynamic_size equ ..dynamic_size
  82.   virtual at ebp - dynamic_size
  83.     dynamic_data:
  84. }
  85.  
  86.  
  87.  
  88. macro begin  {                           ; begin procedure instructions
  89.       ; continue from "proc" macro.
  90. ;     align 4
  91.       rb (4 - ($ - dynamic_data) and 11b) and 11b ; align the stack at dword.
  92.       dynamic_size = $ - dynamic_data
  93.     end virtual
  94.  
  95.     if (dynamic_size = 0)
  96.       if ..ret <> 0
  97.         push ebp                     ; smaller is dynamic_size = 0
  98.         mov  ebp, esp
  99.       end if
  100.     else
  101.       enter dynamic_size, 0
  102.     end if
  103. }
  104.  
  105.  
  106. macro return {                          ; return from procedure
  107.     ; continue from "enter" macro.
  108.     if ..ret <> 0
  109.       leave
  110.       ret ..ret
  111.     else
  112.       if dynamic_size <> 0
  113.         leave
  114.       end if
  115.       ret
  116.     end if
  117. }
  118.  
  119.  
  120. macro endp_used {
  121.   restore proc_args
  122.   end if
  123. }
  124.  
  125. macro endp_debug {
  126.   restore proc_args
  127.   ..Open = ..Open - 1
  128. }
  129.  
  130.  
  131. macro _reversepusharg [arg] {
  132.   reverse
  133.     pushd arg
  134. }
  135.  
  136.  
  137. macro stdcall proc,[arg] {              ; call procedure
  138. common
  139.   if ~ arg eq
  140.     _reversepusharg arg
  141.   end if
  142.   call proc
  143. }
  144.  
  145.  
  146. macro invoke proc,[arg] {               ; invoke procedure (indirect)
  147. common
  148.   stdcall [proc],arg
  149. }
  150.  
  151. ;end of file