2010-01-27 03:00:10 -05:00
|
|
|
! Copyright (C) 2007, 2010 Slava Pestov.
|
2007-09-20 18:09:08 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2010-02-23 05:57:13 -05:00
|
|
|
USING: parser effects.parser kernel sequences words effects
|
|
|
|
combinators assocs definitions quotations namespaces memoize
|
|
|
|
accessors fry compiler.units ;
|
2007-09-20 18:09:08 -04:00
|
|
|
IN: macros
|
|
|
|
|
2009-02-06 11:22:09 -05:00
|
|
|
<PRIVATE
|
|
|
|
|
2009-03-21 04:17:35 -04:00
|
|
|
: real-macro-effect ( effect -- effect' )
|
2009-03-23 01:34:02 -04:00
|
|
|
in>> { "quot" } <effect> ;
|
2008-01-09 17:52:37 -05:00
|
|
|
|
2009-02-06 11:22:09 -05:00
|
|
|
PRIVATE>
|
|
|
|
|
2010-02-01 11:50:13 -05:00
|
|
|
: define-macro ( word definition effect -- )
|
|
|
|
real-macro-effect {
|
2010-02-01 12:56:13 -05:00
|
|
|
[
|
|
|
|
[ '[ _ _ call-effect ] ] keep
|
|
|
|
[ memoize-quot '[ @ call ] ] keep
|
|
|
|
define-declared
|
|
|
|
]
|
2010-02-01 11:50:13 -05:00
|
|
|
[ drop "macro" set-word-prop ]
|
|
|
|
[ 2drop changed-effect ]
|
|
|
|
} 3cleave ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2009-03-21 02:27:50 -04:00
|
|
|
SYNTAX: MACRO: (:) define-macro ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2008-03-26 19:23:19 -04:00
|
|
|
PREDICATE: macro < word "macro" word-prop >boolean ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2010-01-27 03:00:10 -05:00
|
|
|
M: macro make-inline cannot-be-inline ;
|
|
|
|
|
2007-09-20 18:09:08 -04:00
|
|
|
M: macro definer drop \ MACRO: \ ; ;
|
|
|
|
|
2010-02-01 11:50:13 -05:00
|
|
|
M: macro definition "macro" word-prop ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2010-02-01 11:50:13 -05:00
|
|
|
M: macro reset-word
|
|
|
|
[ call-next-method ] [ f "macro" set-word-prop ] bi ;
|
2009-11-13 04:52:14 -05:00
|
|
|
|
2010-01-29 08:58:39 -05:00
|
|
|
M: macro always-bump-effect-counter? drop t ;
|