From owner-p4-projects Tue Apr 9 13:34: 2 2002 Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 903D037B400; Tue, 9 Apr 2002 13:32:46 -0700 (PDT) Delivered-To: perforce@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 53F5337B404 for ; Tue, 9 Apr 2002 13:32:42 -0700 (PDT) Received: (from perforce@localhost) by freefall.freebsd.org (8.11.6/8.11.6) id g39KWf226790 for perforce@freebsd.org; Tue, 9 Apr 2002 13:32:41 -0700 (PDT) (envelope-from jhb@freebsd.org) Date: Tue, 9 Apr 2002 13:32:41 -0700 (PDT) Message-Id: <200204092032.g39KWf226790@freefall.freebsd.org> X-Authentication-Warning: freefall.freebsd.org: perforce set sender to jhb@freebsd.org using -f From: John Baldwin Subject: PERFORCE change 9466 for review To: Perforce Change Reviews Sender: owner-p4-projects@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG http://people.freebsd.org/~peter/p4db/chv.cgi?CH=9466 Change 9466 by jhb@jhb_laptop on 2002/04/09 13:32:31 IFC. Affected files ... ... //depot/projects/smpng/sys/alpha/alpha/machdep.c#40 integrate ... //depot/projects/smpng/sys/boot/common/load_elf.c#4 integrate ... //depot/projects/smpng/sys/boot/ficl/Makefile#2 integrate ... //depot/projects/smpng/sys/boot/ficl/alpha/sysdep.h#2 integrate ... //depot/projects/smpng/sys/boot/ficl/dict.c#2 integrate ... //depot/projects/smpng/sys/boot/ficl/ficl.c#2 integrate ... //depot/projects/smpng/sys/boot/ficl/ficl.h#2 integrate ... //depot/projects/smpng/sys/boot/ficl/fileaccess.c#1 branch ... //depot/projects/smpng/sys/boot/ficl/float.c#1 branch ... //depot/projects/smpng/sys/boot/ficl/i386/sysdep.h#2 integrate ... //depot/projects/smpng/sys/boot/ficl/ia64/sysdep.h#2 integrate ... //depot/projects/smpng/sys/boot/ficl/loader.c#4 integrate ... //depot/projects/smpng/sys/boot/ficl/math64.c#2 integrate ... //depot/projects/smpng/sys/boot/ficl/math64.h#2 integrate ... //depot/projects/smpng/sys/boot/ficl/prefix.c#2 integrate ... //depot/projects/smpng/sys/boot/ficl/search.c#2 integrate ... //depot/projects/smpng/sys/boot/ficl/softwords/ficlclass.fr#1 branch ... //depot/projects/smpng/sys/boot/ficl/softwords/fileaccess.fr#1 branch ... //depot/projects/smpng/sys/boot/ficl/softwords/forml.fr#1 branch ... //depot/projects/smpng/sys/boot/ficl/softwords/ifbrack.fr#2 integrate ... //depot/projects/smpng/sys/boot/ficl/softwords/marker.fr#2 integrate ... //depot/projects/smpng/sys/boot/ficl/softwords/oo.fr#2 integrate ... //depot/projects/smpng/sys/boot/ficl/softwords/prefix.fr#2 integrate ... //depot/projects/smpng/sys/boot/ficl/softwords/softcore.fr#2 integrate ... //depot/projects/smpng/sys/boot/ficl/stack.c#2 integrate ... //depot/projects/smpng/sys/boot/ficl/testmain.c#2 integrate ... //depot/projects/smpng/sys/boot/ficl/tools.c#2 integrate ... //depot/projects/smpng/sys/boot/ficl/vm.c#2 integrate ... //depot/projects/smpng/sys/boot/ficl/words.c#3 integrate ... //depot/projects/smpng/sys/compat/linprocfs/linprocfs.c#14 integrate ... //depot/projects/smpng/sys/compat/pecoff/imgact_pecoff.c#10 integrate ... //depot/projects/smpng/sys/conf/NOTES#4 integrate ... //depot/projects/smpng/sys/conf/files#33 integrate ... //depot/projects/smpng/sys/conf/majors#8 integrate ... //depot/projects/smpng/sys/conf/options#19 integrate ... //depot/projects/smpng/sys/dev/eisa/eisaconf.c#2 integrate ... //depot/projects/smpng/sys/dev/fb/vga.c#6 integrate ... //depot/projects/smpng/sys/dev/kbd/atkbd.c#4 integrate ... //depot/projects/smpng/sys/dev/null/null.c#6 integrate ... //depot/projects/smpng/sys/dev/se/se_console.c#1 branch ... //depot/projects/smpng/sys/dev/se/sereg.h#1 branch ... //depot/projects/smpng/sys/dev/usb/usb.c#13 integrate ... //depot/projects/smpng/sys/geom/geom.h#5 integrate ... //depot/projects/smpng/sys/geom/geom_bsd.c#6 integrate ... //depot/projects/smpng/sys/geom/geom_dev.c#5 integrate ... //depot/projects/smpng/sys/geom/geom_disk.c#6 integrate ... //depot/projects/smpng/sys/geom/geom_io.c#6 integrate ... //depot/projects/smpng/sys/geom/geom_mbr.c#5 integrate ... //depot/projects/smpng/sys/geom/geom_pc98.c#3 integrate ... //depot/projects/smpng/sys/geom/geom_slice.c#4 integrate ... //depot/projects/smpng/sys/geom/geom_slice.h#4 integrate ... //depot/projects/smpng/sys/geom/geom_subr.c#4 integrate ... //depot/projects/smpng/sys/geom/geom_sunlabel.c#5 integrate ... //depot/projects/smpng/sys/i386/conf/GENERIC#18 integrate ... //depot/projects/smpng/sys/i386/conf/NEWCARD#12 integrate ... //depot/projects/smpng/sys/i386/conf/NOTES#34 integrate ... //depot/projects/smpng/sys/i386/i386/machdep.c#35 integrate ... //depot/projects/smpng/sys/i386/include/md_var.h#10 integrate ... //depot/projects/smpng/sys/i386/include/uc_device.h#2 delete ... //depot/projects/smpng/sys/i386/isa/isa_device.h#2 integrate ... //depot/projects/smpng/sys/i386/isa/pcvt/pcvt_drv.c#6 integrate ... //depot/projects/smpng/sys/ia64/ia64/machdep.c#34 integrate ... //depot/projects/smpng/sys/ia64/ia64/ssc.c#8 integrate ... //depot/projects/smpng/sys/ia64/include/ia64_cpu.h#7 integrate ... //depot/projects/smpng/sys/isa/pnpreg.h#2 integrate ... //depot/projects/smpng/sys/kern/imgact_aout.c#11 integrate ... //depot/projects/smpng/sys/kern/kern_acct.c#13 integrate ... //depot/projects/smpng/sys/kern/kern_exit.c#30 integrate ... //depot/projects/smpng/sys/kern/kern_fork.c#34 integrate ... //depot/projects/smpng/sys/kern/kern_intr.c#15 integrate ... //depot/projects/smpng/sys/kern/kern_proc.c#25 integrate ... //depot/projects/smpng/sys/kern/subr_disk.c#9 integrate ... //depot/projects/smpng/sys/kern/sys_process.c#12 integrate ... //depot/projects/smpng/sys/kern/vfs_cache.c#11 integrate ... //depot/projects/smpng/sys/kern/vfs_syscalls.c#35 integrate ... //depot/projects/smpng/sys/kern/vfs_vnops.c#22 integrate ... //depot/projects/smpng/sys/netinet/in.h#9 integrate ... //depot/projects/smpng/sys/netinet/in_pcb.c#23 integrate ... //depot/projects/smpng/sys/netinet/in_pcb.h#10 integrate ... //depot/projects/smpng/sys/netinet/ip_divert.c#13 integrate ... //depot/projects/smpng/sys/pc98/conf/GENERIC#18 integrate ... //depot/projects/smpng/sys/pc98/i386/machdep.c#31 integrate ... //depot/projects/smpng/sys/powerpc/powerpc/machdep.c#22 integrate ... //depot/projects/smpng/sys/sparc64/conf/GENERIC#10 integrate ... //depot/projects/smpng/sys/sparc64/include/emul.h#1 branch ... //depot/projects/smpng/sys/sparc64/include/frame.h#10 integrate ... //depot/projects/smpng/sys/sparc64/include/reg.h#9 integrate ... //depot/projects/smpng/sys/sparc64/sparc64/db_trace.c#10 integrate ... //depot/projects/smpng/sys/sparc64/sparc64/emul.c#3 integrate ... //depot/projects/smpng/sys/sparc64/sparc64/machdep.c#25 integrate ... //depot/projects/smpng/sys/sparc64/sparc64/trap.c#31 integrate ... //depot/projects/smpng/sys/sparc64/sparc64/vm_machdep.c#18 integrate ... //depot/projects/smpng/sys/sys/bio.h#7 integrate ... //depot/projects/smpng/sys/sys/disk.h#6 integrate ... //depot/projects/smpng/sys/sys/ioccom.h#4 integrate ... //depot/projects/smpng/sys/vm/uma_int.h#6 integrate Differences ... ==== //depot/projects/smpng/sys/alpha/alpha/machdep.c#40 (text+ko) ==== @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/sys/alpha/alpha/machdep.c,v 1.175 2002/04/07 21:01:34 phk Exp $ + * $FreeBSD: src/sys/alpha/alpha/machdep.c,v 1.176 2002/04/09 11:18:26 phk Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -278,18 +278,6 @@ vm_ksubmap_init(&kmi); -#if defined(USERCONFIG) -#if defined(USERCONFIG_BOOT) - if (1) -#else - if (boothowto & RB_CONFIG) -#endif - { - userconfig(); - cninit(); /* the preferred console may have changed */ - } -#endif - printf("avail memory = %ld (%ldK bytes)\n", ptoa(cnt.v_free_count), ptoa(cnt.v_free_count) / 1024); ==== //depot/projects/smpng/sys/boot/common/load_elf.c#4 (text+ko) ==== @@ -24,7 +24,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/sys/boot/common/load_elf.c,v 1.22 2002/04/06 04:09:42 peter Exp $ + * $FreeBSD: src/sys/boot/common/load_elf.c,v 1.23 2002/04/09 00:05:46 jake Exp $ */ #include @@ -622,7 +622,7 @@ elf_lookup_symbol(struct preloaded_file *fp, elf_file_t ef, const char* name, Elf_Sym *symp) { - unsigned long symnum; + Elf_Hashelt symnum; Elf_Sym sym; char *strp; unsigned long hash; ==== //depot/projects/smpng/sys/boot/ficl/Makefile#2 (text+ko) ==== @@ -1,8 +1,9 @@ -# $FreeBSD: src/sys/boot/ficl/Makefile,v 1.26 2001/04/29 02:36:33 dcs Exp $ +# $FreeBSD: src/sys/boot/ficl/Makefile,v 1.27 2002/04/09 17:45:11 dcs Exp $ # .PATH: ${.CURDIR}/${MACHINE_ARCH} -BASE_SRCS= dict.c ficl.c math64.c search.c stack.c tools.c \ - prefix.c loader.c vm.c words.c +BASE_SRCS= dict.c ficl.c fileaccess.c float.c loader.c math64.c \ + prefix.c search.c stack.c tools.c vm.c words.c + SRCS= ${BASE_SRCS} sysdep.c softcore.c CLEANFILES= softcore.c testmain testmain.o .if ${MACHINE_ARCH} == "alpha" ==== //depot/projects/smpng/sys/boot/ficl/alpha/sysdep.h#2 (text+ko) ==== @@ -9,7 +9,7 @@ ** FICL_ROBUST is enabled. This may require some consideration ** in firmware systems since assert often ** assumes stderr/stdout. -** $Id: sysdep.h,v 1.6 2001-04-26 21:41:55-07 jsadler Exp jsadler $ +** $Id: sysdep.h,v 1.11 2001/12/05 07:21:34 jsadler Exp $ *******************************************************************/ /* ** Copyright (c) 1997-2001 John Sadler (john_sadler@alum.mit.edu) @@ -17,6 +17,11 @@ ** ** Get the latest Ficl release at http://ficl.sourceforge.net ** +** I am interested in hearing from anyone who uses ficl. If you have +** a problem, a success story, a defect, an enhancement request, or +** if you would like to contribute to the ficl release, please +** contact me by email at the address above. +** ** L I C E N S E and D I S C L A I M E R ** ** Redistribution and use in source and binary forms, with or without @@ -39,16 +44,9 @@ ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY ** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ** SUCH DAMAGE. -** -** I am interested in hearing from anyone who uses ficl. If you have -** a problem, a success story, a defect, an enhancement request, or -** if you would like to contribute to the ficl release, please send -** contact me by email at the address above. -** -** $Id: sysdep.h,v 1.6 2001-04-26 21:41:55-07 jsadler Exp jsadler $ */ -/* $FreeBSD: src/sys/boot/ficl/alpha/sysdep.h,v 1.7 2001/04/29 02:36:35 dcs Exp $ */ +/* $FreeBSD: src/sys/boot/ficl/alpha/sysdep.h,v 1.8 2002/04/09 17:45:22 dcs Exp $ */ #if !defined (__SYSDEP_H__) #define __SYSDEP_H__ @@ -75,7 +73,6 @@ #define FALSE 0 #endif - /* ** System dependent data type declarations... */ @@ -162,6 +159,7 @@ #endif #if (FICL_MINIMAL) #define FICL_WANT_SOFTWORDS 0 +#define FICL_WANT_FILE 0 #define FICL_WANT_FLOAT 0 #define FICL_WANT_USER 0 #define FICL_WANT_LOCALS 0 @@ -181,6 +179,17 @@ #define FICL_PLATFORM_EXTEND 1 #endif + +/* +** FICL_WANT_FILE +** Includes the FILE and FILE-EXT wordset and associated code. Turn this off if you do not +** have a file system! +** Contributed by Larry Hastings +*/ +#if !defined (FICL_WANT_FILE) +#define FICL_WANT_FILE 0 +#endif + /* ** FICL_WANT_FLOAT ** Includes a floating point stack for the VM, and words to do float operations. @@ -199,6 +208,14 @@ #endif /* +** FICL_EXTENDED_PREFIX enables a bunch of extra prefixes in prefix.c and prefix.fr (if +** included as part of softcore.c) +*/ +#if !defined FICL_EXTENDED_PREFIX +#define FICL_EXTENDED_PREFIX 0 +#endif + +/* ** User variables: per-instance variables bound to the VM. ** Kinda like thread-local storage. Could be implemented in a ** VM private dictionary, but I've chosen the lower overhead @@ -341,14 +358,6 @@ #endif /* -** FICL_EXTENDED_PREFIX enables a bunch of extra prefixes in prefix.c and prefix.fr (if -** included as part of softcore.c) -*/ -#if !defined FICL_EXTENDED_PREFIX -#define FICL_EXTENDED_PREFIX 0 -#endif - -/* ** FICL_ALIGN is the power of two to which the dictionary ** pointer address must be aligned. This value is usually ** either 1 or 2, depending on the memory architecture @@ -409,4 +418,15 @@ DPUNS ficlLongMul(FICL_UNS x, FICL_UNS y); UNSQR ficlLongDiv(DPUNS q, FICL_UNS y); + +/* +** FICL_HAVE_FTRUNCATE indicates whether the current OS supports +** the ftruncate() function (available on most UNIXes). This +** function is necessary to provide the complete File-Access wordset. +*/ +#if !defined (FICL_HAVE_FTRUNCATE) +#define FICL_HAVE_FTRUNCATE 0 +#endif + + #endif /*__SYSDEP_H__*/ ==== //depot/projects/smpng/sys/boot/ficl/dict.c#2 (text+ko) ==== @@ -3,7 +3,7 @@ ** Forth Inspired Command Language - dictionary methods ** Author: John Sadler (john_sadler@alum.mit.edu) ** Created: 19 July 1997 -** $Id: dict.c,v 1.6 2000-06-17 07:43:44-07 jsadler Exp jsadler $ +** $Id: dict.c,v 1.14 2001/12/05 07:21:34 jsadler Exp $ *******************************************************************/ /* ** This file implements the dictionary -- FICL's model of @@ -22,6 +22,11 @@ ** ** Get the latest Ficl release at http://ficl.sourceforge.net ** +** I am interested in hearing from anyone who uses ficl. If you have +** a problem, a success story, a defect, an enhancement request, or +** if you would like to contribute to the ficl release, please +** contact me by email at the address above. +** ** L I C E N S E and D I S C L A I M E R ** ** Redistribution and use in source and binary forms, with or without @@ -44,20 +49,12 @@ ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY ** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ** SUCH DAMAGE. -** -** I am interested in hearing from anyone who uses ficl. If you have -** a problem, a success story, a defect, an enhancement request, or -** if you would like to contribute to the ficl release, please send -** contact me by email at the address above. -** -** $Id: dict.c,v 1.8 2001-04-26 21:41:45-07 jsadler Exp jsadler $ */ -/* $FreeBSD: src/sys/boot/ficl/dict.c,v 1.12 2001/05/29 23:44:12 dcs Exp $ */ +/* $FreeBSD: src/sys/boot/ficl/dict.c,v 1.13 2002/04/09 17:45:11 dcs Exp $ */ #ifdef TESTMAIN #include -#include #include #else #include @@ -304,16 +301,19 @@ /************************************************************************** d i c t C h e c k ** Checks the dictionary for corruption and throws appropriate -** errors +** errors. +** Input: +n number of ADDRESS UNITS (not Cells) proposed to allot +** -n number of ADDRESS UNITS proposed to de-allot +** 0 just do a consistency check **************************************************************************/ -void dictCheck(FICL_DICT *pDict, FICL_VM *pVM, int nCells) +void dictCheck(FICL_DICT *pDict, FICL_VM *pVM, int n) { - if ((nCells >= 0) && (dictCellsAvail(pDict) < nCells)) + if ((n >= 0) && (dictCellsAvail(pDict) * (int)sizeof(CELL) < n)) { vmThrowErr(pVM, "Error: dictionary full"); } - if ((nCells <= 0) && (dictCellsUsed(pDict) < -nCells)) + if ((n <= 0) && (dictCellsUsed(pDict) * (int)sizeof(CELL) < -n)) { vmThrowErr(pVM, "Error: dictionary underflow"); } @@ -396,6 +396,7 @@ memset(pDict, 0, sizeof (FICL_DICT)); pDict->dict = ficlMalloc(nAlloc); assert(pDict->dict); + pDict->size = nCells; dictEmpty(pDict, nHash); return pDict; @@ -460,6 +461,84 @@ /************************************************************************** + d i c t H a s h S u m m a r y +** Calculate a figure of merit for the dictionary hash table based +** on the average search depth for all the words in the dictionary, +** assuming uniform distribution of target keys. The figure of merit +** is the ratio of the total search depth for all keys in the table +** versus a theoretical optimum that would be achieved if the keys +** were distributed into the table as evenly as possible. +** The figure would be worse if the hash table used an open +** addressing scheme (i.e. collisions resolved by searching the +** table for an empty slot) for a given size table. +**************************************************************************/ +#if FICL_WANT_FLOAT +void dictHashSummary(FICL_VM *pVM) +{ + FICL_DICT *dp = vmGetDict(pVM); + FICL_HASH *pFHash; + FICL_WORD **pHash; + unsigned size; + FICL_WORD *pFW; + unsigned i; + int nMax = 0; + int nWords = 0; + int nFilled; + double avg = 0.0; + double best; + int nAvg, nRem, nDepth; + + dictCheck(dp, pVM, 0); + + pFHash = dp->pSearch[dp->nLists - 1]; + pHash = pFHash->table; + size = pFHash->size; + nFilled = size; + + for (i = 0; i < size; i++) + { + int n = 0; + pFW = pHash[i]; + + while (pFW) + { + ++n; + ++nWords; + pFW = pFW->link; + } + + avg += (double)(n * (n+1)) / 2.0; + + if (n > nMax) + nMax = n; + if (n == 0) + --nFilled; + } + + /* Calc actual avg search depth for this hash */ + avg = avg / nWords; + + /* Calc best possible performance with this size hash */ + nAvg = nWords / size; + nRem = nWords % size; + nDepth = size * (nAvg * (nAvg+1))/2 + (nAvg+1)*nRem; + best = (double)nDepth/nWords; + + sprintf(pVM->pad, + "%d bins, %2.0f%% filled, Depth: Max=%d, Avg=%2.1f, Best=%2.1f, Score: %2.0f%%", + size, + (double)nFilled * 100.0 / size, nMax, + avg, + best, + 100.0 * best / avg); + + ficlTextOut(pVM, pVM->pad, 1); + + return; +} +#endif + +/************************************************************************** d i c t I n c l u d e s ** Returns TRUE iff the given pointer is within the address range of ** the dictionary. @@ -471,7 +550,6 @@ ); } - /************************************************************************** d i c t L o o k u p ** Find the FICL_WORD that matches the given name and length. @@ -501,15 +579,16 @@ /************************************************************************** - d i c t L o o k u p L o c + f i c l L o o k u p L o c ** Same as dictLookup, but looks in system locals dictionary first... ** Assumes locals dictionary has only one wordlist... **************************************************************************/ #if FICL_WANT_LOCALS -FICL_WORD *dictLookupLoc(FICL_DICT *pDict, STRINGINFO si) +FICL_WORD *ficlLookupLoc(FICL_SYSTEM *pSys, STRINGINFO si) { FICL_WORD *pFW = NULL; - FICL_HASH *pHash = ficlGetLoc()->pForthWords; + FICL_DICT *pDict = pSys->dp; + FICL_HASH *pHash = ficlGetLoc(pSys)->pForthWords; int i; UNS16 hashCode = hashHashCode(si); ==== //depot/projects/smpng/sys/boot/ficl/ficl.c#2 (text+ko) ==== @@ -3,7 +3,7 @@ ** Forth Inspired Command Language - external interface ** Author: John Sadler (john_sadler@alum.mit.edu) ** Created: 19 July 1997 -** $Id: ficl.c,v 1.10 2001-04-26 21:41:42-07 jsadler Exp jsadler $ +** $Id: ficl.c,v 1.16 2001/12/05 07:21:34 jsadler Exp $ *******************************************************************/ /* ** This is an ANS Forth interpreter written in C. @@ -26,6 +26,11 @@ ** ** Get the latest Ficl release at http://ficl.sourceforge.net ** +** I am interested in hearing from anyone who uses ficl. If you have +** a problem, a success story, a defect, an enhancement request, or +** if you would like to contribute to the ficl release, please +** contact me by email at the address above. +** ** L I C E N S E and D I S C L A I M E R ** ** Redistribution and use in source and binary forms, with or without @@ -48,16 +53,9 @@ ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY ** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ** SUCH DAMAGE. -** -** I am interested in hearing from anyone who uses ficl. If you have -** a problem, a success story, a defect, an enhancement request, or -** if you would like to contribute to the ficl release, please send -** contact me by email at the address above. -** -** $Id: ficl.c,v 1.10 2001-04-26 21:41:42-07 jsadler Exp jsadler $ */ -/* $FreeBSD: src/sys/boot/ficl/ficl.c,v 1.17 2001/04/29 02:36:33 dcs Exp $ */ +/* $FreeBSD: src/sys/boot/ficl/ficl.c,v 1.18 2002/04/09 17:45:11 dcs Exp $ */ #ifdef TESTMAIN #include @@ -70,19 +68,19 @@ /* ** System statics -** The system builds a global dictionary during its start -** sequence. This is shared by all interpreter instances. -** Therefore only one instance can update the dictionary +** Each FICL_SYSTEM builds a global dictionary during its start +** sequence. This is shared by all virtual machines of that system. +** Therefore only one VM can update the dictionary ** at a time. The system imports a locking function that ** you can override in order to control update access to ** the dictionary. The function is stubbed out by default, ** but you can insert one: #define FICL_MULTITHREAD 1 ** and supply your own version of ficlLockDictionary. */ -static FICL_SYSTEM *pSys = NULL; +static int defaultStack = FICL_DEFAULT_STACK; + -static int defaultStack = FICL_DEFAULT_STACK; -static int defaultDict = FICL_DEFAULT_DICT; +static void ficlSetVersionEnv(FICL_SYSTEM *pSys); /************************************************************************** @@ -96,67 +94,94 @@ ** precompiled part. Try 1K cells minimum. Use "words" to find ** out how much of the dictionary is used at any time. **************************************************************************/ -void ficlInitSystem(int nDictCells) +FICL_SYSTEM *ficlInitSystemEx(FICL_SYSTEM_INFO *fsi) { - pSys = ficlMalloc(sizeof (FICL_SYSTEM)); + int nDictCells; + int nEnvCells; + FICL_SYSTEM *pSys = ficlMalloc(sizeof (FICL_SYSTEM)); + assert(pSys); + assert(fsi->size == sizeof (FICL_SYSTEM_INFO)); memset(pSys, 0, sizeof (FICL_SYSTEM)); + nDictCells = fsi->nDictCells; if (nDictCells <= 0) - nDictCells = defaultDict; + nDictCells = FICL_DEFAULT_DICT; + + nEnvCells = fsi->nEnvCells; + if (nEnvCells <= 0) + nEnvCells = FICL_DEFAULT_DICT; pSys->dp = dictCreateHashed((unsigned)nDictCells, HASHSIZE); pSys->dp->pForthWords->name = "forth-wordlist"; - pSys->envp = dictCreate((unsigned)FICL_DEFAULT_ENV); + pSys->envp = dictCreate((unsigned)nEnvCells); pSys->envp->pForthWords->name = "environment"; + pSys->textOut = fsi->textOut; + pSys->pExtend = fsi->pExtend; + #if FICL_WANT_LOCALS /* ** The locals dictionary is only searched while compiling, ** but this is where speed is most important. On the other ** hand, the dictionary gets emptied after each use of locals - ** The need to balance search speed with the cost of the empty + ** The need to balance search speed with the cost of the 'empty' ** operation led me to select a single-threaded list... */ pSys->localp = dictCreate((unsigned)FICL_MAX_LOCALS * CELLS_PER_WORD); #endif /* - ** Establish the parse order. Note that prefixes precede numbers - - ** this allows constructs like "0b101010" which would parse as a - ** valid hex value otherwise. - */ - ficlCompilePrefix(pSys); - ficlAddPrecompiledParseStep(pSys, "number?", ficlParseNumber); - - /* ** Build the precompiled dictionary and load softwords. We need a temporary ** VM to do this - ficlNewVM links one to the head of the system VM list. ** ficlCompilePlatform (defined in win32.c, for example) adds platform specific words. */ ficlCompileCore(pSys); + ficlCompilePrefix(pSys); #if FICL_WANT_FLOAT ficlCompileFloat(pSys); #endif - #if FICL_PLATFORM_EXTEND ficlCompilePlatform(pSys); #endif + ficlSetVersionEnv(pSys); + + /* + ** Establish the parse order. Note that prefixes precede numbers - + ** this allows constructs like "0b101010" which might parse as a + ** hex value otherwise. + */ + ficlAddPrecompiledParseStep(pSys, "?prefix", ficlParsePrefix); + ficlAddPrecompiledParseStep(pSys, "?number", ficlParseNumber); +#if FICL_WANT_FLOAT + ficlAddPrecompiledParseStep(pSys, ">float", ficlParseFloatNumber); +#endif /* - ** Now we can create a VM to compile the softwords. Note that the VM initialization - ** code needs to be able to find "interpret" in the dictionary in order to - ** succeed, so as presently constructed ficlCompileCore has to finish before - ** a VM can be created successfully. + ** Now create a temporary VM to compile the softwords. Since all VMs are + ** linked into the vmList of FICL_SYSTEM, we don't have to pass the VM + ** to ficlCompileSoftCore -- it just hijacks whatever it finds in the VM list. + ** ficl 2.05: vmCreate no longer depends on the presence of INTERPRET in the + ** dictionary, so a VM can be created before the dictionary is built. It just + ** can't do much... */ - ficlNewVM(); + ficlNewVM(pSys); ficlCompileSoftCore(pSys); ficlFreeVM(pSys->vmList); - return; + return pSys; +} + + +FICL_SYSTEM *ficlInitSystem(int nDictCells) +{ + FICL_SYSTEM_INFO fsi; + ficlInitInfo(&fsi); + fsi.nDictCells = nDictCells; + return ficlInitSystemEx(&fsi); } @@ -226,11 +251,13 @@ ** Create a new virtual machine and link it into the system list ** of VMs for later cleanup by ficlTermSystem. **************************************************************************/ -FICL_VM *ficlNewVM(void) +FICL_VM *ficlNewVM(FICL_SYSTEM *pSys) { FICL_VM *pVM = vmCreate(NULL, defaultStack, defaultStack); pVM->link = pSys->vmList; pVM->pSys = pSys; + pVM->pExtend = pSys->pExtend; + vmSetTextOut(pVM, pSys->textOut); pSys->vmList = pVM; return pVM; @@ -246,6 +273,7 @@ **************************************************************************/ void ficlFreeVM(FICL_VM *pVM) { + FICL_SYSTEM *pSys = pVM->pSys; FICL_VM *pList = pSys->vmList; assert(pVM != 0); @@ -284,10 +312,12 @@ ** flags -- 0 or more of F_IMMEDIATE, F_COMPILE, use bitwise OR! ** **************************************************************************/ -int ficlBuild(char *name, FICL_CODE code, char flags) +int ficlBuild(FICL_SYSTEM *pSys, char *name, FICL_CODE code, char flags) { +#if FICL_MULTITHREAD int err = ficlLockDictionary(TRUE); if (err) return err; +#endif /* FICL_MULTITHREAD */ assert(dictCellsAvail(pSys->dp) > sizeof (FICL_WORD) / sizeof (CELL)); dictAppendWord(pSys->dp, name, code, flags); @@ -298,6 +328,21 @@ /************************************************************************** + f i c l E v a l u a t e +** Wrapper for ficlExec() which sets SOURCE-ID to -1. +**************************************************************************/ +int ficlEvaluate(FICL_VM *pVM, char *pText) +{ + int returnValue; + CELL id = pVM->sourceID; + pVM->sourceID.i = -1; + returnValue = ficlExecC(pVM, pText, -1); + pVM->sourceID = id; + return returnValue; +} + + +/************************************************************************** f i c l E x e c ** Evaluates a block of input text in the context of the ** specified interpreter. Emits any requested output to the @@ -322,23 +367,16 @@ int ficlExecC(FICL_VM *pVM, char *pText, FICL_INT size) { - FICL_WORD **pInterp = pSys->pInterp; - FICL_DICT *dp = pSys->dp; + FICL_SYSTEM *pSys = pVM->pSys; + FICL_DICT *dp = pSys->dp; int except; jmp_buf vmState; jmp_buf *oldState; TIB saveTib; - if (!pInterp[0]) - { - pInterp[0] = ficlLookup("interpret"); - pInterp[1] = ficlLookup("(branch)"); - pInterp[2] = (FICL_WORD *)(void *)(-2); - } - - assert(pInterp[0]); assert(pVM); + assert(pSys->pInterp[0]); if (size < 0) size = strlen(pText); @@ -362,7 +400,7 @@ } else { /* set VM up to interpret text */ - vmPushIP(pVM, &pInterp[0]); + vmPushIP(pVM, &(pSys->pInterp[0])); } vmInnerLoop(pVM); @@ -438,17 +476,13 @@ **************************************************************************/ int ficlExecXT(FICL_VM *pVM, FICL_WORD *pWord) { - static FICL_WORD *pQuit = NULL; int except; jmp_buf vmState; jmp_buf *oldState; FICL_WORD *oldRunningWord; - if (!pQuit) - pQuit = ficlLookup("exit-inner"); - assert(pVM); - assert(pQuit); + assert(pVM->pSys->pExitInner); /* ** Save the runningword so that RESTART behaves correctly @@ -465,7 +499,7 @@ if (except) vmPopIP(pVM); else - vmPushIP(pVM, &pQuit); + vmPushIP(pVM, &(pVM->pSys->pExitInner)); switch (except) { @@ -506,7 +540,7 @@ ** found, return the address of the corresponding FICL_WORD. Otherwise ** return NULL. **************************************************************************/ -FICL_WORD *ficlLookup(char *name) +FICL_WORD *ficlLookup(FICL_SYSTEM *pSys, char *name) { STRINGINFO si; SI_PSZ(si, name); @@ -518,7 +552,7 @@ f i c l G e t D i c t ** Returns the address of the system dictionary **************************************************************************/ -FICL_DICT *ficlGetDict(void) +FICL_DICT *ficlGetDict(FICL_SYSTEM *pSys) { return pSys->dp; } @@ -528,7 +562,7 @@ f i c l G e t E n v ** Returns the address of the system environment space **************************************************************************/ -FICL_DICT *ficlGetEnv(void) +FICL_DICT *ficlGetEnv(FICL_SYSTEM *pSys) { return pSys->envp; } @@ -539,7 +573,7 @@ ** Create an environment variable with a one-CELL payload. ficlSetEnvD ** makes one with a two-CELL payload. **************************************************************************/ -void ficlSetEnv(char *name, FICL_UNS value) +void ficlSetEnv(FICL_SYSTEM *pSys, char *name, FICL_UNS value) { STRINGINFO si; FICL_WORD *pFW; @@ -561,7 +595,7 @@ return; } -void ficlSetEnvD(char *name, FICL_UNS hi, FICL_UNS lo) +void ficlSetEnvD(FICL_SYSTEM *pSys, char *name, FICL_UNS hi, FICL_UNS lo) { FICL_WORD *pFW; STRINGINFO si; @@ -591,7 +625,7 @@ ** only used during compilation, and is shared by all VMs. **************************************************************************/ #if FICL_WANT_LOCALS -FICL_DICT *ficlGetLoc(void) +FICL_DICT *ficlGetLoc(FICL_SYSTEM *pSys) { return pSys->localp; } @@ -620,7 +654,7 @@ ** Tear the system down by deleting the dictionaries and all VMs. ** This saves you from having to keep track of all that stuff. **************************************************************************/ -void ficlTermSystem(void) +void ficlTermSystem(FICL_SYSTEM *pSys) { if (pSys->dp) dictDelete(pSys->dp); @@ -649,3 +683,14 @@ } +/************************************************************************** + f i c l S e t V e r s i o n E n v +** Create a double cell environment constant for the version ID +**************************************************************************/ +static void ficlSetVersionEnv(FICL_SYSTEM *pSys) +{ + ficlSetEnvD(pSys, "ficl-version", FICL_VER_MAJOR, FICL_VER_MINOR); + ficlSetEnv (pSys, "ficl-robust", FICL_ROBUST); + return; +} + ==== //depot/projects/smpng/sys/boot/ficl/ficl.h#2 (text+ko) ==== @@ -3,7 +3,8 @@ ** Forth Inspired Command Language ** Author: John Sadler (john_sadler@alum.mit.edu) ** Created: 19 July 1997 -** $Id: ficl.h,v 1.11 2001-04-26 21:41:48-07 jsadler Exp jsadler $ +** Dedicated to RHS, in loving memory +** $Id: ficl.h,v 1.18 2001/12/05 07:21:34 jsadler Exp $ *******************************************************************/ /* ** Copyright (c) 1997-2001 John Sadler (john_sadler@alum.mit.edu) @@ -11,6 +12,11 @@ ** ** Get the latest Ficl release at http://ficl.sourceforge.net ** +** I am interested in hearing from anyone who uses ficl. If you have +** a problem, a success story, a defect, an enhancement request, or +** if you would like to contribute to the ficl release, please +** contact me by email at the address above. +** ** L I C E N S E and D I S C L A I M E R ** ** Redistribution and use in source and binary forms, with or without @@ -33,16 +39,9 @@ ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY ** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ** SUCH DAMAGE. -** -** I am interested in hearing from anyone who uses ficl. If you have -** a problem, a success story, a defect, an enhancement request, or -** if you would like to contribute to the ficl release, please send -** contact me by email at the address above. -** -** $Id: ficl.h,v 1.11 2001-04-26 21:41:48-07 jsadler Exp jsadler $ */ -/* $FreeBSD: src/sys/boot/ficl/ficl.h,v 1.19 2001/05/29 23:44:12 dcs Exp $ */ +/* $FreeBSD: src/sys/boot/ficl/ficl.h,v 1.20 2002/04/09 17:45:11 dcs Exp $ */ #if !defined (__FICL_H__) #define __FICL_H__ @@ -125,17 +124,14 @@ ** T o D o L i s t ** ** 1. Unimplemented system dependent CORE word: key -** 2. Kludged CORE word: ACCEPT -** 3. Dictionary locking is full of holes - only one vm at a time -** can alter the dict. -** 4. Ficl uses the pad in CORE words - this violates the standard, +** 2. Ficl uses the PAD in some CORE words - this violates the standard, ** but it's cleaner for a multithreaded system. I'll have to make a ** second pad for reference by the word PAD to fix this. ** ** F o r M o r e I n f o r m a t i o n ** ** Web home of ficl -** http://www.taygeta.com/forth/compilers +** http://ficl.sourceforge.net ** Check this website for Forth literature (including the ANSI standard) ** http://www.taygeta.com/forthlit.html ** and here for software and more links @@ -154,7 +150,7 @@ ** - Make the main hash table a bigger prime (HASHSIZE) ** - FORGET about twiddling the hash function - my experience is ** that that is a waste of time. -** - eliminate the need to pass the pVM parameter on the stack +** - Eliminate the need to pass the pVM parameter on the stack ** by dedicating a register to it. Most words need access to the ** vm, but the parameter passing overhead can be reduced. One way ** requires that the host OS have a task switch callout. Create @@ -228,15 +224,22 @@ ** Forward declarations... read on. */ struct ficl_word; +typedef struct ficl_word FICL_WORD; struct vm; +typedef struct vm FICL_VM; struct ficl_dict; +typedef struct ficl_dict FICL_DICT; struct ficl_system; typedef struct ficl_system FICL_SYSTEM; +struct ficl_system_info; +typedef struct ficl_system_info FICL_SYSTEM_INFO; /* ** the Good Stuff starts here... */ -#define FICL_VER "2.05" +#define FICL_VER "3.02" +#define FICL_VER_MAJOR 3 +#define FICL_VER_MINOR 2 #if !defined (FICL_PROMPT) #define FICL_PROMPT "ok> " #endif @@ -254,7 +257,8 @@ /* ** A CELL is the main storage type. It must be large enough ** to contain a pointer or a scalar. In order to accommodate -** 32 bit and 64 bit processors, use abstract types for i and u. +** 32 bit and 64 bit processors, use abstract types for int, +** unsigned, and float. */ typedef union _cell { @@ -268,7 +272,7 @@ } CELL; /* -** LVALUEtoCELL does a little pointer trickery to cast any 32 bit +** LVALUEtoCELL does a little pointer trickery to cast any CELL sized ** lvalue (informal definition: an expression whose result has an ** address) to CELL. Remember that constants and casts are NOT ** themselves lvalues! @@ -363,59 +367,59 @@ /* ** Stack methods... many map closely to required Forth words. */ -FICL_STACK *stackCreate(unsigned nCells); -void stackDelete(FICL_STACK *pStack); -int stackDepth (FICL_STACK *pStack); -void stackDrop (FICL_STACK *pStack, int n); -CELL stackFetch (FICL_STACK *pStack, int n); -CELL stackGetTop(FICL_STACK *pStack); -void stackLink (FICL_STACK *pStack, int nCells); -void stackPick (FICL_STACK *pStack, int n); -CELL stackPop (FICL_STACK *pStack); -void *stackPopPtr(FICL_STACK *pStack); -FICL_UNS stackPopUNS(FICL_STACK *pStack); -FICL_INT stackPopINT(FICL_STACK *pStack); >>> TRUNCATED FOR MAIL (1000 lines) <<< To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe p4-projects" in the body of the message