Compare commits

..

No commits in common. "56996cc2e76372eab838ad6004c257ddf2337f1a" and "5652b9d98e7d8f95aaf2a3acba938e8d228f2d0e" have entirely different histories.

4 changed files with 16 additions and 13 deletions

View File

@ -24,6 +24,7 @@ Union = _PLACEHOLDER
Optional = _PLACEHOLDER
Callable = _PLACEHOLDER
Type = _PLACEHOLDER
Protocol = _PLACEHOLDER
Literal = _PLACEHOLDER
LiteralString = _PLACEHOLDER
@ -36,8 +37,8 @@ Hashable = _PLACEHOLDER
TypeVar = _PLACEHOLDER
Self = _PLACEHOLDER
Protocol = object
Generic = object
class Generic:
pass
TYPE_CHECKING = False

File diff suppressed because one or more lines are too long

View File

@ -2,8 +2,6 @@
#include "pocketpy/pocketpy.h"
#include <time.h>
int64_t time_ns(); // from random.c
/* https://github.com/clibs/mt19937ar
Copyright (c) 2011 Mutsuo Saito, Makoto Matsumoto, Hiroshima
@ -78,8 +76,7 @@ static uint32_t mt19937__next_uint32(mt19937* self) {
int kk;
if(self->mti == N + 1) { /* if init_genrand() has not been called, */
int64_t seed = time_ns();
mt19937__seed(self, (uint32_t)seed);
mt19937__seed(self, clock());
// seed(5489UL); /* a default initial seed is used */
}

View File

@ -4,7 +4,7 @@
#define NANOS_PER_SEC 1000000000
int64_t time_ns() {
static bool get_ns(int64_t* out) {
struct timespec tms;
#if defined( __ANDROID__) || defined(__MINGW32__) || defined(__MINGW64__)
clock_gettime(CLOCK_REALTIME, &tms);
@ -16,19 +16,22 @@ int64_t time_ns() {
int64_t nanos = tms.tv_sec * NANOS_PER_SEC;
/* Add full nanoseconds */
nanos += tms.tv_nsec;
return nanos;
*out = nanos;
return true;
}
static bool time_time(int argc, py_Ref argv) {
PY_CHECK_ARGC(0);
int64_t nanos = time_ns();
int64_t nanos;
if(!get_ns(&nanos)) return false;
py_newfloat(py_retval(), (double)nanos / NANOS_PER_SEC);
return true;
}
static bool time_time_ns(int argc, py_Ref argv) {
PY_CHECK_ARGC(0);
int64_t nanos = time_ns();
int64_t nanos;
if(!get_ns(&nanos)) return false;
py_newint(py_retval(), nanos);
return true;
}
@ -38,10 +41,12 @@ static bool time_sleep(int argc, py_Ref argv) {
py_f64 secs;
if(!py_castfloat(argv, &secs)) return false;
int64_t start = time_ns();
int64_t start;
if(!get_ns(&start)) return false;
const int64_t end = start + secs * 1000000000;
while(true) {
int64_t now = time_ns();
int64_t now;
if(!get_ns(&now)) return false;
if(now >= end) break;
}
py_newnone(py_retval());