@cella-lang/cfamily 0.1.202611041233 → 0.1.202611042110

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGES.md CHANGED
@@ -2,6 +2,36 @@
2
2
 
3
3
  ## 未發佈
4
4
 
5
+ - printf、scanf 可以當運算式用(C11 7.21.6.3p3、7.21.6.4p3):`while (scanf("%d", &x) == 1)`、`n = printf(...)`。scanf 的值是指定的個數,
6
+ 第一個轉換之前就遇到輸入結束是 EOF(-1);printf 的值是寫出的位元組數(中文一個字三個位元組)。兩者進了 C 函式庫的表
7
+ (`LibraryFunction.input`),呼叫是 `libraryCall`,格式從記憶體裡的字面量讀(UTF-8 的位元組,與敘述形態一致);效果是讀寫主控台,
8
+ 所以 `scanf(...) + scanf(...)` 兩種順序都跑一次比(讀到的值對調時是 `ubOrder`)。敘述形態(`sScanf`/`sPrintf`)照舊。
9
+ 除錯工作階段在會讀到輸入結尾的 scanf 呼叫停下等輸入(同敘述形態)。
10
+ - scanf 的 `%c` 不再在讀到的字元後面多寫一個 null(7.21.6.2p12):之前 `char c; scanf(" %c", &c);` 讀 " z" 得到 `'\0'`
11
+ (null 寫在同一個 char 上,蓋掉 z),`char w[3]` 的 `%2c` 多寫了 `w[2]`。格式裡的空白、一般字元的比對本來就對,新增的測試鎖住。
12
+ - scanf 支援 `%n`(寫到目前讀了幾個字元,不算進指定的個數;`%*n` 與帶欄寬的是未定義行為):之前 `%n` 被當成不合法的格式判 reject。
13
+ - 型別查詢:`p->f` 的節點是成員的型別(之前是 `*p` 的 struct:`->` 的間接與成員同一個節點,查詢取了先出現的那一個)。
14
+
15
+ ### ⚠️ 不相容
16
+
17
+ - `Scanned` 的 `bytesScanned` 多一欄 `terminated`(%s、%[ 是 true,%c 是 false);`ScanState` 多一欄 `start`;`ScanKind` 多 `charactersRead`。
18
+ - C 函式庫的表多了 `printf`、`scanf`。
19
+
20
+ - 兩個呼叫的效果可能衝突時(C11 6.5.2.2p10、C++17 [intro.execution]p11:彼此不定序,不是未定義行為),執行時兩種順序都跑一次、
21
+ 比兩邊留下的狀態(變數與記憶體,新建的區塊編號可以不同;輸出、輸入、檔案、串流與方言的部分),相同就照常,不同才是 `ubOrder`。
22
+ 之前只要兩邊「可能寫到」同一處就判 unknown:`s.substr(1) + s.substr(0, 1)`、計數加 memo 的 `fib(n - 1) + fib(n - 2)` 都誤判。
23
+ 兩種順序的暫存物件以不同順序解構時,解構也各跑一次再比。判決的量詞照實:「這組輸入上,每個分歧點的兩種順序(其餘照由左到右)」;
24
+ 遞迴在自己的比較裡再遇到同一點時不再比(只比最外層)。比較的預算是燃料的一半(試跑的步數與比過的區塊、物件各算一步)。
25
+
26
+ ### ⚠️ 不相容
27
+
28
+ - `ubOrder` 改成結構化的問題:params 是 `difference`(`output`:兩種順序寫的不同;`state`:輸出相同、留下的值不同;`end`:其中一種沒有
29
+ 正常走完那段呼叫,例外、exit 或停下),`output` 是時是由左到右那一種在比較點上寫的、`otherOutput` 是另一種的。
30
+ - 新的 kind `orderUncompared`(結構化,`category` 是 `indeterminate`,判決 unknown):可能依順序而變、但沒有比。`why` 是 `budget`
31
+ (比較超過預算;之後的分歧點都不再比)或 `access`(呼叫的效果和呼叫之外的存取衝突,例如 `x + f()` 而 f 寫 x:模型在兩邊的呼叫
32
+ 之後才讀 x,不是兩種順序之一,clang 是先讀)。之前這兩種都是 `ubOrder`。
33
+ - `ubOrder` 在 C 程式的條文改成 C11 6.5.2.2p10(之前一律寫 C++17 的)。
34
+
5
35
  - printf、scanf 的格式字串照 UTF-8:格式裡直接寫的非 ASCII 字元(例如中文提示字)原樣寫出、拿來對輸入的位元組;之前每個字被當成一個位元組,
6
36
  輸出變成 U+FFFD(`printf("我是\n")` 印出 `"��\n"`),`%s` 帶進去的則一直是對的。
7
37
  - 除錯工作階段變快:每一步問「這個節點能不能停」原本逐一比對程式寫的所有節點(一步的成本和程式長度成正比),改成平衡樹的查找。
package/README.md CHANGED
@@ -53,6 +53,14 @@ A branch's `verdict src input fuel` returns:
53
53
  of the structured ones are listed in `verdict-kinds.json` (shipped with this package; the C, C++ and Arduino
54
54
  branches share it). An undeclared name is `undeclared` with `name`, `what` (`variable`, `function` or `name`) and,
55
55
  when a standard header declares it, `header`.
56
+ Two calls in an unspecified order (C11 6.5.2.2p10, C++17 [intro.execution]p11) whose effects could conflict are run in
57
+ both orders and the states compared: a difference is `ubOrder` with `difference` (`output`: what the two orders
58
+ wrote differs, `output` being what the order run, left to right as clang, wrote at that point and `otherOutput` the
59
+ other's; `state`: the same output, other values left; `end`: one of them did not end normally). `orderUncompared` is
60
+ an order that may matter but was not compared: `why` is `budget` (comparing ran past its budget, half the fuel) or
61
+ `access` (a call's effect could change an access outside the calls, as `x + f()` with f writing x). The verdict's
62
+ quantifier is this input: each point where the order matters, its two orders with the others left to right (a
63
+ recursive call meeting the point again inside its own comparison is not compared again).
56
64
  - `assumes` (always there, empty when nothing is assumed): the implementation's choices the result depends on,
57
65
  `[{implementation, choice}]`.
58
66
  The library makes them as libc++ does (`vector.growth`: capacity and when `push_back` reallocates; `library.what`:
@@ -89,7 +97,7 @@ verdict `unknown` with a `hole` problem. `candidates` is a JSON array of types w
89
97
  | Syntax | `cfamily.syntax` (the surface syntax), `syntaxtypes`, `syntaxnodes`, `syntaxwalk`, `syntaxcollect` |
90
98
  | Types | `integer` (the integer types), `representation`, `resolution` (written types to resolved ones), `layout`, `literals`, `rules` (where the dialects differ on the same construct), `typetext` (types written as C) |
91
99
  | Checking | `typed` (the typed core syntax), `conversion`, `expressions`, `statements`, `lifting`, `statics`, `tables`, `program` |
92
- | Running | `memory` (objects, pointers as paths, bytes as the target represents them), `arithmetic`, `behavior` (what the standard leaves open), `state`, `evaluation`, `execution`, `sequencing` (unsequenced accesses), `summaries` (what a function may read and write), `running` (a program to its verdict), `encoding` (text at the boundary) |
100
+ | Running | `memory` (objects, pointers as paths, bytes as the target represents them), `arithmetic`, `behavior` (what the standard leaves open), `state`, `evaluation`, `execution`, `sequencing` (unsequenced accesses), `orders` (the two orders of calls compared), `summaries` (what a function may read and write), `running` (a program to its verdict), `encoding` (text at the boundary) |
93
101
  | C library | `clibrary`, `standardlibrary`, `librarycode` (the functions written in C), `formatting` (printf), `scanning` (scanf, strtod), `files` |
94
102
  | Debugger | `debugging` (the machine for the debugger driver), `sessions`, `variables` |
95
103
  | Editors | `querying` (the type query), `generate` (programs back to source) |
Binary file
Binary file
package/cfamily.cell CHANGED
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file