From ba5ee94871e670fbe1ea091dd5731e593df0b29f Mon Sep 17 00:00:00 2001 From: Zuhaitz Méndez Fernández de Aránguiz Date: Sun, 11 Jan 2026 17:47:30 +0000 Subject: Some std for you --- std/time.zc | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 std/time.zc (limited to 'std/time.zc') 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 + #include + #include + + 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)); + } +} -- cgit v1.2.3