@cella-lang/c 0.1.202610121528 → 0.1.202610121705

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
@@ -4,6 +4,7 @@
4
4
 
5
5
  ## 未發佈
6
6
 
7
+ - **不相容**:定理與前置條件改證 `a = b`(原本是路徑 `≡`),同 cpp。名字不變;前置條件照舊寫 `refl` 或具名的洞。`stable-defs.json` 裡雜湊改變的 4 個:`c.ShlOk`、`c.divV`、`c.litV`、`c.remV`。
7
8
  - 標準庫 `int` 的定理改證 `a = b`(cpp 跟著改):用到的定義雜湊可能改變,意思不變。
8
9
  - 標準庫定理名字裡的舊運算名跟著改(`ltNat_refl` → `blt_refl`、`modNatLt` → `modLt`……;規則見 cella-lang 的 CHANGES):套件內的使用處一起改。
9
10
  - 標準庫的定理放進型別的 namespace(`addComm` → `Nat.addComm` 等;原始碼照舊寫裸名):用到它們的定義雜湊改變,意思不變。
package/README.md CHANGED
@@ -26,15 +26,15 @@ Statements reuse the language-neutral statement model of `@cella-lang/cpp` (`cpp
26
26
  Output: `c.format p fmt args refl : String` and `c.printf p fmt args refl st` (appends to the stream state shared with the C++ model and
27
27
  returns the number of characters as an `int`), the integer subset of `printf`: `%d %i %u %o %x %X %c %%`, flags `- + space # 0`, field width
28
28
  and precision (digits or `*`), length modifiers `hh h l ll`. Arguments go through the default argument promotions (`c.argV p x`). Undefined
29
- behaviour is the precondition `c.printfOkB p fmt args ≡ true`: a malformed or unknown conversion, too few arguments, an argument whose type
29
+ behaviour is the precondition `c.printfOkB p fmt args = true`: a malformed or unknown conversion, too few arguments, an argument whose type
30
30
  does not match the conversion (a signed/unsigned counterpart is allowed only when the value fits both), `#` with `d i u c`, `0` or a
31
31
  precision with `c`, anything inside `%%`.
32
32
 
33
33
  ```cella
34
34
  import c
35
35
  def p : cpp.Platform := c.lp64P
36
- def n (v : Int) (ok : cpp.inTB (c.tInt p) v ≡ true) : c.Arg := c.argV p (c.litV (c.tInt p) v ok)
37
- def s : c.format p "%5d|%-+4d|%#x" [n (pos 42) refl, n (pos 7) refl, n (pos 255) refl] refl ≡ " 42|+7 |0xff" := refl -- accept
36
+ def n (v : Int) (ok : cpp.inTB (c.tInt p) v = true) : c.Arg := c.argV p (c.litV (c.tInt p) v ok)
37
+ def s : c.format p "%5d|%-+4d|%#x" [n (pos 42) refl, n (pos 7) refl, n (pos 255) refl] refl = " 42|+7 |0xff" := refl -- accept
38
38
  def t : String := c.format p "%d %d" [n (pos 1) refl] refl -- reject: too few arguments
39
39
  ```
40
40
 
@@ -48,7 +48,7 @@ type. `c.sizeofA p a` is `N * sizeof(T)` as a `size_t`. For loops, `c.Full t n`
48
48
  import c
49
49
  def p : cpp.Platform := c.lp64P
50
50
  def a : c.Arr (c.tInt p) := c.initA (c.tInt p) 5 [c.litV (c.tInt p) (pos 1) refl, c.litV (c.tInt p) (pos 2) refl] refl
51
- def s : c.get (c.at a (c.litV (c.tInt p) (pos 3) refl) (c.readable refl)) ≡ pos 0 := refl -- accept: a[3] is zero
51
+ def s : c.get (c.at a (c.litV (c.tInt p) (pos 3) refl) (c.readable refl)) = pos 0 := refl -- accept: a[3] is zero
52
52
  def t : c.Val (c.tInt p) := c.at a (c.litV (c.tInt p) (pos 5) refl) (c.readable refl) -- reject: a[5] is out of bounds
53
53
  ```
54
54
 
@@ -64,7 +64,7 @@ without a NULL check does not prove. `c.calloc` zero-fills; `c.free` requires NU
64
64
  import c
65
65
  def t : cpp.IType := cpp.tInt cpp.lp64P
66
66
  def r : c.Allocated t := c.addrOf (c.memNew t) (c.litV t (pos 5) refl) -- int x = 5; int *q = &x;
67
- def s : c.get (c.load (c.amem r) (c.aptr r) (c.derefOk refl)) ≡ pos 5 := refl -- accept: *q is 5
67
+ def s : c.get (c.load (c.amem r) (c.aptr r) (c.derefOk refl)) = pos 5 := refl -- accept: *q is 5
68
68
  def u : c.Val t := c.load (c.memNew t) c.nullP (c.derefOk refl) -- reject: *NULL
69
69
  ```
70
70
 
@@ -81,7 +81,7 @@ import c
81
81
  def p : cpp.Platform := c.lp64P
82
82
  def C : cpp.IType := c.tChar p
83
83
  def r : c.Allocated C := c.strLit p (c.memNew C) "hello"
84
- def s : c.format p "[%-7s]" [c.argS (c.amem r) (c.aptr r)] refl ≡ "[hello ]" := refl -- accept
84
+ def s : c.format p "[%-7s]" [c.argS (c.amem r) (c.aptr r)] refl = "[hello ]" := refl -- accept
85
85
  def t : c.Mem C := c.store (c.amem r) (c.aptr r) (c.litV C (pos 72) refl) (c.storeOk refl) -- reject: writes a string literal
86
86
  ```
87
87
 
@@ -98,12 +98,12 @@ import c
98
98
  def I : cpp.IType := c.tInt c.lp64P
99
99
  def Point : c.Members := c.mCons "x" (c.ctInt I) (c.mCons "y" (c.ctInt I) c.mNil)
100
100
  def p : c.Struct Point := c.initS Point [c.iInt (c.litV I (pos 1) refl)] refl
101
- def y : c.get (c.scalar (c.member Point "y" p) refl) ≡ pos 0 := refl -- accept: y is zero-filled
101
+ def y : c.get (c.scalar (c.member Point "y" p) refl) = pos 0 := refl -- accept: y is zero-filled
102
102
  def u : c.Val I := c.scalar (c.member Point "y" (c.uninitS Point)) refl -- reject: y is uninitialized
103
103
  ```
104
104
 
105
105
  Array parameters are pointers, so a function does not know the length: `int sum(int a[], int n)` takes the precondition
106
- `c.readableNB m a n ≡ true` ("n cells after a are readable"), and `c.readK m a n ok k h` reads `a[k]` for `h : k < n` — the function is
106
+ `c.readableNB m a n = true` ("n cells after a are readable"), and `c.readK m a n ok k h` reads `a[k]` for `h : k < n` — the function is
107
107
  checked once for any memory and pointer, and a caller with a concrete array proves the precondition by `refl`. Writing is the same with
108
108
  `c.writableNB` / `c.writeK`, and `c.writableAfterWriteK` keeps the precondition through a loop. Pointers can be stored in memory
109
109
  (`cpp.GMem c.Ptr`, `c.loadP` for `*pp`), and `c.mkArgv p ["prog", "x"]` builds `argv` (NUL-terminated strings, a NULL at `argv[argc]`).
@@ -115,7 +115,7 @@ wrong type, a result that does not fit (`%d` reading `99999999999`), and a `%s`
115
115
 
116
116
  Multi-dimensional arrays: `c.arr2ToMem m R C inits refl` declares `T a[R][C]` (nested or flat initializers), and `c.at2 m a R C i j hi hj ok`
117
117
  reads `a[i][j]` with the bounds checked per dimension — `a[0][C]` is out of bounds for the inner array even though it is inside the object.
118
- A function taking `int a[][C]` gets `c.readable2 m a n C ≡ true` and reads with `c.read2K`.
118
+ A function taking `int a[][C]` gets `c.readable2 m a n C = true` and reads with `c.read2K`.
119
119
 
120
120
  Floating point: `c.Double` and `c.Float` are IEEE 754 binary64 and binary32 (shared with the C++ model). `c.dlit m e` is the literal
121
121
  m × 10^e; `c.toInt t x (c.truncOk refl)` truncates toward zero with the result required to fit; division needs a nonzero divisor.
package/c.cell CHANGED
Binary file