@cella-lang/python 0.1.202611141129 → 0.1.202611150249
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 +36 -0
- package/README.md +3 -1
- package/index.json +1538 -1266
- package/package.json +5 -5
- package/python.builtins.cell +0 -0
- package/python.calls.cell +0 -0
- package/python.cell +0 -0
- package/python.containers.cell +0 -0
- package/python.debugging.cell +0 -0
- package/python.dispatch.cell +0 -0
- package/python.execution.cell +0 -0
- package/python.flattening.cell +0 -0
- package/python.generators.cell +0 -0
- package/python.iterators.cell +0 -0
- package/python.lazy.cell +0 -0
- package/python.lowering.cell +0 -0
- package/python.methods.cell +0 -0
- package/python.numbers.cell +0 -0
- package/python.objects.cell +0 -0
- package/python.operations.cell +0 -0
- package/python.printing.cell +0 -0
- package/python.querying.cell +0 -0
- package/python.random.cell +0 -0
- package/python.session.cell +0 -0
- package/python.sets.cell +0 -0
- package/python.sorting.cell +0 -0
- package/python.symbols.cell +0 -0
- package/python.text.cell +0 -0
- package/python.values.cell +0 -0
- package/python.variables.cell +0 -0
package/CHANGES.md
CHANGED
|
@@ -2,6 +2,42 @@
|
|
|
2
2
|
|
|
3
3
|
## 未發佈
|
|
4
4
|
|
|
5
|
+
- **str 的 set 只在順序看得到時才假設 `str.hash`**(之前只要結束時堆上有一個裝著 str 的 set 就列進 `assumes`):一個名字
|
|
6
|
+
若只由 `x = {…}`、`x = {… for …}`、`x = set()`、`x = set(it)` 綁定(不在 class 本體裡),其他地方只用
|
|
7
|
+
`len(x)`、`sorted(x)`、`v in x`、`v not in x`、`x.add(v)`、`x.discard(v)`、`x.remove(v)`、`if x:`、`while x:`、
|
|
8
|
+
`not x`,它的 set 不算進 `assumes`——這些用法的結果與 set 裡的順序無關。`sorted(x)` 遇到不全是 str 的項目時照舊假設
|
|
9
|
+
(先比到哪一對決定是哪個 TypeError)。印出、走訪、轉成 list、經別的名字讀、當參數傳、`return`、`|=` 之類照舊假設;
|
|
10
|
+
程式自己定義了 `len`、`sorted`、`set`,或用到 `globals`、`locals`、`vars`、`eval`、`exec`、`builtins` 時全部照舊。
|
|
11
|
+
判決與輸出不變,只是 `assumes` 少了 `str.hash`(`tags = {"a", "b", "a"}; print(len(tags))`、`a = set(); a.add("b");
|
|
12
|
+
a.add("a"); for x in sorted(a): print(x)`)。
|
|
13
|
+
- 修正:set 印出之後再 `clear()`(或 `&=`、`-=` 等原地運算換掉內容)時漏了 `str.hash`/`object.address`(之前 `assumes`
|
|
14
|
+
只看結束時的內容;現在原地修改保留之前依賴的選擇)。
|
|
15
|
+
- **新增 `collections.deque`**(之前 `from collections import deque` 判 unknown):`from collections import deque`
|
|
16
|
+
(可以 `as`)、`import collections` 再 `collections.deque`。`deque()`、`deque(iterable)`;`append`、`appendleft`、`pop`、
|
|
17
|
+
`popleft`、`extend`、`clear`;`d[i]`、`d[i] = v`、`del d[i]`(負的從尾端數,越界是 `IndexError: deque index out of range`,
|
|
18
|
+
不是整數是 `TypeError: sequence index must be integer, not 'str'`,切片也是這個 TypeError);`len`、真假、`in`、`==`
|
|
19
|
+
(和另一個 deque 照內容,和 list 不相等)、迭代(`for`、`list`、`sorted`、`sum`、解開、`*d`),repr 是 `deque([1, 2])`
|
|
20
|
+
(裝著自己是 `deque([[...]])`)。空的 `pop()`、`popleft()` 是 `IndexError: pop from an empty deque`;參數個數的
|
|
21
|
+
TypeError 照 CPython(`deque.append() takes exactly one argument (0 given)`、`deque.pop() takes no arguments (1 given)`、
|
|
22
|
+
`deque() takes at most 2 arguments (3 given)`)。迭代時長度變了(append、pop、extend 非空、clear、del)照 CPython 的
|
|
23
|
+
`state` 是 `RuntimeError: deque mutated during iteration`——檢查在取下一個之前,所以走完之後再改、再 `next` 也是;只改
|
|
24
|
+
項目(`d[0] = v`)、`extend([])` 不算。型別名照 CPython:`<class 'collections.deque'>`、`deque.__name__` 是
|
|
25
|
+
`deque`,訊息裡是 `'collections.deque'`(不能 hash:`unhashable type: 'collections.deque'`;`d.x` 是 AttributeError),
|
|
26
|
+
`isinstance(d, deque)`、`type(d) is deque`;`d.maxlen` 是 None。兩端各放一個陣列(左邊的倒著放),兩端進出各是陣列的
|
|
27
|
+
深度;一端空了從另一端拿時把全部拆成兩半,所以一連串的 `popleft` 平均每個是常數。還不支援(判 unknown):`maxlen`(第二個
|
|
28
|
+
參數)與用 keyword 給的參數、`rotate`、`extendleft`、`insert`、`remove`、`index`、`count`、`copy`、`reverse`、
|
|
29
|
+
`reversed(d)`、`+`、`*`、`+=`、`*=`、兩個 deque 比大小、子類別化 deque、`collections` 裡其他的名字。
|
|
30
|
+
- 修正:以 `object` 與例外之外的內建類別當基底(`class Box(dict)`、`class Q(list)`)判 unknown(之前 `Box()` 錯判
|
|
31
|
+
accept,印出 `<__main__.Box object at 0x…>`;`Q([1])` 錯判成 `TypeError: Q() takes no arguments`)。`bool`、`range`、
|
|
32
|
+
`slice` 照舊是 `TypeError: type 'bool' is not an acceptable base type`。
|
|
33
|
+
- 修正:瀏覽器的建置上(WasmGC)大的串列判得出。`[0] * 200007`、`(7,) * N`、`"ab" * N`、`a *= N` 之前丟出
|
|
34
|
+
`RangeError: Maximum call stack size exceeded`(重複是 N 份串接,一層呼叫套一層,V8 約七千多層就爆;原生的 VM 撐得住,
|
|
35
|
+
所以本機的測試看不到),現在呼叫深度不隨 N 增加。`xs.append(x)`、`xs.extend(ys)` 與 `xs.pop()`(取最後一個)改成直接接在
|
|
36
|
+
陣列的尾端:之前每次把整個陣列攤成串列再建回來,推導式或迴圈建 N 個元素要 N^2(`[[0] * 2 for _ in range(100007)]` 在瀏覽器上
|
|
37
|
+
十分鐘還沒跑完,現在約三秒)。判決與輸出不變,用掉的步數也不變。
|
|
38
|
+
- 修正:瀏覽器的建置上讀 list 的一格(`xs[i]`)直接取陣列的那一格,不再先把整個 list 攤成串列再數過去(之前讀一次是 list 的
|
|
39
|
+
長度,迴圈裡逐個讀是 N^2:`a = [1] * 20000` 再逐個讀 `a[i]` 約 140 秒,廣度優先搜尋 2 萬個點約 9 分鐘,現在各是幾秒、
|
|
40
|
+
約 30 秒)。判決、輸出與步數不變。
|
|
5
41
|
- **新增 slice 物件**(之前 `slice(...)` 判 unknown,`xs[a:b]` 只在內部讀界限):`slice(stop)`、`slice(start, stop[, step])`
|
|
6
42
|
(參數個數與 keyword 的 TypeError 照 CPython),repr 與 str 是 `slice(1, 2, None)`,`start`、`stop`、`step` 是給的值
|
|
7
43
|
(唯讀:設定或刪除是 `AttributeError: readonly attribute`),`type(s) is slice`、`isinstance`。`indices(n)` 照
|
package/README.md
CHANGED
|
@@ -17,7 +17,9 @@ Depends on `@cella-lang/machine`.
|
|
|
17
17
|
`incomplete` for an empty slot, `indeterminate` for the step limit or waiting for input, `invalid` for JSON that is
|
|
18
18
|
not a program). `assumes` (always there) lists the implementation's choices the run relied on, each
|
|
19
19
|
`{"implementation": "CPython", "choice": …}`: `random.seed` (an unseeded `random` starts as
|
|
20
|
-
`seed(0)`), `str.hash` (a set ordered by str hashes, as under `PYTHONHASHSEED=0
|
|
20
|
+
`seed(0)`), `str.hash` (a set ordered by str hashes, as under `PYTHONHASHSEED=0`; not for a set held only by a
|
|
21
|
+
name bound to a new set and otherwise used only by `len`, `sorted` of str items, `in`, `not in`, `add`, `discard`,
|
|
22
|
+
`remove` and its truth, whose order shows nowhere) and `object.address` (an object's
|
|
21
23
|
address shown as text, or a set ordered by objects' hashes; each run of a `def` or `lambda` makes a function object
|
|
22
24
|
of its own, so a user's function is one too: the model places the object at heap position `a` at
|
|
23
25
|
`0x1000 + 16a`, not where CPython's memory would). A verdict proved by the kernels:
|