Fun 0.41.5
The programming language that makes you have fun!
Loading...
Searching...
No Matches
clock_mono_ms.c
Go to the documentation of this file.
1/*
2 * This file is part of the Fun programming language.
3 * https://fun-lang.xyz/
4 *
5 * Copyright 2025 Johannes Findeisen <you@hanez.org>
6 * Licensed under the terms of the Apache-2.0 license.
7 * https://opensource.org/license/apache-2-0
8 */
9
10/**
11 * @file clock_mono_ms.c
12 * @brief Implements OP_CLOCK_MONO_MS to push monotonic clock in ms.
13 *
14 * Example:
15 * - OP_CLOCK_MONO_MS
16 * - Stack before: []
17 * - Stack after: [int ms]
18 */
19
20#include <stdint.h>
21#include <time.h>
22
24 int64_t ms;
25#if defined(CLOCK_MONOTONIC) && !defined(_WIN32)
26 struct timespec ts;
27 if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) {
28 ms = (int64_t)ts.tv_sec * 1000 + (int64_t)(ts.tv_nsec / 1000000);
29 } else {
30 time_t s = time(NULL);
31 ms = (int64_t)s * 1000;
32 }
33#else
34 time_t s = time(NULL);
35 ms = (int64_t)s * 1000;
36#endif
38 break;
39}
@ OP_CLOCK_MONO_MS
Definition bytecode.h:145
push_value(vm, make_int(ms))
uint32_t s
Definition rol.c:31
Value make_int(int64_t v)
Construct a Value representing a 64-bit integer.
Definition value.c:51