feat: std.time — wall + monotonic clocks over clock_gettime (PLAN-HTTPZ S1)
now_secs (CLOCK_REALTIME, epoch seconds) and mono_ms (CLOCK_MONOTONIC, process-local milliseconds for deadlines). Clock ids are darwin's; the per-OS selection mechanism is PLAN-HTTPZ C3. No error channel: with module-constant clock ids and a stack timespec, clock_gettime is total. std.sx namespace tail carries the time alias; examples/1629 pins epoch plausibility, monotone advance, and the alias carry.
This commit is contained in:
35
examples/1629-std-time.sx
Normal file
35
examples/1629-std-time.sx
Normal file
@@ -0,0 +1,35 @@
|
||||
// std.time (PLAN-HTTPZ S1): the wall clock reads a plausible epoch and
|
||||
// the monotonic clock advances and never runs backwards. The `time`
|
||||
// alias rides the std.sx namespace tail like its siblings.
|
||||
#import "modules/std.sx";
|
||||
|
||||
main :: () -> i32 {
|
||||
now := time.now_secs();
|
||||
if now < 1767225600 { // before 2026-01-01: implausible
|
||||
print("wall clock implausibly old: {}\n", now);
|
||||
return 1;
|
||||
}
|
||||
if now > 4102444800 { // after 2100-01-01: implausible
|
||||
print("wall clock implausibly far: {}\n", now);
|
||||
return 1;
|
||||
}
|
||||
|
||||
a := time.mono_ms();
|
||||
b := a;
|
||||
spins := 0;
|
||||
while b == a and spins < 100000000 { // a real ms tick arrives long before the bound
|
||||
b = time.mono_ms();
|
||||
spins += 1;
|
||||
}
|
||||
if b < a {
|
||||
print("monotonic went backwards: {} -> {}\n", a, b);
|
||||
return 1;
|
||||
}
|
||||
if b == a {
|
||||
print("monotonic never advanced\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
print("std.time ok\n");
|
||||
return 0;
|
||||
}
|
||||
1
examples/expected/1629-std-time.exit
Normal file
1
examples/expected/1629-std-time.exit
Normal file
@@ -0,0 +1 @@
|
||||
0
|
||||
1
examples/expected/1629-std-time.stderr
Normal file
1
examples/expected/1629-std-time.stderr
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
1
examples/expected/1629-std-time.stdout
Normal file
1
examples/expected/1629-std-time.stdout
Normal file
@@ -0,0 +1 @@
|
||||
std.time ok
|
||||
Reference in New Issue
Block a user