From e8d528ad93d29a9312d07358ccad3217c0a51cba Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 16 Jun 2010 23:39:16 -0500 Subject: [PATCH] Remove system_micros from vm, implement gmt hook on windows --- basis/calendar/calendar.factor | 6 ++---- basis/calendar/windows/windows.factor | 25 ++++++++++++++----------- core/bootstrap/primitives.factor | 1 - extra/time/windows/windows.factor | 3 --- vm/os-unix.cpp | 7 ------- vm/os-unix.hpp | 1 - vm/os-windows-ce.cpp | 10 ---------- vm/os-windows-ce.hpp | 1 - vm/os-windows-nt.cpp | 8 -------- vm/os-windows.hpp | 1 - vm/primitives.hpp | 1 - vm/run.cpp | 5 ----- vm/vm.hpp | 1 - 13 files changed, 16 insertions(+), 54 deletions(-) diff --git a/basis/calendar/calendar.factor b/basis/calendar/calendar.factor index 8758b8198b..d9a6dfb370 100644 --- a/basis/calendar/calendar.factor +++ b/basis/calendar/calendar.factor @@ -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- ; diff --git a/basis/calendar/windows/windows.factor b/basis/calendar/windows/windows.factor index abec2dcf9f..80253ea91b 100644 --- a/basis/calendar/windows/windows.factor +++ b/basis/calendar/windows/windows.factor @@ -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 - 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 ; + [ [ wSecond>> ] [ wMilliseconds>> 1000 / ] bi + ] + } cleave instant ; + +M: windows gmt-offset ( -- hours minutes seconds ) + TIME_ZONE_INFORMATION + 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 [ GetSystemTime ] keep SYSTEMTIME>timestamp ; diff --git a/core/bootstrap/primitives.factor b/core/bootstrap/primitives.factor index c00199e9b3..07f6e9ef9a 100644 --- a/core/bootstrap/primitives.factor +++ b/core/bootstrap/primitives.factor @@ -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 )) } diff --git a/extra/time/windows/windows.factor b/extra/time/windows/windows.factor index 1f2259d137..e5d7f918d9 100644 --- a/extra/time/windows/windows.factor +++ b/extra/time/windows/windows.factor @@ -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 [ GetSystemTime ] keep ; - M: windows set-time >gmt timestamp>SYSTEMTIME SetSystemTime win32-error=0/f ; diff --git a/vm/os-unix.cpp b/vm/os-unix.cpp index 034dfcbf5f..e95b84f51a 100644 --- a/vm/os-unix.cpp +++ b/vm/os-unix.cpp @@ -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; diff --git a/vm/os-unix.hpp b/vm/os-unix.hpp index 3673c4e121..54e9d068ef 100644 --- a/vm/os-unix.hpp +++ b/vm/os-unix.hpp @@ -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(); diff --git a/vm/os-windows-ce.cpp b/vm/os-windows-ce.cpp index a57db667c4..65e8ef5b09 100644 --- a/vm/os-windows-ce.cpp +++ b/vm/os-windows-ce.cpp @@ -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 */ diff --git a/vm/os-windows-ce.hpp b/vm/os-windows-ce.hpp index 02de1cd4a8..892fc88be9 100755 --- a/vm/os-windows-ce.hpp +++ b/vm/os-windows-ce.hpp @@ -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(); diff --git a/vm/os-windows-nt.cpp b/vm/os-windows-nt.cpp index 97cd2146af..7fdb882122 100755 --- a/vm/os-windows-nt.cpp +++ b/vm/os-windows-nt.cpp @@ -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; diff --git a/vm/os-windows.hpp b/vm/os-windows.hpp index 020a506038..ad8a9907a7 100755 --- a/vm/os-windows.hpp +++ b/vm/os-windows.hpp @@ -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(); diff --git a/vm/primitives.hpp b/vm/primitives.hpp index 9cda1db9a8..5df73f5fac 100644 --- a/vm/primitives.hpp +++ b/vm/primitives.hpp @@ -125,7 +125,6 @@ namespace factor _(special_object) \ _(string) \ _(strip_stack_traces) \ - _(system_micros) \ _(tuple) \ _(tuple_boa) \ _(unimplemented) \ diff --git a/vm/run.cpp b/vm/run.cpp index 6c8a8452e7..605fd9b725 100755 --- a/vm/run.cpp +++ b/vm/run.cpp @@ -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(); diff --git a/vm/vm.hpp b/vm/vm.hpp index 147647b528..40b3df5ecf 100755 --- a/vm/vm.hpp +++ b/vm/vm.hpp @@ -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();