sysdep.c revision 40883
140843Smsmith/*******************************************************************
240843Smsmith** s y s d e p . c
340843Smsmith** Forth Inspired Command Language
440843Smsmith** Author: John Sadler (john_sadler@alum.mit.edu)
540843Smsmith** Created: 16 Oct 1997
640843Smsmith** Implementations of FICL external interface functions...
740843Smsmith**
840843Smsmith*******************************************************************/
940843Smsmith
1040883Smsmith#ifdef TESTMAIN
1140883Smsmith#include <stdio.h>
1240883Smsmith#include <stdlib.h>
1340883Smsmith#else
1440876Smsmith#include <stand.h>
1540883Smsmith#endif
1640876Smsmith#include "ficl.h"
1740843Smsmith
1840843Smsmith/*
1940843Smsmith*******************  FreeBSD  P O R T   B E G I N S   H E R E ******************** Michael Smith
2040843Smsmith*/
2140843Smsmith
2240843SmsmithUNS64 ficlLongMul(UNS32 x, UNS32 y)
2340843Smsmith{
2440843Smsmith    UNS64 q;
2540843Smsmith    u_int64_t qx;
2640843Smsmith
2740843Smsmith    qx = (u_int64_t)x * (u_int64_t) y;
2840843Smsmith
2940843Smsmith    q.hi = (u_int32_t)( qx >> 32 );
3040843Smsmith    q.lo = (u_int32_t)( qx & 0xFFFFFFFFL);
3140843Smsmith
3240843Smsmith    return q;
3340843Smsmith}
3440843Smsmith
3540843SmsmithUNSQR ficlLongDiv(UNS64 q, UNS32 y)
3640843Smsmith{
3740843Smsmith    UNSQR result;
3840843Smsmith    u_int64_t qx, qh;
3940843Smsmith
4040843Smsmith    qh = q.hi;
4140843Smsmith    qx = (qh << 32) | q.lo;
4240843Smsmith
4340843Smsmith    result.quot = qx / y;
4440843Smsmith    result.rem  = qx % y;
4540843Smsmith
4640843Smsmith    return result;
4740843Smsmith}
4840843Smsmith
4940843Smsmithvoid  ficlTextOut(FICL_VM *pVM, char *msg, int fNewline)
5040843Smsmith{
5140843Smsmith    IGNORE(pVM);
5240843Smsmith
5340843Smsmith    while(*msg != 0)
5440843Smsmith	putchar(*(msg++));
5540843Smsmith    if (fNewline)
5640843Smsmith	putchar('\n');
5740843Smsmith
5840843Smsmith   return;
5940843Smsmith}
6040843Smsmith
6140843Smsmithvoid *ficlMalloc (size_t size)
6240843Smsmith{
6340843Smsmith    return malloc(size);
6440843Smsmith}
6540843Smsmith
6640843Smsmithvoid  ficlFree   (void *p)
6740843Smsmith{
6840843Smsmith    free(p);
6940843Smsmith}
7040843Smsmith
7140843Smsmith/*
7240843Smsmith** Stub function for dictionary access control - does nothing
7340843Smsmith** by default, user can redefine to guarantee exclusive dict
7440843Smsmith** access to a single thread for updates. All dict update code
7540843Smsmith** is guaranteed to be bracketed as follows:
7640843Smsmith** ficlLockDictionary(TRUE);
7740843Smsmith** <code that updates dictionary>
7840843Smsmith** ficlLockDictionary(FALSE);
7940843Smsmith**
8040843Smsmith** Returns zero if successful, nonzero if unable to acquire lock
8140843Smsmith** befor timeout (optional - could also block forever)
8240843Smsmith*/
8340843Smsmith#if FICL_MULTITHREAD
8440843Smsmithint ficlLockDictionary(short fLock)
8540843Smsmith{
8640843Smsmith	IGNORE(fLock);
8740843Smsmith	return 0;
8840843Smsmith}
8940843Smsmith#endif /* FICL_MULTITHREAD */
9040843Smsmith
9140843Smsmith
92