2007-09-20 18:09:08 -04:00
|
|
|
! Copyright (C) 2007 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
|
|
|
|
USING: parser kernel sequences words effects inference.transforms
|
2007-12-31 00:44:40 -05:00
|
|
|
combinators assocs definitions quotations namespaces memoize ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
IN: macros
|
|
|
|
|
2007-12-31 00:44:40 -05:00
|
|
|
: (:) ( -- word definition effect-in )
|
2007-09-20 18:09:08 -04:00
|
|
|
CREATE dup reset-generic parse-definition
|
|
|
|
over "declared-effect" word-prop effect-in length ;
|
|
|
|
|
2008-01-09 17:52:37 -05:00
|
|
|
: real-macro-effect ( word -- effect' )
|
|
|
|
"declared-effect" word-prop effect-in 1 <effect> ;
|
|
|
|
|
2007-12-31 00:44:40 -05:00
|
|
|
: (MACRO:) ( word definition effect-in -- )
|
|
|
|
>r 2dup "macro" set-word-prop
|
2008-01-09 17:52:37 -05:00
|
|
|
2dup over real-macro-effect memoize-quot
|
2008-01-06 13:17:50 -05:00
|
|
|
[ call ] append define
|
2007-09-20 18:09:08 -04:00
|
|
|
r> define-transform ;
|
|
|
|
|
|
|
|
: MACRO:
|
|
|
|
(:) (MACRO:) ; parsing
|
|
|
|
|
2008-01-02 19:36:36 -05:00
|
|
|
PREDICATE: word macro "macro" word-prop >boolean ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
M: macro definer drop \ MACRO: \ ; ;
|
|
|
|
|
|
|
|
M: macro definition "macro" word-prop ;
|
|
|
|
|
|
|
|
: macro-expand ( ... word -- quot ) "macro" word-prop call ;
|
|
|
|
|
|
|
|
: n*quot ( n seq -- seq' ) <repetition> concat >quotation ;
|
|
|
|
|
|
|
|
: saver \ >r <repetition> >quotation ;
|
|
|
|
|
|
|
|
: restorer \ r> <repetition> >quotation ;
|