Skip to content

Commit

Permalink
Add require-path and required-path.
Browse files Browse the repository at this point in the history
  • Loading branch information
SirWumpus committed Oct 22, 2024
1 parent 08ed095 commit 76fd6f5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
15 changes: 15 additions & 0 deletions doc/file.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,18 @@ Write `u` characters from address `caddr` to the file `fid` followed by an imple
Search the colon (:) separated path list, `path` `p`, and open the first file, `file` `f`, found using the file access `mode`. On success return the file id `fid` and `ior` equal to zero; otherwise on error `fid` is zero and `ior` is a non-zero error code (see `errno(2)`).

- - -
#### require-path
( `i*x` `<spaces>filepath` -- `j*x` )
If `filepath` has been previous loaded by `INCLUDE-PATH` or `REQURIE-PATH`, then skip the file; otherwise push the
address and length of the `filepath` on the stack and perform the function of `required-path`.

ok REQUIRE-PATH ed.p4

- - -
#### required-path
( `caddr` `u` -- )
If the file `caddr` `u` has been `INCLUDED` or `REQUIRED` already, discard `caddr` `u`; otherwise perform the function of `INCLUDED-PATH`, which searches the colon (:) separated path list given by the environment variable `POST4_PATH` for the first file `caddr` `f`.

ok S" ed.p4" REQUIRED-PATH

- - -
29 changes: 18 additions & 11 deletions src/post4.p4
Original file line number Diff line number Diff line change
Expand Up @@ -2061,9 +2061,6 @@ VARIABLE SCR
\ (S: i*x caddr u -- j*x )
: included-path S" POST4_PATH" env 2SWAP R/O open-file-path THROW _include_and_close ; $20 _pp!

\ (S: i*x <spaces>filename" -- j*x )
: include-path PARSE-NAME _string0_store included-path ;

\ ... ACTION-OF ...
\
\ (S: <spaces>name -- xt )
Expand Down Expand Up @@ -2854,26 +2851,36 @@ FORTH-WORDLIST SET-CURRENT

WORDLIST CONSTANT required-wordlist

: INCLUDED
\ (S: <spaces>filename" -- )
: _parse_string0 PARSE-NAME _string0_store ;

\ (S: caddr u -- )
: _save_included
\ Avoid adding duplicate files to the word-list.
2DUP required-wordlist FIND-NAME-IN 0= IF
GET-CURRENT >R required-wordlist SET-CURRENT
2DUP _created R> SET-CURRENT
THEN
INCLUDED
;

\ (S: caddr u -- )
: INCLUDED _save_included INCLUDED ;
: included-path _save_included included-path ;

\ (S: i*x <spaces>filename" -- j*x )
: INCLUDE PARSE-NAME _string0_store INCLUDED ;
: INCLUDE _parse_string0 INCLUDED ;
: include-path _parse_string0 included-path ;

\ (S: caddr u -- )
: _already_included 2DUP required-wordlist FIND-NAME-IN ;

\ (S: i*x caddr u -- j*x )
: REQUIRED
2DUP required-wordlist FIND-NAME-IN IF 2DROP EXIT THEN
INCLUDED
;
: REQUIRED _already_included IF 2DROP EXIT THEN INCLUDED ;
: required-path _already_included IF 2DROP EXIT THEN included-path ;

\ (S: i*x <spaces>filename" -- j*x )
: REQUIRE PARSE-NAME _string0_store REQUIRED ;
: REQUIRE _parse_string0 REQUIRED ;
: require-path _parse_string0 required-path ;

: _free_word ( w -- )
?DUP IF
Expand Down

0 comments on commit 76fd6f5

Please sign in to comment.