From 724cf31c7596e70caa4205433feb6117448b06ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B9=E7=85=9C?= Date: Wed, 17 Sep 2025 17:34:56 +0800 Subject: [PATCH 1/4] =?UTF-8?q?main/206=5F1.md:os=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E6=96=B0=E5=A2=9Esleep=E6=96=B9=E6=B3=95=EF=BC=8C=E5=8D=95?= =?UTF-8?q?=E4=BD=8D=E7=A7=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- goldfish/liii/os.scm | 5 +++++ src/goldfish.hpp | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/goldfish/liii/os.scm b/goldfish/liii/os.scm index 00810460..a063c93a 100644 --- a/goldfish/liii/os.scm +++ b/goldfish/liii/os.scm @@ -132,6 +132,11 @@ (define (getpid) (g_getpid)) + (define (sleep seconds) + (if (not (number? seconds)) ; 检查是否是数字,单位秒 + (error 'type-error "(sleep seconds): seconds must be a number") + (g_sleep seconds))) + ) ; end of begin ) ; end of define-library diff --git a/src/goldfish.hpp b/src/goldfish.hpp index ce6b926f..99d628e5 100644 --- a/src/goldfish.hpp +++ b/src/goldfish.hpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -522,6 +523,25 @@ glue_getpid (s7_scheme* sc) { glue_define (sc, name, desc, f_getpid, 0, 0); } +static s7_pointer +f_sleep(s7_scheme* sc, s7_pointer args) { + s7_double seconds = s7_real(s7_car(args)); + + // 使用 std::this_thread::sleep_for 实现跨平台睡眠 + std::this_thread::sleep_for(std::chrono::duration(seconds)); + + return s7_nil(sc); +} + +inline void +glue_sleep(s7_scheme* sc) { + const char* name = "g_sleep"; + const char* desc = "(g_sleep seconds) => nil, sleep for the specified number of seconds"; + glue_define(sc, name, desc, f_sleep, 1, 0); +} + + + inline void glue_liii_os (s7_scheme* sc) { glue_os_arch (sc); @@ -540,6 +560,7 @@ glue_liii_os (s7_scheme* sc) { glue_listdir (sc); glue_getlogin (sc); glue_getpid (sc); + glue_sleep(sc); } static s7_pointer -- Gitee From 17d1d6c8b60a38d3d3aeb5d3c6b821cd4f4ed641 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B9=E7=85=9C?= Date: Wed, 17 Sep 2025 17:47:40 +0800 Subject: [PATCH 2/4] =?UTF-8?q?main/206=5F1.md:os=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E6=96=B0=E5=A2=9Esleep=E6=96=B9=E6=B3=95=EF=BC=8C=E5=8D=95?= =?UTF-8?q?=E4=BD=8D=E7=A7=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- devel/206_1.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 devel/206_1.md diff --git a/devel/206_1.md b/devel/206_1.md new file mode 100644 index 00000000..a7a65a84 --- /dev/null +++ b/devel/206_1.md @@ -0,0 +1,34 @@ +# [206_5] os模块新增sleep方法,单位秒 + +## 任务相关的代码文件 +- goldfish/liii/os.scm +- src/goldfish.hpp + +## 如何测试 +```sh +./bin/goldfish -i +... +xmake config --yes +xmake b goldfish +gf> (import (liii os)) +$3 = (rootlet) +gf> (sleep 10) +$4 = () +gf> (sleep 5) +``` + +## PR提交规范 +1. 每次提PR前,先从main分支拉取最新代码:`git pull origin main` +2. 分支名必须采用`da/206_5/xxx`这种格式,其中da是`$USER`,xxx是功能名称 +3. 一个PR只包含一个功能 +4. **注意:不要在文档里面写示例代码** + +## 2025/09/17 + +### What + +os模块新增sleep方法,单位秒 + +### Why + +丰富os模块方法,实现等待操作 -- Gitee From 343dea69a5c52202cf67b554ff927991a75950af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B9=E7=85=9C?= Date: Wed, 17 Sep 2025 17:50:27 +0800 Subject: [PATCH 3/4] =?UTF-8?q?main/206=5F1.md:os=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E6=96=B0=E5=A2=9Esleep=E6=96=B9=E6=B3=95=EF=BC=8C=E5=8D=95?= =?UTF-8?q?=E4=BD=8D=E7=A7=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- devel/206_1.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/devel/206_1.md b/devel/206_1.md index a7a65a84..b5bfb23c 100644 --- a/devel/206_1.md +++ b/devel/206_1.md @@ -1,4 +1,4 @@ -# [206_5] os模块新增sleep方法,单位秒 +# [206_1] os模块新增sleep方法,单位秒 ## 任务相关的代码文件 - goldfish/liii/os.scm @@ -8,8 +8,6 @@ ```sh ./bin/goldfish -i ... -xmake config --yes -xmake b goldfish gf> (import (liii os)) $3 = (rootlet) gf> (sleep 10) -- Gitee From 144f43d02270c0b4507c58ded10f273bfc6a1790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B9=E7=85=9C?= Date: Wed, 17 Sep 2025 17:54:52 +0800 Subject: [PATCH 4/4] =?UTF-8?q?main/206=5F1.md:os=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E6=96=B0=E5=A2=9Esleep=E6=96=B9=E6=B3=95=EF=BC=8C=E5=8D=95?= =?UTF-8?q?=E4=BD=8D=E7=A7=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- goldfish/liii/os.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/goldfish/liii/os.scm b/goldfish/liii/os.scm index a063c93a..8ba7e334 100644 --- a/goldfish/liii/os.scm +++ b/goldfish/liii/os.scm @@ -19,7 +19,7 @@ os-arch os-type os-windows? os-linux? os-macos? os-temp-dir os-sep pathsep os-call ; system - mkdir chdir rmdir remove getenv putenv unsetenv getcwd listdir access getlogin getpid) + mkdir chdir rmdir remove getenv putenv unsetenv getcwd listdir access getlogin getpid sleep) (import (scheme process-context) (liii base) (liii error) -- Gitee