mirror of
https://github.com/ilyakooo0/Idris-dev.git
synced 2024-09-11 08:55:23 +03:00
Implement idris_clock on windows
This commit is contained in:
parent
5eebc7b046
commit
7626280473
@ -100,7 +100,6 @@ record Clock where
|
||||
nanoseconds : Integer
|
||||
|
||||
||| Get the system's wall clock time.
|
||||
||| At the moment, this returns 0 on Windows
|
||||
clockTime : IO Clock
|
||||
clockTime
|
||||
= do vm <- getMyVM
|
||||
|
@ -11,9 +11,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
int win_fpoll(void* h);
|
||||
FILE *win32_u8fopen(const char *path, const char *mode);
|
||||
FILE *win32_u8popen(const char *path, const char *mode);
|
||||
#include "windows/win_utils.h"
|
||||
#else
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
@ -209,9 +207,11 @@ VAL idris_time() {
|
||||
VAL idris_clock(VM* vm) {
|
||||
VAL result;
|
||||
#ifdef _WIN32
|
||||
int64_t sec, nsec;
|
||||
win32_gettime(&sec, &nsec);
|
||||
idris_constructor(result, vm, 0, 2, 0);
|
||||
idris_setConArg(result, 0, MKBIGI(0));
|
||||
idris_setConArg(result, 1, MKBIGI(0));
|
||||
idris_setConArg(result, 0, MKBIGI(sec));
|
||||
idris_setConArg(result, 1, MKBIGI(nsec));
|
||||
#else
|
||||
struct timespec ts;
|
||||
// We're not checking the result here, which is of course bad, but
|
||||
|
@ -1,7 +1,9 @@
|
||||
#include <io.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
// THis file exists to avoid clashes between windows.h and idris_rts.h
|
||||
//
|
||||
|
||||
@ -28,6 +30,7 @@ int widen_utf8(const char *filename_utf8, LPWSTR *filename_w)
|
||||
MultiByteToWideChar(CP_UTF8, 0, filename_utf8, -1, *filename_w, num_chars);
|
||||
return num_chars;
|
||||
}
|
||||
|
||||
FILE *win32_u8fopen(const char *path, const char *mode)
|
||||
{
|
||||
LPWSTR wpath, wmode;
|
||||
@ -49,3 +52,16 @@ FILE *win32_u8popen(const char *path, const char *mode)
|
||||
free(wmode);
|
||||
return f;
|
||||
}
|
||||
|
||||
void win32_gettime(int64_t* sec, int64_t* nsec)
|
||||
{
|
||||
FILETIME ft;
|
||||
GetSystemTimePreciseAsFileTime(&ft);
|
||||
ULARGE_INTEGER t;
|
||||
t.HighPart = ft.dwHighDateTime;
|
||||
t.LowPart = ft.dwLowDateTime;
|
||||
|
||||
*nsec = (t.QuadPart % 10000000)*100;
|
||||
*sec = t.QuadPart / 10000000;
|
||||
*sec -= 11644473600; // LDAP epoch to Unix epoch
|
||||
}
|
9
rts/windows/win_utils.h
Normal file
9
rts/windows/win_utils.h
Normal file
@ -0,0 +1,9 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
int win_fpoll(void *h);
|
||||
FILE *win32_u8fopen(const char *path, const char *mode);
|
||||
FILE *win32_u8popen(const char *path, const char *mode);
|
||||
void win32_gettime(int64_t* sec, int64_t* nsec);
|
Loading…
Reference in New Issue
Block a user