home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / EFFO / pd6.lzh / LIB / TILE / macros.f83 < prev    next >
Text File  |  1989-12-21  |  3KB  |  77 lines

  1. \
  2. \  MACRO DEFINITIONS
  3. \
  4. \  Copyright (c) 1989 by Mikael R.K. Patel
  5. \
  6. \  Computer Aided Design Laboratory (CADLAB)
  7. \  Department of Computer and Information Science
  8. \  Linkoping University
  9. \  S-581 83 LINKOPING
  10. \  SWEDEN
  11. \
  12. \  Email: mip@ida.liu.se
  13. \
  14. \  Started on: 30 June 1988
  15. \
  16. \  Last updated on: 29 November 1989
  17. \
  18. \  Dependencies:
  19. \       (forth) forth, structures
  20. \
  21. \  Description:
  22. \       Allows colon definitions to be marked as macros and thus expand
  23. \       when used in compilation (else executed).
  24. \
  25. \  Copying:
  26. \       This program is free software; you can redistribute it and\or modify
  27. \       it under the terms of the GNU General Public License as published by
  28. \       the Free Software Foundation; either version 1, or (at your option)
  29. \       any later version.
  30. \
  31. \       This program is distributed in the hope that it will be useful,
  32. \       but WITHOUT ANY WARRANTY; without even the implied warranty of
  33. \       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  34. \       GNU General Public License for more details.
  35. \
  36. \       You should have received a copy of the GNU General Public License
  37. \       along with this program; see the file COPYING.  If not, write to
  38. \       the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  39.  
  40. .( Loading Macro definitions...) cr
  41.  
  42. #include forth.f83
  43. #include structures.f83
  44.  
  45. vocabulary macros
  46.  
  47. structures forth macros definitions
  48.  
  49. struct.type MACRO ( -- ) private
  50.   ptr  +body private                   ( Pointer to macro code body)
  51.   long +size private                   ( Size of code body in bytes)
  52. struct.init ( body size MACRO -- )
  53.   swap over +size ! +body !            ( Initiate macro structure block)
  54. struct.end
  55.  
  56. : [macro] ( macro -- )
  57.   compiling                            ( Check compilation state. If compiling)
  58.   if dup +body @ here                  ( Allocate space for copy of macro body)
  59.     rot +size @ dup allot cmove                ( Allocate and copy)
  60.   else                                 ( If execution mode)
  61.     +body @ >r                         ( Access body and execute)
  62.   then ; private
  63.  
  64. : macro ( -- )
  65.   last >body here over - sizeof ptr -  ( Create a new MACRO structure)
  66.   new MACRO last +parameter !          ( Modify parameter field of last)
  67.   immediate                            ( and mode field to immediate)
  68.   ['] [macro] >body last +code ! ;     ( and code field to macro management)
  69.  
  70. : .macro ( -- )
  71.   ." macro#" ' >body dup .             ( Access macro and print address)
  72.   ." size: " dup +size @ .             ( and the size )
  73.   ." body: " +body @ .  ;              ( and pointer to body of macro)
  74.  
  75. forth only
  76.  
  77.