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).
This commit is contained in:
parent
6a9b63e385
commit
33ecda9af6
@ -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");
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -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>
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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);
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user