Remove system_micros from vm, implement gmt hook on windows

db4
Doug Coleman 2010-06-16 23:39:16 -05:00
parent 570801ff3d
commit e8d528ad93
13 changed files with 16 additions and 54 deletions

View File

@ -7,6 +7,8 @@ IN: calendar
HOOK: gmt-offset os ( -- hours minutes seconds )
HOOK: gmt os ( -- timestamp )
TUPLE: duration
{ year real }
{ month real }
@ -371,10 +373,6 @@ M: duration time-
: timestamp>micros ( timestamp -- n )
unix-1970 (time-) 1000000 * >integer ;
: gmt ( -- timestamp )
#! GMT time, right now
unix-1970 system-micros microseconds time+ ;
: now ( -- timestamp ) gmt >local-time ;
: hence ( duration -- timestamp ) now swap time+ ;
: ago ( duration -- timestamp ) now swap time- ;

View File

@ -3,15 +3,6 @@ windows.kernel32 kernel math combinators windows.errors
accessors classes.struct calendar.format math.functions ;
IN: calendar.windows
M: windows gmt-offset ( -- hours minutes seconds )
TIME_ZONE_INFORMATION <struct>
dup GetTimeZoneInformation {
{ TIME_ZONE_ID_INVALID [ win32-error-string throw ] }
{ TIME_ZONE_ID_UNKNOWN [ Bias>> ] }
{ TIME_ZONE_ID_STANDARD [ Bias>> ] }
{ TIME_ZONE_ID_DAYLIGHT [ [ Bias>> ] [ DaylightBias>> ] bi + ] }
} case neg 60 /mod 0 ;
: timestamp>SYSTEMTIME ( timestamp -- SYSTEMTIME )
{
[ year>> ]
@ -34,5 +25,17 @@ M: windows gmt-offset ( -- hours minutes seconds )
[ wDay>> ]
[ wHour>> ]
[ wMinute>> ]
[ [ wSecond>> ] [ wMilliseconds>> 1000 /f ] bi + ]
} cleave gmt-offset-duration <timestamp> ;
[ [ wSecond>> ] [ wMilliseconds>> 1000 / ] bi + ]
} cleave instant <timestamp> ;
M: windows gmt-offset ( -- hours minutes seconds )
TIME_ZONE_INFORMATION <struct>
dup GetTimeZoneInformation {
{ TIME_ZONE_ID_INVALID [ win32-error-string throw ] }
{ TIME_ZONE_ID_UNKNOWN [ Bias>> ] }
{ TIME_ZONE_ID_STANDARD [ Bias>> ] }
{ TIME_ZONE_ID_DAYLIGHT [ [ Bias>> ] [ DaylightBias>> ] bi + ] }
} case neg 60 /mod 0 ;
M: windows gmt
SYSTEMTIME <struct> [ GetSystemTime ] keep SYSTEMTIME>timestamp ;

View File

@ -536,7 +536,6 @@ tuple
{ "set-string-nth-fast" "strings.private" "primitive_set_string_nth_fast" (( ch n string -- )) }
{ "(exit)" "system" "primitive_exit" (( n -- * )) }
{ "nano-count" "system" "primitive_nano_count" (( -- ns )) }
{ "system-micros" "system" "primitive_system_micros" (( -- us )) }
{ "(sleep)" "threads.private" "primitive_sleep" (( nanos -- )) }
{ "callstack-for" "threads.private" "primitive_callstack_for" (( context -- array )) }
{ "context-object-for" "threads.private" "primitive_context_object_for" (( n context -- obj )) }

View File

@ -4,9 +4,6 @@ USING: calendar.windows system time windows.errors
windows.kernel32 kernel classes.struct calendar ;
IN: time.windows
: windows-system-time ( -- SYSTEMTIME )
SYSTEMTIME <struct> [ GetSystemTime ] keep ;
M: windows set-time
>gmt
timestamp>SYSTEMTIME SetSystemTime win32-error=0/f ;

View File

@ -19,13 +19,6 @@ THREADHANDLE start_thread(void *(*start_routine)(void *),void *args)
static void *null_dll;
u64 system_micros()
{
struct timeval t;
gettimeofday(&t,NULL);
return (u64)t.tv_sec * 1000000 + t.tv_usec;
}
void sleep_nanos(u64 nsec)
{
timespec ts;

View File

@ -42,7 +42,6 @@ inline static THREADHANDLE thread_id() { return pthread_self(); }
void signal_handler(int signal, siginfo_t* siginfo, void* uap);
void dump_stack_signal(int signal, siginfo_t* siginfo, void* uap);
u64 system_micros();
u64 nano_count();
void sleep_nanos(u64 nsec);
void open_console();

View File

@ -3,16 +3,6 @@
namespace factor
{
u64 system_micros()
{
SYSTEMTIME st;
FILETIME ft;
GetSystemTime(&st);
SystemTimeToFileTime(&st, &ft);
return (((s64)ft.dwLowDateTime
| (s64)ft.dwHighDateTime<<32) - EPOCH_OFFSET) / 10;
}
char *strerror(int err)
{
/* strerror() is not defined on WinCE */

View File

@ -21,7 +21,6 @@ char *getenv(char *name);
#define snprintf _snprintf
#define snwprintf _snwprintf
u64 system_micros();
void c_to_factor_toplevel(cell quot);
void open_console();

View File

@ -8,14 +8,6 @@ THREADHANDLE start_thread(void *(*start_routine)(void *), void *args)
return (void *)CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)start_routine, args, 0, 0);
}
u64 system_micros()
{
FILETIME t;
GetSystemTimeAsFileTime(&t);
return (((u64)t.dwLowDateTime | (u64)t.dwHighDateTime<<32)
- EPOCH_OFFSET) / 10;
}
u64 nano_count()
{
static double scale_factor;

View File

@ -45,7 +45,6 @@ typedef wchar_t vm_char;
inline static void early_init() {}
u64 system_micros();
u64 nano_count();
void sleep_nanos(u64 nsec);
long getpagesize();

View File

@ -125,7 +125,6 @@ namespace factor
_(special_object) \
_(string) \
_(strip_stack_traces) \
_(system_micros) \
_(tuple) \
_(tuple_boa) \
_(unimplemented) \

View File

@ -8,11 +8,6 @@ void factor_vm::primitive_exit()
exit((int)to_fixnum(ctx->pop()));
}
void factor_vm::primitive_system_micros()
{
ctx->push(from_unsigned_8(system_micros()));
}
void factor_vm::primitive_nano_count()
{
u64 nanos = nano_count();

View File

@ -146,7 +146,6 @@ struct factor_vm
// run
void primitive_exit();
void primitive_system_micros();
void primitive_nano_count();
void primitive_sleep();
void primitive_set_slot();