39 lines
		
	
	
		
			938 B
		
	
	
	
		
			Factor
		
	
	
			
		
		
	
	
			39 lines
		
	
	
		
			938 B
		
	
	
	
		
			Factor
		
	
	
! Copyright (C) 2007, 2010 Slava Pestov.
 | 
						|
! See http://factorcode.org/license.txt for BSD license.
 | 
						|
USING: accessors combinators compiler.units definitions effects
 | 
						|
effects.parser fry kernel memoize words ;
 | 
						|
IN: macros
 | 
						|
 | 
						|
<PRIVATE
 | 
						|
 | 
						|
: real-macro-effect ( effect -- effect' )
 | 
						|
    in>> { "quot" } <effect> ;
 | 
						|
 | 
						|
PRIVATE>
 | 
						|
 | 
						|
: define-macro ( word definition effect -- )
 | 
						|
    real-macro-effect {
 | 
						|
        [
 | 
						|
            [ '[ _ _ call-effect ] ] keep
 | 
						|
            [ memoize-quot '[ @ call ] ] keep
 | 
						|
            define-declared
 | 
						|
        ]
 | 
						|
        [ drop "macro" set-word-prop ]
 | 
						|
        [ 2drop changed-effect ]
 | 
						|
    } 3cleave ;
 | 
						|
 | 
						|
SYNTAX: MACRO: (:) define-macro ;
 | 
						|
 | 
						|
PREDICATE: macro < word "macro" word-prop >boolean ;
 | 
						|
 | 
						|
M: macro make-inline cannot-be-inline ;
 | 
						|
 | 
						|
M: macro definer drop \ MACRO: \ ; ;
 | 
						|
 | 
						|
M: macro definition "macro" word-prop ;
 | 
						|
 | 
						|
M: macro reset-word
 | 
						|
    [ call-next-method ] [ f "macro" set-word-prop ] bi ;
 | 
						|
 | 
						|
M: macro always-bump-effect-counter? drop t ;
 |