Implement REQUIRE (Forth 2012)
[debian/pforth] / fth / require.fth
1 \ REQUIRE and REQUIRED
2 \
3 \ This code is part of pForth.
4 \
5 \ The pForth software code is dedicated to the public domain,
6 \ and any third party may reproduce, distribute and modify
7 \ the pForth software code or any derivative works thereof
8 \ without any compensation or license.  The pForth software
9 \ code is provided on an "as is" basis without any warranty
10 \ of any kind, including, without limitation, the implied
11 \ warranties of merchantability and fitness for a particular
12 \ purpose and their equivalents under the laws of any jurisdiction.
13
14 private{
15
16 \ Has the file with name C-ADDR/U already been included?
17 \
18 \ This searches the "::::<filename>" marker created by INCLUDED.  This
19 \ works for now, but may break if pForth ever receives wordlists.
20 : INCLUDED? ( c-addr u -- flag )
21     s" ::::" here place         ( c-addr u )
22     here $append                ( )
23     here latest findnfa.from    ( x found? )
24     nip
25 ;
26
27 \ FIXME: use real PARSE-NAME when available
28 : (PARSE-NAME) ( "word" -- c-addr u ) bl parse-word ;
29
30 }private
31
32 : REQUIRED ( i*x c-addr u -- j*x ) 2dup included? IF 2drop ELSE included THEN ;
33 : REQUIRE ( i*x "name" -- i*x ) (parse-name) required ;
34
35 privatize