lib/time+test: add types, ops, now
Replaces the lib/time placeholder (a monotonic(*timespec) shim that
predated lib/os's syscall surface). Ships Hare's time module first
cut per ref/hare/time/{duration,instant,arithm,+linux/functions}.ha:
- duration (i64 ns); nanosecond / microsecond / millisecond / second
constants.
- instant (sec, nsec) — Hare's layout, NOT POSIX's nsec:u32. Matches
Linux struct timespec on 64-bit, so &instant lands directly in
clock_gettime.
- clock enum: realtime + monotonic only. The rest of Hare's set
(process_cpu / thread_cpu / boot / realtime_alarm / boot_alarm / tai)
graduates when a caller actually needs it (rule 9).
- now(c: clock) instant — aborts on EINVAL/EFAULT (mirrors Hare's
abort-on-impossible-errno). Deliberately NOT (instant | oserror) to
sidestep task #9's 1-word-payload tagged-return trap.
- add / diff / compare on instants per ref/hare/time/arithm.ha
verbatim.
Deferred to follow-up commits when a caller surfaces: sleep, format /
strftime, time.chrono / time.date calendar, timezone, time.error
sum-return shape, time.unix helpers, time.mult, conversion helpers.
Tests at lib/time/timetest.ww (15 rows, table-pattern, semantic per
Class B doctrine). Driver test/wcc/977_time_run.c slotted between
976_stat_run and 978_intdiv_signed in the 9xx _run band.
examples/cmatrix migrates to the new API in the same commit (sole
pre-existing caller — bisect-clean per rule 11).
Class B bug #16 (sign-extend before IDIVQ) was surfaced by the
negative-duration rows during this work; landed 63332fe..4fa4bcf
before this commit. Rows 8-9 (addneg_noborrow / addneg_borrow) are
the load-bearing Class B exercisers; would have stayed silently wrong
pre-#16.
lib/time's own .s output has a cstage/wwstage label-counter skew in
add (cstage emits add_ct_7/_ce_8/_end_6 vs wwstage _6/_7/_5). Filed
as task #15; non-bootstrap-blocking since lib/time is outside the
selfhost toolchain transitive chain.
This commit is contained in:
@@ -189,12 +189,9 @@ fn setup() (*void | initerr) = {
|
||||
|
||||
// ---- clock helper -----------------------------------------------------
|
||||
|
||||
fn now_ns() (u64 | initerr) = {
|
||||
let ts: time.timespec; // uninitialised — keep the type for the shape
|
||||
if (time.monotonic(&ts) != 0) {
|
||||
return "clock_gettime failed": initerr;
|
||||
};
|
||||
let v = ts.sec * 1000000000i64 + ts.nsec;
|
||||
fn now_ns() u64 = {
|
||||
let i = time.now(time.clock.monotonic);
|
||||
let v = i.sec * 1000000000i64 + i.nsec;
|
||||
return v: u64;
|
||||
};
|
||||
|
||||
@@ -468,9 +465,9 @@ fn run(seed: u64) (i32 | initerr) = {
|
||||
// ---- entry ------------------------------------------------------------
|
||||
|
||||
export fn main() i32 = {
|
||||
// `!` — unwrap the success variant or abort. The clock is a
|
||||
// pre-init dependency; if it fails there's nothing to tear down.
|
||||
let seed = now_ns()!;
|
||||
// Clock is a pre-init dependency; time.now aborts on
|
||||
// syscall failure (EINVAL / EFAULT are programmer errors).
|
||||
let seed = now_ns();
|
||||
|
||||
// match-as-expression: every arm `yield`s the exit code, and the
|
||||
// whole match resolves to a single i32. One return site for the
|
||||
|
||||
Reference in New Issue
Block a user