diff options
author | jkh <jkh@FreeBSD.org> | 1998-11-05 08:39:43 +0000 |
---|---|---|
committer | jkh <jkh@FreeBSD.org> | 1998-11-05 08:39:43 +0000 |
commit | 33ecda9af6cd79db0f8bc85975b466659a140a5d (patch) | |
tree | dcf09926361f18a2af7284bb0bd911c4b7a1e1a3 | |
parent | 6a9b63e38581729c20e76a9680f81a0b31961f50 (diff) | |
download | FreeBSD-src-33ecda9af6cd79db0f8bc85975b466659a140a5d.zip FreeBSD-src-33ecda9af6cd79db0f8bc85975b466659a140a5d.tar.gz |
Remember a bit more of my forth and do:
o Add fexists word to check for the presence of a file
o make fexists and fload immediate words which DTRT both interpreted
and compiled (doh!)
o add an init word which gets run at bootstrapping time to do extra
post-coldload initialization (in the default implementation, we
look for /boot/boot.4th and load it if found).
-rw-r--r-- | sys/boot/common/interp_forth.c | 7 | ||||
-rw-r--r-- | sys/boot/ficl/Makefile | 4 | ||||
-rw-r--r-- | sys/boot/ficl/softwords/softcore.fr | 3 | ||||
-rw-r--r-- | sys/boot/ficl/words.c | 61 |
4 files changed, 59 insertions, 16 deletions
diff --git a/sys/boot/common/interp_forth.c b/sys/boot/common/interp_forth.c index cdc71ea..36d4838 100644 --- a/sys/boot/common/interp_forth.c +++ b/sys/boot/common/interp_forth.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: interp_forth.c,v 1.1 1998/11/04 00:29:01 msmith Exp $ + * $Id: interp_forth.c,v 1.2 1998/11/04 03:41:09 msmith Exp $ */ #include <stand.h> @@ -90,13 +90,14 @@ bf_init(void) { struct bootblk_command **cmdp; - ficlInitSystem(3000); /* Default dictionary ~2000 cells */ + ficlInitSystem(4000); /* Default dictionary ~4000 cells */ bf_vm = ficlNewVM(); /* make all commands appear as Forth words */ SET_FOREACH(cmdp, Xcommand_set) ficlBuild((*cmdp)->c_name, bf_command, FW_DEFAULT); - + /* run the init word from softcore */ + ficlExec(bf_vm, "init"); } /* diff --git a/sys/boot/ficl/Makefile b/sys/boot/ficl/Makefile index 2455714..5dd33e1 100644 --- a/sys/boot/ficl/Makefile +++ b/sys/boot/ficl/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.4 1998/11/05 04:54:05 msmith Exp $ +# $Id: Makefile,v 1.5 1998/11/05 07:27:55 jkh Exp $ # LIB= ficl NOPROFILE= yes @@ -17,7 +17,7 @@ SOFTWORDS= softcore.fr jhlocal.fr marker.fr CFLAGS+= -I${.CURDIR} softcore.c: ${SOFTWORDS} softcore.pl - (cd ${.CURDIR}/softwords; ${PERL} softcore.pl ${SOFTWORDS}) > ${.TARGET} + (cd ${.CURDIR}/softwords; perl softcore.pl ${SOFTWORDS}) > ${.TARGET} .include <bsd.lib.mk> diff --git a/sys/boot/ficl/softwords/softcore.fr b/sys/boot/ficl/softwords/softcore.fr index bcc2696..ad3d55b 100644 --- a/sys/boot/ficl/softwords/softcore.fr +++ b/sys/boot/ficl/softwords/softcore.fr @@ -121,5 +121,8 @@ decimal 32 constant bl wordlist constant hidden : hide hidden dup >search ficl-set-current ; +\ init - hook for extra startup behavior +: init ( -- ) fexists "/boot/boot.4th" if fload "/boot/boot.4th" then ; + \ ** E N D S O F T C O R E . F R diff --git a/sys/boot/ficl/words.c b/sys/boot/ficl/words.c index 1bd9d35..35e4348 100644 --- a/sys/boot/ficl/words.c +++ b/sys/boot/ficl/words.c @@ -4031,26 +4031,31 @@ static void forget(FICL_VM *pVM) #define nLINEBUF 256 static void fload(FICL_VM *pVM) { - char cp[nLINEBUF]; - char filename[nLINEBUF]; - FICL_STRING *pFilename = (FICL_STRING *)filename; + char *p, cp[nLINEBUF]; + FICL_STRING *pFilename; int i, fd, nLine = 0; char ch; CELL id; + FICL_DICT *dp = ficlGetDict(); - vmGetString(pVM, pFilename, '\n'); + if (pVM->state == COMPILE) + { + dictAppendCell(dp, LVALUEtoCELL(pStringLit)); + dp->here = PTRtoCELL vmGetString(pVM, (FICL_STRING *)dp->here, '\"'); + dictAlign(dp); + return; + } - if (pFilename->count <= 0) + pFilename = (FICL_STRING *)dp->here; + vmGetString(pVM, pFilename, '\"'); + if (pFilename->count <= 1) { vmTextOut(pVM, "fload: no filename specified", 1); return; } - /* - ** get the file's size and make sure it exists - */ - fd = open(pFilename->text, O_RDONLY); - + p = (*pFilename->text == '\"') ? pFilename->text + 1 : pFilename->text; + fd = open(p, O_RDONLY); if (fd == -1) { vmTextOut(pVM, "fload: Unable to open file: ", 0); @@ -4095,6 +4100,39 @@ static void fload(FICL_VM *pVM) return; } +static void fexists(FICL_VM *pVM) +{ + char *p; + FICL_STRING *pFilename; + int fd; + FICL_DICT *dp = ficlGetDict(); + + if (pVM->state == COMPILE) + { + dictAppendCell(dp, LVALUEtoCELL(pStringLit)); + dp->here = PTRtoCELL vmGetString(pVM, (FICL_STRING *)dp->here, '\"'); + dictAlign(dp); + return; + } + + pFilename = (FICL_STRING *)dp->here; + vmGetString(pVM, pFilename, '\"'); + if (pFilename->count <= 1) + { + vmTextOut(pVM, "fexists: no filename specified", 1); + return; + } + p = (*pFilename->text == '\"') ? pFilename->text + 1 : pFilename->text; + fd = open(p, O_RDONLY); + if (fd > 0) { + stackPushINT32(pVM->pStack, TRUE); + close(fd); + } + else + stackPushINT32(pVM->pStack, FALSE); + return; +} + /* Get a character from stdin */ static void key(FICL_VM *pVM) { @@ -4277,7 +4315,8 @@ void ficlCompileCore(FICL_DICT *dp) dictAppendWord(dp, "\\", commentLine, FW_IMMEDIATE); /* FreeBSD extention words */ - dictAppendWord(dp, "fload", fload, FW_DEFAULT); + dictAppendWord(dp, "fload", fload, FW_IMMEDIATE); + dictAppendWord(dp, "fexists", fexists, FW_IMMEDIATE); dictAppendWord(dp, "key", key, FW_DEFAULT); /* |