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 >
Wrap
Text File
|
1989-12-21
|
3KB
|
77 lines
\
\ MACRO DEFINITIONS
\
\ Copyright (c) 1989 by Mikael R.K. Patel
\
\ Computer Aided Design Laboratory (CADLAB)
\ Department of Computer and Information Science
\ Linkoping University
\ S-581 83 LINKOPING
\ SWEDEN
\
\ Email: mip@ida.liu.se
\
\ Started on: 30 June 1988
\
\ Last updated on: 29 November 1989
\
\ Dependencies:
\ (forth) forth, structures
\
\ Description:
\ Allows colon definitions to be marked as macros and thus expand
\ when used in compilation (else executed).
\
\ Copying:
\ This program is free software; you can redistribute it and\or modify
\ it under the terms of the GNU General Public License as published by
\ the Free Software Foundation; either version 1, or (at your option)
\ any later version.
\
\ This program is distributed in the hope that it will be useful,
\ but WITHOUT ANY WARRANTY; without even the implied warranty of
\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\ GNU General Public License for more details.
\
\ You should have received a copy of the GNU General Public License
\ along with this program; see the file COPYING. If not, write to
\ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
.( Loading Macro definitions...) cr
#include forth.f83
#include structures.f83
vocabulary macros
structures forth macros definitions
struct.type MACRO ( -- ) private
ptr +body private ( Pointer to macro code body)
long +size private ( Size of code body in bytes)
struct.init ( body size MACRO -- )
swap over +size ! +body ! ( Initiate macro structure block)
struct.end
: [macro] ( macro -- )
compiling ( Check compilation state. If compiling)
if dup +body @ here ( Allocate space for copy of macro body)
rot +size @ dup allot cmove ( Allocate and copy)
else ( If execution mode)
+body @ >r ( Access body and execute)
then ; private
: macro ( -- )
last >body here over - sizeof ptr - ( Create a new MACRO structure)
new MACRO last +parameter ! ( Modify parameter field of last)
immediate ( and mode field to immediate)
['] [macro] >body last +code ! ; ( and code field to macro management)
: .macro ( -- )
." macro#" ' >body dup . ( Access macro and print address)
." size: " dup +size @ . ( and the size )
." body: " +body @ . ; ( and pointer to body of macro)
forth only