factor/native/misc.c

60 lines
970 B
C
Raw Normal View History

2004-08-04 03:12:55 -04:00
#include "factor.h"
void primitive_exit(void)
{
exit(to_fixnum(dpop()));
2004-08-04 03:12:55 -04:00
}
void primitive_os_env(void)
{
char *name, *value;
maybe_garbage_collection();
name = unbox_c_string();
value = getenv(name);
2004-08-04 03:12:55 -04:00
if(value == NULL)
2004-09-19 17:39:28 -04:00
dpush(F);
2004-08-04 03:12:55 -04:00
else
2004-09-19 17:39:28 -04:00
box_c_string(getenv(name));
2004-08-04 03:12:55 -04:00
}
void primitive_eq(void)
{
2004-11-08 22:36:51 -05:00
box_boolean(dpop() == dpop());
2004-08-04 03:12:55 -04:00
}
2004-12-10 21:39:45 -05:00
#ifdef WIN32
int64_t current_millis(void)
{
FILETIME t;
GetSystemTimeAsFileTime(&t);
return ((int64_t)t.dwLowDateTime | (int64_t)t.dwHighDateTime<<32) / 100000
- 172456224000;
}
#else
int64_t current_millis(void)
2004-08-04 03:12:55 -04:00
{
struct timeval t;
gettimeofday(&t,NULL);
2004-12-10 21:39:45 -05:00
return (int64_t)t.tv_sec * 1000 + t.tv_usec/1000;
2004-11-22 19:15:14 -05:00
}
2004-12-10 21:39:45 -05:00
#endif
2004-11-22 19:15:14 -05:00
void primitive_millis(void)
{
maybe_garbage_collection();
2004-11-22 19:15:14 -05:00
dpush(tag_object(s48_long_long_to_bignum(current_millis())));
2004-08-04 03:12:55 -04:00
}
void primitive_init_random(void)
{
2004-12-10 21:39:45 -05:00
srand((unsigned)time(NULL));
}
void primitive_random_int(void)
{
maybe_garbage_collection();
2004-12-10 21:39:45 -05:00
dpush(tag_object(s48_long_to_bignum(rand())));
}