1ca987d46SWarner Losh /*******************************************************************
2ca987d46SWarner Losh ** s y s d e p . c
3ca987d46SWarner Losh ** Forth Inspired Command Language
4ca987d46SWarner Losh ** Author: John Sadler (john_sadler@alum.mit.edu)
5ca987d46SWarner Losh ** Created: 16 Oct 1997
6ca987d46SWarner Losh ** Implementations of FICL external interface functions...
7ca987d46SWarner Losh **
8ca987d46SWarner Losh *******************************************************************/
9ca987d46SWarner Losh
10ca987d46SWarner Losh
11ca987d46SWarner Losh #ifdef TESTMAIN
12ca987d46SWarner Losh #include <stdio.h>
13ca987d46SWarner Losh #include <stdlib.h>
14ca987d46SWarner Losh #else
15ca987d46SWarner Losh #include <stand.h>
16ca987d46SWarner Losh #endif
17ca987d46SWarner Losh #include "ficl.h"
18ca987d46SWarner Losh
19ca987d46SWarner Losh /*
20ca987d46SWarner Losh ******************* FreeBSD P O R T B E G I N S H E R E ******************** Michael Smith
21ca987d46SWarner Losh */
22ca987d46SWarner Losh
23ca987d46SWarner Losh #if PORTABLE_LONGMULDIV == 0
ficlLongMul(FICL_UNS x,FICL_UNS y)24ca987d46SWarner Losh DPUNS ficlLongMul(FICL_UNS x, FICL_UNS y)
25ca987d46SWarner Losh {
26ca987d46SWarner Losh DPUNS q;
27*56e53cb8SWarner Losh uint64_t qx;
28ca987d46SWarner Losh
29*56e53cb8SWarner Losh qx = (uint64_t)x * (uint64_t) y;
30ca987d46SWarner Losh
31*56e53cb8SWarner Losh q.hi = (uint32_t)( qx >> 32 );
32*56e53cb8SWarner Losh q.lo = (uint32_t)( qx & 0xFFFFFFFFL);
33ca987d46SWarner Losh
34ca987d46SWarner Losh return q;
35ca987d46SWarner Losh }
36ca987d46SWarner Losh
ficlLongDiv(DPUNS q,FICL_UNS y)37ca987d46SWarner Losh UNSQR ficlLongDiv(DPUNS q, FICL_UNS y)
38ca987d46SWarner Losh {
39ca987d46SWarner Losh UNSQR result;
40*56e53cb8SWarner Losh uint64_t qx, qh;
41ca987d46SWarner Losh
42ca987d46SWarner Losh qh = q.hi;
43ca987d46SWarner Losh qx = (qh << 32) | q.lo;
44ca987d46SWarner Losh
45ca987d46SWarner Losh result.quot = qx / y;
46ca987d46SWarner Losh result.rem = qx % y;
47ca987d46SWarner Losh
48ca987d46SWarner Losh return result;
49ca987d46SWarner Losh }
50ca987d46SWarner Losh #endif
51ca987d46SWarner Losh
ficlTextOut(FICL_VM * pVM,char * msg,int fNewline)52ca987d46SWarner Losh void ficlTextOut(FICL_VM *pVM, char *msg, int fNewline)
53ca987d46SWarner Losh {
54ca987d46SWarner Losh IGNORE(pVM);
55ca987d46SWarner Losh
56ca987d46SWarner Losh while(*msg != 0)
57ca987d46SWarner Losh putchar(*(msg++));
58ca987d46SWarner Losh if (fNewline)
59ca987d46SWarner Losh putchar('\n');
60ca987d46SWarner Losh
61ca987d46SWarner Losh return;
62ca987d46SWarner Losh }
63ca987d46SWarner Losh
ficlMalloc(size_t size)64ca987d46SWarner Losh void *ficlMalloc (size_t size)
65ca987d46SWarner Losh {
66ca987d46SWarner Losh return malloc(size);
67ca987d46SWarner Losh }
68ca987d46SWarner Losh
ficlRealloc(void * p,size_t size)69ca987d46SWarner Losh void *ficlRealloc (void *p, size_t size)
70ca987d46SWarner Losh {
71ca987d46SWarner Losh return realloc(p, size);
72ca987d46SWarner Losh }
73ca987d46SWarner Losh
ficlFree(void * p)74ca987d46SWarner Losh void ficlFree (void *p)
75ca987d46SWarner Losh {
76ca987d46SWarner Losh free(p);
77ca987d46SWarner Losh }
78ca987d46SWarner Losh
79ca987d46SWarner Losh
80ca987d46SWarner Losh /*
81ca987d46SWarner Losh ** Stub function for dictionary access control - does nothing
82ca987d46SWarner Losh ** by default, user can redefine to guarantee exclusive dict
83ca987d46SWarner Losh ** access to a single thread for updates. All dict update code
84ca987d46SWarner Losh ** is guaranteed to be bracketed as follows:
85ca987d46SWarner Losh ** ficlLockDictionary(TRUE);
86ca987d46SWarner Losh ** <code that updates dictionary>
87ca987d46SWarner Losh ** ficlLockDictionary(FALSE);
88ca987d46SWarner Losh **
89ca987d46SWarner Losh ** Returns zero if successful, nonzero if unable to acquire lock
90ca987d46SWarner Losh ** befor timeout (optional - could also block forever)
91ca987d46SWarner Losh */
92ca987d46SWarner Losh #if FICL_MULTITHREAD
ficlLockDictionary(short fLock)93ca987d46SWarner Losh int ficlLockDictionary(short fLock)
94ca987d46SWarner Losh {
95ca987d46SWarner Losh IGNORE(fLock);
96ca987d46SWarner Losh return 0;
97ca987d46SWarner Losh }
98ca987d46SWarner Losh #endif /* FICL_MULTITHREAD */
99