/**
* -- Words making sense in POSIX-like systems only.
*
* Copyright (C) Tektronix, Inc. 1998 - 2001. All rights reserved.
*
* @see GNU LGPL
* @author Tektronix CTE %derived_by: guidod %
* @version %version: bln_mpt1!5.22 %
* (%date_modified: Tue Nov 13 17:07:02 2001 %)
*
* @description
* This file exports a set of system words for
* a posixish OS environment. So should do
* any alternative wordset you might create for your OS.
*//*@{*/
/**
* CLOCKS_PER_SEC - usually one million ticks, but can be
* very different on a specific system. Exported
* as a constant. see CLOCK
*//*"CLK_TCK"*/
/**#!( "..." -- )
* ignores the rest of the line,
* defining `#!' is used to support forth scripts
* executed by the unix kernel
*/FCode (p4_ignore_line)
{
p4_refill ();
}
/**
* helper function - both arg pointers MUST be given
*/_export void
p4_gettimeofday (p4ucell* sec, p4ucell* usec)
{
# ifdef PFE_HAVE_VXWORKS_H# define PFE_HAVE_CLOCK_GETTIME# endif# if defined PFE_HAVE_CLOCK_GETTIME
struct timespec tv;
clock_gettime (CLOCK_REALTIME, &tv);
if (usec) *usec = tv.tv_nsec/1000;
*sec = tv.tv_sec;
# elif defined PFE_HAVE_WINBASE_H
SYSTEMTIME stime;
GetSystemTime (&stime);
if (usec) *usec = stime.wMilliseconds*1000;
*sec = time(0);
# elif defined PFE_HAVE_UNISTD_H || defined PFE_HAVE_GETTIMEOFDAY
struct timeval tv;
gettimeofday (&tv, 0);
if (usec) *usec = tv.tv_usec;
*sec = tv.tv_sec;
# else
if (usec) *usec = 0;
*sec = time(0);
# endif
};
/**GETTIMEOFDAY( -- double-time )
* returns SVR/BSD gettimeofday(2).
* Never defined on 16-bit systems, hence
* TIMEDATE is more portable.
*/static
FCode (gettimeofday)
{
FX_2ROOM;
p4_gettimeofday (&SP[0], &SP[1]);
}
/**ENVIRONMENT CLK_TCK( -- HZ )
* the system's scheduler heartbeat clock (a.k.a. jiffies a.k.a. HZ)
* for every function that expects time-values in ticks.
*/static FCode(p4__clk_tck)
{
# if defined CLOCKS_PER_SEC
FX_PUSH (CLOCKS_PER_SEC);
# elif defined CLK_TCK
FX_PUSH (CLK_TCK);
# else/* including HOST_OS_AIX1 */
FX_PUSH (1000000); /* just a guess :-) */# endif
}
#if 0#define PFE_NTOHS_DIRECT 1#endif
/**NTOHS( w -- w' )
* if current host-encoding is bigendian, this is a NOOP
* otherwise byteswap the lower 16-bit bits of the topofstack.
* see W@ and W!
* (on some platforms, the upper bits are erased, on others not)
*/FCode (p4_ntohs)
{
# ifdef PFE_NTOHS_DIRECT
*(unsigned short**)SP = ntohs (*(unsigned short**)SP);
# else
register p4ucell item = *SP;
*SP = ntohs (item);
# endif
}
/**NTOHL( l -- l' )
* if current host-encoding is bigendian, this is a NOOP
* otherwise byteswap the lower 32-bit bits of the topofstack.
* see L@ and L! (being usually just @ and ! )
* (on some platforms, the upper bits are erased, on others not)
*/FCode (p4_ntohl)
{
# ifdef PFE_NTOHS_DIRECT
*(unsigned long**)SP = ntohl (*(unsigned long**)SP);
# else
register p4ucell item = *SP;
*SP = ntohl (item);
# endif
}