1 !:folding=indent:collapseFolds=1:
5 ! Copyright (C) 2003 Slava Pestov.
7 ! Redistribution and use in source and binary forms, with or without
8 ! modification, are permitted provided that the following conditions are met:
10 ! 1. Redistributions of source code must retain the above copyright notice,
11 ! this list of conditions and the following disclaimer.
13 ! 2. Redistributions in binary form must reproduce the above copyright notice,
14 ! this list of conditions and the following disclaimer in the documentation
15 ! and/or other materials provided with the distribution.
17 ! THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 ! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
19 ! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20 ! DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 ! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 ! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 ! OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 ! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 ! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 : worddef? ( obj -- boolean )
38 "factor.FactorWordDefinition" is ;
40 : worddef ( word -- worddef )
42 intern dup [ [ "def" get ] bind ] when
45 : word-property ( pname word -- pvalue )
48 : set-word-property ( pvalue pname word -- )
51 : redefine ( word def -- )
52 swap [ "def" set ] bind ;
54 : word? ( obj -- boolean )
55 "factor.FactorWord" is ;
57 : compiled? ( worddef -- boolean )
58 "factor.compiler.CompiledDefinition" is ;
60 : compound? ( worddef -- boolean )
61 "factor.FactorCompoundDefinition" is ;
63 : compound-or-compiled? ( worddef -- ? )
64 dup compiled? swap compound? or ;
66 : comment? ( obj -- ? )
67 "factor.FactorDocComment" is ;
70 [ ] "factor.FactorWord" "gensym" jinvoke-static ;
72 : <compound> ( word def -- worddef )
73 swap intern swap interpreter
74 [ "factor.FactorWord" "factor.Cons" "factor.FactorInterpreter" ]
75 "factor.FactorCompoundDefinition"
78 : no-name ( list -- word )
79 ! Generates an uninternalized word and gives it a compound
80 ! definition created from the given list.
81 [ gensym dup dup ] dip <compound> redefine ;
83 : primitive? ( worddef -- boolean )
84 "factor.FactorPrimitiveDefinition" is ;
86 : shuffle? ( worddef -- boolean )
87 "factor.FactorShuffleDefinition" is ;
89 : word-of-worddef ( worddef -- word )
91 [ "factor.FactorInterpreter" ]
92 "factor.FactorWordDefinition" "getWord" jinvoke ;
94 : defined? ( obj -- ? )
95 dup word? [ worddef ] [ drop f ] ifte ;
97 : worddef>list ( worddef -- list )
98 worddef interpreter swap
99 [ "factor.FactorInterpreter" ] "factor.FactorWordDefinition"
102 : skip-docs ( list -- list )
103 dup [ dup car comment? [ cdr skip-docs ] when ] when ;
105 : compound>list ( worddef -- list )
106 worddef>list dup [ skip-docs ] when ;