]> gitweb.factorcode.org Git - factor.git/blob - basis/macros/macros.factor
Fix permission bits
[factor.git] / basis / macros / macros.factor
1 ! Copyright (C) 2007, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: parser kernel sequences words effects
4 stack-checker.transforms combinators assocs definitions
5 quotations namespaces memoize accessors ;
6 IN: macros
7
8 : real-macro-effect ( word -- effect' )
9     "declared-effect" word-prop in>> 1 <effect> ;
10
11 : define-macro ( word definition -- )
12     over "declared-effect" word-prop in>> length >r
13     2dup "macro" set-word-prop
14     2dup over real-macro-effect memoize-quot [ call ] append define
15     r> define-transform ;
16
17 : MACRO:
18     (:) define-macro ; parsing
19
20 PREDICATE: macro < word "macro" word-prop >boolean ;
21
22 M: macro definer drop \ MACRO: \ ; ;
23
24 M: macro definition "macro" word-prop ;
25
26 M: macro reset-word
27     [ call-next-method ] [ f "macro" set-word-prop ] bi ;
28
29 : n*quot ( n seq -- seq' ) <repetition> concat >quotation ;
30
31 : saver ( n -- quot ) \ >r <repetition> >quotation ;
32
33 : restorer ( n -- quot ) \ r> <repetition> >quotation ;