Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions devel/210_12.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# [210_12] `(srfi srfi-19)`

## 任务相关的代码文件
- `src/goldfish.hpp`
- `tests/goldfish/liii/time-test.scm`
- `goldfish/scheme/time.scm`
- `goldfish/srfi/srfi-19.scm`

## 如何测试

```shell
# 可能需要清除缓存
# rm .xmake/ build/ -r
xmake f -vyD
xmake b goldfish
./bin/goldfish tests/goldfish/liii/time-test.scm
```

## 2026/1/30 初始化 time 和 date 结构

### What

1. 新增 glue:`g_get-time-of-day`, `g_monotonic-nanosecond`, `g_steady-clock-resolution`, `g_system-clock-resolution`
2. 实现 time 与 date 基本结构
3. 实现部分 SRFI-19 proc,包括 `current-time`, `date->string`

### Why

扩充时间与日期的支持。

### How

通过 C++17 的 chrono 绑定实现。
17 changes: 14 additions & 3 deletions goldfish/scheme/time.scm
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,26 @@
;

(define-library (scheme time)
(export current-second current-jiffy jiffies-per-second)
(import (only (scheme base) let-values s7-round))
(export current-second current-jiffy jiffies-per-second
get-time-of-day monotonic-nanosecond
system-clock-resolution steady-clock-resolution)
(begin

(define (jiffies-per-second) 1000000)

(define (current-second) (g_current-second))
(define get-time-of-day g_get-time-of-day)
(define monotonic-nanosecond g_monotonic-nanosecond)
(define system-clock-resolution g_system-clock-resolution)
(define steady-clock-resolution g_steady-clock-resolution)

(define (current-second)
(let-values (((sec usec) (get-time-of-day)))
(+ sec (exact->inexact (/ usec 1000000)))))

(define (current-jiffy)
(round (* (current-second) (jiffies-per-second))))
;; NOTE: use the s7-round to ensure that a natural number is returned.
(s7-round (* (current-second) (jiffies-per-second))))

) ; end of begin
) ; end of define-library
Loading