picrin/src/time.c

50 lines
795 B
C
Raw Normal View History

2014-01-17 06:58:31 -05:00
/**
* See Copyright Notice in picrin.h
*/
2013-10-19 23:04:15 -04:00
#include <time.h>
#include "picrin.h"
#define UTC_TAI_DIFF 35
static pic_value
pic_current_second(pic_state *pic)
{
time_t t;
pic_get_args(pic, "");
time(&t);
return pic_float_value((double)t + UTC_TAI_DIFF);
}
static pic_value
pic_current_jiffy(pic_state *pic)
{
clock_t c;
pic_get_args(pic, "");
c = clock();
2013-10-27 11:21:24 -04:00
return pic_int_value(c);
2013-10-19 23:04:15 -04:00
}
static pic_value
pic_jiffies_per_second(pic_state *pic)
{
pic_get_args(pic, "");
2013-10-27 11:21:24 -04:00
return pic_int_value(CLOCKS_PER_SEC);
2013-10-19 23:04:15 -04:00
}
void
pic_init_time(pic_state *pic)
{
2014-02-01 01:41:30 -05:00
pic_deflibrary ("(scheme time)") {
2013-12-08 02:17:28 -05:00
pic_defun(pic, "current-second", pic_current_second);
pic_defun(pic, "current-jiffy", pic_current_jiffy);
pic_defun(pic, "jiffies-per-second", pic_jiffies_per_second);
}
2013-10-19 23:04:15 -04:00
}