mirror of
https://github.com/pocketpy/pocketpy
synced 2025-11-08 04:30:17 +00:00
Compare commits
No commits in common. "56996cc2e76372eab838ad6004c257ddf2337f1a" and "5652b9d98e7d8f95aaf2a3acba938e8d228f2d0e" have entirely different histories.
56996cc2e7
...
5652b9d98e
@ -24,6 +24,7 @@ Union = _PLACEHOLDER
|
|||||||
Optional = _PLACEHOLDER
|
Optional = _PLACEHOLDER
|
||||||
Callable = _PLACEHOLDER
|
Callable = _PLACEHOLDER
|
||||||
Type = _PLACEHOLDER
|
Type = _PLACEHOLDER
|
||||||
|
Protocol = _PLACEHOLDER
|
||||||
|
|
||||||
Literal = _PLACEHOLDER
|
Literal = _PLACEHOLDER
|
||||||
LiteralString = _PLACEHOLDER
|
LiteralString = _PLACEHOLDER
|
||||||
@ -36,8 +37,8 @@ Hashable = _PLACEHOLDER
|
|||||||
TypeVar = _PLACEHOLDER
|
TypeVar = _PLACEHOLDER
|
||||||
Self = _PLACEHOLDER
|
Self = _PLACEHOLDER
|
||||||
|
|
||||||
Protocol = object
|
class Generic:
|
||||||
Generic = object
|
pass
|
||||||
|
|
||||||
TYPE_CHECKING = False
|
TYPE_CHECKING = False
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -2,8 +2,6 @@
|
|||||||
#include "pocketpy/pocketpy.h"
|
#include "pocketpy/pocketpy.h"
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
int64_t time_ns(); // from random.c
|
|
||||||
|
|
||||||
/* https://github.com/clibs/mt19937ar
|
/* https://github.com/clibs/mt19937ar
|
||||||
|
|
||||||
Copyright (c) 2011 Mutsuo Saito, Makoto Matsumoto, Hiroshima
|
Copyright (c) 2011 Mutsuo Saito, Makoto Matsumoto, Hiroshima
|
||||||
@ -78,8 +76,7 @@ static uint32_t mt19937__next_uint32(mt19937* self) {
|
|||||||
int kk;
|
int kk;
|
||||||
|
|
||||||
if(self->mti == N + 1) { /* if init_genrand() has not been called, */
|
if(self->mti == N + 1) { /* if init_genrand() has not been called, */
|
||||||
int64_t seed = time_ns();
|
mt19937__seed(self, clock());
|
||||||
mt19937__seed(self, (uint32_t)seed);
|
|
||||||
// seed(5489UL); /* a default initial seed is used */
|
// seed(5489UL); /* a default initial seed is used */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#define NANOS_PER_SEC 1000000000
|
#define NANOS_PER_SEC 1000000000
|
||||||
|
|
||||||
int64_t time_ns() {
|
static bool get_ns(int64_t* out) {
|
||||||
struct timespec tms;
|
struct timespec tms;
|
||||||
#if defined( __ANDROID__) || defined(__MINGW32__) || defined(__MINGW64__)
|
#if defined( __ANDROID__) || defined(__MINGW32__) || defined(__MINGW64__)
|
||||||
clock_gettime(CLOCK_REALTIME, &tms);
|
clock_gettime(CLOCK_REALTIME, &tms);
|
||||||
@ -16,19 +16,22 @@ int64_t time_ns() {
|
|||||||
int64_t nanos = tms.tv_sec * NANOS_PER_SEC;
|
int64_t nanos = tms.tv_sec * NANOS_PER_SEC;
|
||||||
/* Add full nanoseconds */
|
/* Add full nanoseconds */
|
||||||
nanos += tms.tv_nsec;
|
nanos += tms.tv_nsec;
|
||||||
return nanos;
|
*out = nanos;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool time_time(int argc, py_Ref argv) {
|
static bool time_time(int argc, py_Ref argv) {
|
||||||
PY_CHECK_ARGC(0);
|
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);
|
py_newfloat(py_retval(), (double)nanos / NANOS_PER_SEC);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool time_time_ns(int argc, py_Ref argv) {
|
static bool time_time_ns(int argc, py_Ref argv) {
|
||||||
PY_CHECK_ARGC(0);
|
PY_CHECK_ARGC(0);
|
||||||
int64_t nanos = time_ns();
|
int64_t nanos;
|
||||||
|
if(!get_ns(&nanos)) return false;
|
||||||
py_newint(py_retval(), nanos);
|
py_newint(py_retval(), nanos);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -38,10 +41,12 @@ static bool time_sleep(int argc, py_Ref argv) {
|
|||||||
py_f64 secs;
|
py_f64 secs;
|
||||||
if(!py_castfloat(argv, &secs)) return false;
|
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;
|
const int64_t end = start + secs * 1000000000;
|
||||||
while(true) {
|
while(true) {
|
||||||
int64_t now = time_ns();
|
int64_t now;
|
||||||
|
if(!get_ns(&now)) return false;
|
||||||
if(now >= end) break;
|
if(now >= end) break;
|
||||||
}
|
}
|
||||||
py_newnone(py_retval());
|
py_newnone(py_retval());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user