1188824Simp/*******************************************************************
2188824Simp** s y s d e p . c
3188824Simp** Forth Inspired Command Language
4188824Simp** Author: John Sadler (john_sadler@alum.mit.edu)
5188824Simp** Created: 16 Oct 1997
6188824Simp** Implementations of FICL external interface functions...
7188824Simp**
8188824Simp*******************************************************************/
9188824Simp
10188824Simp/* $FreeBSD$ */
11188824Simp
12188824Simp#ifdef TESTMAIN
13188824Simp#include <stdio.h>
14188824Simp#include <stdlib.h>
15188824Simp#else
16188824Simp#include <stand.h>
17188824Simp#endif
18188824Simp#include "ficl.h"
19188824Simp
20188824Simp/*
21188824Simp*******************  FreeBSD  P O R T   B E G I N S   H E R E ******************** Michael Smith
22188824Simp*/
23188824Simp
24188824Simp#if PORTABLE_LONGMULDIV == 0
25188824SimpDPUNS ficlLongMul(FICL_UNS x, FICL_UNS y)
26188824Simp{
27188824Simp    DPUNS q;
28188824Simp    u_int64_t qx;
29188824Simp
30188824Simp    qx = (u_int64_t)x * (u_int64_t) y;
31188824Simp
32188824Simp    q.hi = (u_int32_t)( qx >> 32 );
33188824Simp    q.lo = (u_int32_t)( qx & 0xFFFFFFFFL);
34188824Simp
35188824Simp    return q;
36188824Simp}
37188824Simp
38188824SimpUNSQR ficlLongDiv(DPUNS q, FICL_UNS y)
39188824Simp{
40188824Simp    UNSQR result;
41188824Simp    u_int64_t qx, qh;
42188824Simp
43188824Simp    qh = q.hi;
44188824Simp    qx = (qh << 32) | q.lo;
45188824Simp
46188824Simp    result.quot = qx / y;
47188824Simp    result.rem  = qx % y;
48188824Simp
49188824Simp    return result;
50188824Simp}
51188824Simp#endif
52188824Simp
53188824Simpvoid  ficlTextOut(FICL_VM *pVM, char *msg, int fNewline)
54188824Simp{
55188824Simp    IGNORE(pVM);
56188824Simp
57188824Simp    while(*msg != 0)
58188824Simp	putchar(*(msg++));
59188824Simp    if (fNewline)
60188824Simp	putchar('\n');
61188824Simp
62188824Simp   return;
63188824Simp}
64188824Simp
65188824Simpvoid *ficlMalloc (size_t size)
66188824Simp{
67188824Simp    return malloc(size);
68188824Simp}
69188824Simp
70188824Simpvoid *ficlRealloc (void *p, size_t size)
71188824Simp{
72188824Simp    return realloc(p, size);
73188824Simp}
74188824Simp
75188824Simpvoid  ficlFree   (void *p)
76188824Simp{
77188824Simp    free(p);
78188824Simp}
79188824Simp
80188824Simp
81188824Simp/*
82188824Simp** Stub function for dictionary access control - does nothing
83188824Simp** by default, user can redefine to guarantee exclusive dict
84188824Simp** access to a single thread for updates. All dict update code
85188824Simp** is guaranteed to be bracketed as follows:
86188824Simp** ficlLockDictionary(TRUE);
87188824Simp** <code that updates dictionary>
88188824Simp** ficlLockDictionary(FALSE);
89188824Simp**
90188824Simp** Returns zero if successful, nonzero if unable to acquire lock
91188824Simp** befor timeout (optional - could also block forever)
92188824Simp*/
93188824Simp#if FICL_MULTITHREAD
94188824Simpint ficlLockDictionary(short fLock)
95188824Simp{
96188824Simp	IGNORE(fLock);
97188824Simp	return 0;
98188824Simp}
99188824Simp#endif /* FICL_MULTITHREAD */
100188824Simp
101188824Simp
102