home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / tile-forth-2.1-bin.lha / lib / tile-forth / macros.f83 < prev    next >
Text File  |  1996-10-12  |  2KB  |  76 lines

  1. \
  2. \  MACRO DEFINITIONS
  3. \
  4. \  Copyright (C) 1988-1990 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: 27 July 1990
  17. \
  18. \  Dependencies:
  19. \       (forth) forth, internals, structures
  20. \
  21. \  Description:
  22. \       Allows colon definitions to be marked as macros and expanded
  23. \       when used in compilation mode (else executed as usual).
  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 Macros definitions...) cr
  41.  
  42. #include internals.f83
  43. #include structures.f83
  44.  
  45. vocabulary macros ( -- )
  46.  
  47. structures forth macros definitions
  48.  
  49. struct.type MACRO ( -- ) private
  50.   ptr  +body ( macro -- addr) private
  51.   long +size ( macro -- addr) private
  52. struct.init ( body size macro -- )
  53.   tuck +size ! +body !            ( Initiate macro structure block)
  54. struct.does ( macro -- )
  55.   compiling                ( Check compilation state)
  56.   if dup +body @ here            ( Allocate space for copy of body)
  57.     rot +size @ dup allot cmove        ( Allocate and copy)
  58.   else                    ( If execution mode)
  59.     +body @ >r                ( Access body and execute)
  60.   then
  61. struct.end
  62.  
  63. : macro ( -- )
  64.   last >body here over - sizeof ptr -    ( Create a new MACRO structure)
  65.   new-struct MACRO last +parameter !    ( Modify parameter field of last)
  66.   immediate                ( and mode field to immediate)
  67. ;
  68.  
  69. : .macro ( -- )
  70.   ." macro#" ' >body dup .        ( Access macro and print address)
  71.   ." size: " dup +size @ .        ( and the size)
  72.   ." body: " +body @ .            ( and pointer to body of macro)
  73. ;
  74.  
  75. forth only
  76.