diff options
| author | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-11 17:47:30 +0000 |
|---|---|---|
| committer | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-11 17:47:30 +0000 |
| commit | ba5ee94871e670fbe1ea091dd5731e593df0b29f (patch) | |
| tree | 3b706a9ab11effa4acb094482f3d657c986ef501 /std/time.zc | |
| parent | aba9191ab3ef0699b0f9507ee3d03161f9ee7771 (diff) | |
Some std for you
Diffstat (limited to 'std/time.zc')
| -rw-r--r-- | std/time.zc | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/std/time.zc b/std/time.zc new file mode 100644 index 0000000..72e611a --- /dev/null +++ b/std/time.zc @@ -0,0 +1,44 @@ + +import "./core.zc" + +raw { + #include <time.h> + #include <unistd.h> + #include <sys/time.h> + + static uint64_t _time_now_impl(void) { + struct timeval tv; + gettimeofday(&tv, NULL); + return (uint64_t)(tv.tv_sec) * 1000 + (uint64_t)(tv.tv_usec) / 1000; + } +} + +struct Duration { + millis: U64; +} + +impl Duration { + fn from_ms(ms: U64) -> Duration { + return Duration { millis: ms }; + } + + fn from_secs(s: U64) -> Duration { + return Duration { millis: s * (U64)1000 }; + } +} + +struct Time {} + +impl Time { + fn now() -> U64 { + return _time_now_impl(); + } + + fn sleep(d: Duration) { + usleep((U32)(d.millis * (U64)1000)); + } + + fn sleep_ms(ms: U64) { + usleep((U32)(ms * (U64)1000)); + } +} |
