]> gitweb.factorcode.org Git - factor.git/blob - core/generic/parser/parser.factor
ba9cd5244c4312502b2c2a468c4985ce9536575a
[factor.git] / core / generic / parser / parser.factor
1 ! Copyright (C) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: parser kernel words generic namespaces inspector ;
4 IN: generic.parser
5
6 ERROR: not-in-a-method-error ;
7
8 M: not-in-a-method-error summary
9     drop "call-next-method can only be called in a method definition" ;
10
11 : CREATE-GENERIC ( -- word ) CREATE dup reset-word ;
12
13 : create-method-in ( class generic -- method )
14     create-method f set-word dup save-location ;
15
16 : CREATE-METHOD ( -- method )
17     scan-word bootstrap-word scan-word create-method-in ;
18
19 SYMBOL: current-class
20 SYMBOL: current-generic
21
22 : with-method-definition ( quot -- parsed )
23     [
24         >r
25         [ "method-class" word-prop current-class set ]
26         [ "method-generic" word-prop current-generic set ]
27         [ ] tri
28         r> call
29     ] with-scope ; inline
30
31 : (M:) ( method def -- )
32     CREATE-METHOD [ parse-definition ] with-method-definition ;
33