forth/test/sysinfo.fth · 2005 字节 · 下载原文
\ sysinfo.fth —— 全能接口 CALLJSON(#573) 自检:调用 sysinfo 并把返回的 JSON 整份打出来。
\ sysinfo.fth —— self-check of the all-purpose interface CALLJSON(#573): call sysinfo and print the whole returned JSON.
\ ⚠ 两条 Forth 特有的规矩,写错了都**不报错、只是输出不对**:
\ ⚠ Two Forth-specific rules; getting either wrong **raises no error, it just produces wrong output**:
\ ① `S" ..."` 压的是 (地址, 长度) **两个单元**(标准 Forth 如此),而
\ ① `S" ..."` pushes **two cells** (address, length) (standard Forth behavior), while
\ `ui_call_json_s(char* fn, char* args)` 只要一个指针 ⇒ 长度必须 `DROP` 掉。
\ `ui_call_json_s(char* fn, char* args)` wants only one pointer ⇒ the length must be `DROP`ped.
\ 不 DROP 的话栈顶那个"长度"会顶到 fn 的位置上 —— 实测宿主收到的是空串,
\ Without the DROP, that "length" at the top of the stack lands in fn's position —— measured: the host receives an empty string,
\ 报「函数名为空」(`{"ok":false,"error":"函数名为空"}`)。2026-10-04 复验:文案与旧记的不同,但**结论不变** —— 少一个 DROP 传进去的就是个空名。
\ and reports a "function name is empty" error from the host. Re-verified 2026-10-04: the wording differs from the old note's "function not implemented:", but the **conclusion is unchanged** -- without the DROP an empty name is passed in.
\ ② 实参顺序:**最后压的 = C 的第 1 个实参** ⇒ args 先压、fn 后压。
\ ② Argument order: **the last one pushed = C's first argument** ⇒ push args first, fn last.
\ (所以 C 里写 `ui_call_json_s("sysinfo","")`,这里写成 `S" " … S" sysinfo" …`)
\ (so where C writes `ui_call_json_s("sysinfo","")`, here it is `S" " … S" sysinfo" …`)
S" " DROP S" sysinfo" DROP ui_call_json_s DROP
ui_call_json_print