codecin 7.22.10__py3-none-win_amd64.whl

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.
Files changed (202) hide show
  1. codecin/__init__.py +27 -0
  2. codecin/aot.py +1057 -0
  3. codecin/assembler.py +619 -0
  4. codecin/cbackend.py +3024 -0
  5. codecin/cin.py +4265 -0
  6. codecin/cli.py +670 -0
  7. codecin/codecin_native.dll +0 -0
  8. codecin/config.py +50 -0
  9. codecin/console.py +183 -0
  10. codecin/cpu.py +312 -0
  11. codecin/crom.py +449 -0
  12. codecin/cvm.py +708 -0
  13. codecin/disasm.py +149 -0
  14. codecin/environment.py +176 -0
  15. codecin/errors.py +54 -0
  16. codecin/isa.py +560 -0
  17. codecin/lib/array/pic.toml +10 -0
  18. codecin/lib/array/src/array.cin +103 -0
  19. codecin/lib/bigint/pic.toml +10 -0
  20. codecin/lib/bigint/src/bigint.cin +589 -0
  21. codecin/lib/bits/pic.toml +10 -0
  22. codecin/lib/bits/src/bits.cin +143 -0
  23. codecin/lib/bitset/pic.toml +10 -0
  24. codecin/lib/bitset/src/bitset.cin +374 -0
  25. codecin/lib/codec/pic.toml +10 -0
  26. codecin/lib/codec/src/codec.cin +563 -0
  27. codecin/lib/combin/pic.toml +10 -0
  28. codecin/lib/combin/src/combin.cin +414 -0
  29. codecin/lib/conv/pic.toml +10 -0
  30. codecin/lib/conv/src/conv.cin +151 -0
  31. codecin/lib/cppstd/pic.toml +10 -0
  32. codecin/lib/cppstd/src/cppstd.cin +418 -0
  33. codecin/lib/cstd/pic.toml +10 -0
  34. codecin/lib/cstd/src/cstd.cin +424 -0
  35. codecin/lib/csv/pic.toml +10 -0
  36. codecin/lib/csv/src/csv.cin +405 -0
  37. codecin/lib/dp/pic.toml +10 -0
  38. codecin/lib/dp/src/dp.cin +325 -0
  39. codecin/lib/ffi/pic.toml +10 -0
  40. codecin/lib/ffi/src/ffi.cin +163 -0
  41. codecin/lib/fmt/pic.toml +10 -0
  42. codecin/lib/fmt/src/fmt.cin +325 -0
  43. codecin/lib/frac/pic.toml +10 -0
  44. codecin/lib/frac/src/frac.cin +252 -0
  45. codecin/lib/gostd/pic.toml +10 -0
  46. codecin/lib/gostd/src/gostd.cin +415 -0
  47. codecin/lib/graph/pic.toml +10 -0
  48. codecin/lib/graph/src/graph.cin +367 -0
  49. codecin/lib/gui/pic.toml +10 -0
  50. codecin/lib/gui/src/gui.cin +218 -0
  51. codecin/lib/hash/pic.toml +10 -0
  52. codecin/lib/hash/src/hash.cin +67 -0
  53. codecin/lib/heap/pic.toml +10 -0
  54. codecin/lib/heap/src/heap.cin +199 -0
  55. codecin/lib/io/pic.toml +10 -0
  56. codecin/lib/io/src/io.cin +141 -0
  57. codecin/lib/json/pic.toml +10 -0
  58. codecin/lib/json/src/json.cin +84 -0
  59. codecin/lib/key/pic.toml +10 -0
  60. codecin/lib/key/src/key.cin +78 -0
  61. codecin/lib/math/pic.toml +10 -0
  62. codecin/lib/math/src/math.cin +50 -0
  63. codecin/lib/matrix/pic.toml +10 -0
  64. codecin/lib/matrix/src/matrix.cin +155 -0
  65. codecin/lib/net/pic.toml +10 -0
  66. codecin/lib/net/src/net.cin +171 -0
  67. codecin/lib/path/pic.toml +10 -0
  68. codecin/lib/path/src/path.cin +372 -0
  69. codecin/lib/queue/pic.toml +10 -0
  70. codecin/lib/queue/src/queue.cin +112 -0
  71. codecin/lib/rand/pic.toml +10 -0
  72. codecin/lib/rand/src/rand.cin +46 -0
  73. codecin/lib/set/pic.toml +10 -0
  74. codecin/lib/set/src/set.cin +269 -0
  75. codecin/lib/sort/pic.toml +10 -0
  76. codecin/lib/sort/src/sort.cin +93 -0
  77. codecin/lib/stat/pic.toml +10 -0
  78. codecin/lib/stat/src/stat.cin +138 -0
  79. codecin/lib/str/pic.toml +10 -0
  80. codecin/lib/str/src/str.cin +54 -0
  81. codecin/lib/termux/pic.toml +10 -0
  82. codecin/lib/termux/src/termux.cin +118 -0
  83. codecin/lib/test/pic.toml +10 -0
  84. codecin/lib/test/src/test.cin +74 -0
  85. codecin/lib/text/pic.toml +10 -0
  86. codecin/lib/text/src/text.cin +323 -0
  87. codecin/lib/time/pic.toml +10 -0
  88. codecin/lib/time/src/time.cin +54 -0
  89. codecin/lib/token/pic.toml +10 -0
  90. codecin/lib/token/src/token.cin +183 -0
  91. codecin/lib/tree/pic.toml +10 -0
  92. codecin/lib/tree/src/tree.cin +256 -0
  93. codecin/lib/unionfind/pic.toml +10 -0
  94. codecin/lib/unionfind/src/unionfind.cin +115 -0
  95. codecin/lib/validate/pic.toml +10 -0
  96. codecin/lib/validate/src/validate.cin +148 -0
  97. codecin/lib/vec/pic.toml +10 -0
  98. codecin/lib/vec/src/vec.cin +88 -0
  99. codecin/logger.py +145 -0
  100. codecin/memory.py +306 -0
  101. codecin/mkn.py +916 -0
  102. codecin/native/aot/aot.go +114 -0
  103. codecin/native/aot/stub_main.go.txt +23 -0
  104. codecin/native/build.ps1 +33 -0
  105. codecin/native/build.sh +48 -0
  106. codecin/native/cmd/cincc/main.go +66 -0
  107. codecin/native/compiler/codegen.go +2238 -0
  108. codecin/native/compiler/compile_test.go +1069 -0
  109. codecin/native/compiler/parser.go +1331 -0
  110. codecin/native/compiler/syscalls.go +166 -0
  111. codecin/native/compiler/tokenizer.go +394 -0
  112. codecin/native/compiler/types.go +217 -0
  113. codecin/native/engine/args.go +37 -0
  114. codecin/native/engine/audio.go +402 -0
  115. codecin/native/engine/audio_other.go +105 -0
  116. codecin/native/engine/audio_test.go +279 -0
  117. codecin/native/engine/audio_windows.go +190 -0
  118. codecin/native/engine/canvas.go +271 -0
  119. codecin/native/engine/console_other.go +9 -0
  120. codecin/native/engine/console_windows.go +43 -0
  121. codecin/native/engine/crom.go +86 -0
  122. codecin/native/engine/encode.go +93 -0
  123. codecin/native/engine/engine_test.go +198 -0
  124. codecin/native/engine/ffi_nocgo.go +20 -0
  125. codecin/native/engine/ffi_registry.go +69 -0
  126. codecin/native/engine/ffi_unix.go +109 -0
  127. codecin/native/engine/ffi_windows.go +117 -0
  128. codecin/native/engine/gui.go +209 -0
  129. codecin/native/engine/gui_stub.go +13 -0
  130. codecin/native/engine/gui_test.go +148 -0
  131. codecin/native/engine/gui_windows.go +604 -0
  132. codecin/native/engine/gui_x11.go +723 -0
  133. codecin/native/engine/host_test.go +139 -0
  134. codecin/native/engine/hostcrypto.go +30 -0
  135. codecin/native/engine/hostdesktop.go +173 -0
  136. codecin/native/engine/hostnet.go +127 -0
  137. codecin/native/engine/isa_gen.go +689 -0
  138. codecin/native/engine/keyboard.go +432 -0
  139. codecin/native/engine/keyboard_other.go +94 -0
  140. codecin/native/engine/keyboard_stub.go +17 -0
  141. codecin/native/engine/keyboard_termios_darwin.go +9 -0
  142. codecin/native/engine/keyboard_termios_linux.go +9 -0
  143. codecin/native/engine/keyboard_test.go +246 -0
  144. codecin/native/engine/keyboard_windows.go +208 -0
  145. codecin/native/engine/keyboard_windows_test.go +123 -0
  146. codecin/native/engine/lineedit.go +262 -0
  147. codecin/native/engine/lineedit_test.go +105 -0
  148. codecin/native/engine/lineint_unix.go +17 -0
  149. codecin/native/engine/lineint_windows.go +19 -0
  150. codecin/native/engine/mem_other.go +37 -0
  151. codecin/native/engine/mem_windows.go +33 -0
  152. codecin/native/engine/native.go +640 -0
  153. codecin/native/engine/netsock.go +321 -0
  154. codecin/native/engine/ops_ext.go +515 -0
  155. codecin/native/engine/stdin.go +72 -0
  156. codecin/native/engine/stdin_other.go +9 -0
  157. codecin/native/engine/stdin_windows.go +60 -0
  158. codecin/native/engine/system.go +313 -0
  159. codecin/native/engine/termux.go +180 -0
  160. codecin/native/engine/version_gen.go +7 -0
  161. codecin/native/engine/vkb_darwin.go +62 -0
  162. codecin/native/engine/vkb_linux.go +95 -0
  163. codecin/native/engine/vkb_stub.go +11 -0
  164. codecin/native/engine/vm.go +1677 -0
  165. codecin/native/go.mod +3 -0
  166. codecin/native/ir/ir.go +48 -0
  167. codecin/native/main.go +448 -0
  168. codecin/native/mc/aarch64.go +165 -0
  169. codecin/native/mc/aarch64_test.go +30 -0
  170. codecin/native/mc/elf.go +88 -0
  171. codecin/native/mc/print_test.go +52 -0
  172. codecin/native/mc/x86_64.go +1262 -0
  173. codecin/native/mc/x86_64_test.go +102 -0
  174. codecin/native.py +432 -0
  175. codecin/native_codegen.py +987 -0
  176. codecin/nativegen.py +786 -0
  177. codecin/object.py +539 -0
  178. codecin/optimizer.py +236 -0
  179. codecin/packaging/__init__.py +46 -0
  180. codecin/packaging/archive.py +177 -0
  181. codecin/packaging/model.py +519 -0
  182. codecin/packaging/spec.py +193 -0
  183. codecin/packaging/store.py +372 -0
  184. codecin/packaging/toml.py +541 -0
  185. codecin/packaging/vcs.py +215 -0
  186. codecin/pic.py +1917 -0
  187. codecin/pic_api.py +374 -0
  188. codecin/pic_login.py +519 -0
  189. codecin/pic_registry.py +515 -0
  190. codecin/registers.py +130 -0
  191. codecin/sdgcc.py +493 -0
  192. codecin/stats.py +230 -0
  193. codecin/stdlib.py +138 -0
  194. codecin/toolchain.py +396 -0
  195. codecin/toolkit.py +26 -0
  196. codecin/version.py +260 -0
  197. codecin-7.22.10.dist-info/METADATA +1077 -0
  198. codecin-7.22.10.dist-info/RECORD +202 -0
  199. codecin-7.22.10.dist-info/WHEEL +5 -0
  200. codecin-7.22.10.dist-info/entry_points.txt +5 -0
  201. codecin-7.22.10.dist-info/licenses/LICENSE +7 -0
  202. codecin-7.22.10.dist-info/top_level.txt +1 -0
@@ -0,0 +1,199 @@
1
+ // Code CIN 官方标准库: 定长二叉堆 (heap)
2
+ // 用法: import "heap.cin"
3
+ //
4
+ // 纯 CIN 实现, 不使用任何宿主能力内建, 也不做动态内存分配:
5
+ // 堆存放在库内全局数组里, 容量上限 HEAP_CAP = 64。
6
+ // 同一份实现同时支持最小堆与最大堆, 由标志位 heap_is_max 选择
7
+ // (heap_is_max == 0 为最小堆, 非零为最大堆); heap_sort 固定升序。
8
+ //
9
+ // 全局数据段占用 (每槽 8 字节):
10
+ // heap_data[64] = 64 槽
11
+ // 标量 (heap_len / heap_is_max) = 2 槽
12
+ // 合计 66 槽 = 528 字节, 远小于默认 64 KiB 数据段。
13
+ //
14
+ // 语义说明:
15
+ // * 库内只有一份全局实例, 同一程序内共享; 需要多个堆请用 struct 自行封装;
16
+ // * heap_sort 直接在被排序数组上就地完成 (内部自建最大堆), 不读写上面的全局堆,
17
+ // 因此调用 heap_sort 不会破坏已有的堆状态;
18
+ // * 空堆: heap_pop / heap_peek / heap_replace 返回 0 (无法区分"空"与"堆顶就是 0",
19
+ // 需要区分时先查 heap_is_empty)。
20
+
21
+ int heap_data[64]
22
+ int heap_len = 0
23
+ int heap_is_max = 0
24
+
25
+ // ---------------- 生命周期 ----------------
26
+
27
+ // 容量上限
28
+ function heap_capacity() -> int {
29
+ return 64
30
+ }
31
+
32
+ // 重置为空堆; is_max 非零表示最大堆, 否则最小堆
33
+ function heap_reset(int is_max) -> void {
34
+ heap_len = 0
35
+ if (is_max) {
36
+ heap_is_max = 1
37
+ } else {
38
+ heap_is_max = 0
39
+ }
40
+ }
41
+
42
+ // ---------------- 状态查询 ----------------
43
+
44
+ function heap_size() -> int {
45
+ return heap_len
46
+ }
47
+
48
+ // 空堆返回 1
49
+ function heap_is_empty() -> int {
50
+ if (heap_len == 0) { return 1 }
51
+ return 0
52
+ }
53
+
54
+ // ---------------- 内部辅助 ----------------
55
+
56
+ // a 是否应排在 b 前面 (即 a 更靠近堆顶); 内部辅助
57
+ function heap_better(int a, int b) -> int {
58
+ if (heap_is_max != 0) {
59
+ if (a > b) { return 1 }
60
+ return 0
61
+ }
62
+ if (a < b) { return 1 }
63
+ return 0
64
+ }
65
+
66
+ // 把下标 i 的元素下沉到合适位置 (内部辅助, 按当前 heap_is_max)
67
+ function heap_sift_down(int i) -> void {
68
+ int done = 0
69
+ while (done == 0) {
70
+ int l = 2 * i + 1
71
+ int r = 2 * i + 2
72
+ int best = i
73
+ if (l < heap_len && heap_better(heap_data[l], heap_data[best]) == 1) { best = l }
74
+ if (r < heap_len && heap_better(heap_data[r], heap_data[best]) == 1) { best = r }
75
+ if (best == i) {
76
+ done = 1
77
+ } else {
78
+ int t = heap_data[i]
79
+ heap_data[i] = heap_data[best]
80
+ heap_data[best] = t
81
+ i = best
82
+ }
83
+ }
84
+ }
85
+
86
+ // 在 a[0..m-1] 内把下标 i 下沉 (最大堆, 供 heap_sort 用); 内部辅助
87
+ function heap_sift_max(int[] a, int m, int i) -> void {
88
+ int done = 0
89
+ while (done == 0) {
90
+ int l = 2 * i + 1
91
+ int r = 2 * i + 2
92
+ int best = i
93
+ if (l < m && a[l] > a[best]) { best = l }
94
+ if (r < m && a[r] > a[best]) { best = r }
95
+ if (best == i) {
96
+ done = 1
97
+ } else {
98
+ int t = a[i]
99
+ a[i] = a[best]
100
+ a[best] = t
101
+ i = best
102
+ }
103
+ }
104
+ }
105
+
106
+ // ---------------- 入堆 / 出堆 ----------------
107
+
108
+ // 入堆; 成功返回 1, 满时返回 0 (丢弃该值)
109
+ function heap_push(int v) -> int {
110
+ if (heap_len >= 64) { return 0 }
111
+ int i = heap_len
112
+ heap_data[i] = v
113
+ heap_len = heap_len + 1
114
+ int done = 0
115
+ while (i > 0 && done == 0) {
116
+ int p = idiv(i - 1, 2)
117
+ if (heap_better(heap_data[i], heap_data[p]) == 1) {
118
+ int t = heap_data[i]
119
+ heap_data[i] = heap_data[p]
120
+ heap_data[p] = t
121
+ i = p
122
+ } else {
123
+ done = 1
124
+ }
125
+ }
126
+ return 1
127
+ }
128
+
129
+ // 弹出堆顶并返回; 空堆返回 0
130
+ function heap_pop() -> int {
131
+ if (heap_len == 0) { return 0 }
132
+ int top = heap_data[0]
133
+ heap_len = heap_len - 1
134
+ if (heap_len > 0) {
135
+ heap_data[0] = heap_data[heap_len]
136
+ heap_sift_down(0)
137
+ }
138
+ return top
139
+ }
140
+
141
+ // 查看堆顶 (不出堆); 空堆返回 0
142
+ function heap_peek() -> int {
143
+ if (heap_len == 0) { return 0 }
144
+ return heap_data[0]
145
+ }
146
+
147
+ // 弹出堆顶并压入 v, 返回被弹出的值; 空堆时等价于 push(v) 并返回 0
148
+ function heap_replace(int v) -> int {
149
+ if (heap_len == 0) {
150
+ heap_push(v)
151
+ return 0
152
+ }
153
+ int top = heap_data[0]
154
+ heap_data[0] = v
155
+ heap_sift_down(0)
156
+ return top
157
+ }
158
+
159
+ // ---------------- 建堆 / 校验 / 排序 ----------------
160
+
161
+ // 用 a 的前 n 个元素重建堆; n 钳制到 [0, 64], 超过容量的元素被丢弃
162
+ function heap_build(int[] a, int n, int is_max) -> void {
163
+ heap_reset(is_max)
164
+ int k = n
165
+ if (k < 0) { k = 0 }
166
+ if (k > 64) { k = 64 }
167
+ for (int i = 0; i < k; i = i + 1) {
168
+ heap_data[i] = a[i]
169
+ }
170
+ heap_len = k
171
+ int i = idiv(heap_len, 2) - 1
172
+ while (i >= 0) {
173
+ heap_sift_down(i)
174
+ i = i - 1
175
+ }
176
+ }
177
+
178
+ // 校验堆性质: 每个孩子都不比父节点更优先; 满足返回 1, 否则 0
179
+ function heap_is_valid() -> int {
180
+ for (int i = 1; i < heap_len; i = i + 1) {
181
+ int p = idiv(i - 1, 2)
182
+ if (heap_better(heap_data[i], heap_data[p]) == 1) { return 0 }
183
+ }
184
+ return 1
185
+ }
186
+
187
+ // 就地升序排序 (堆排序, 内部自建最大堆); 不依赖也不修改全局堆状态
188
+ function heap_sort(int[] a, int n) -> void {
189
+ if (n <= 1) { return }
190
+ for (int i = idiv(n, 2) - 1; i >= 0; i = i - 1) {
191
+ heap_sift_max(a, n, i)
192
+ }
193
+ for (int end = n - 1; end > 0; end = end - 1) {
194
+ int t = a[0]
195
+ a[0] = a[end]
196
+ a[end] = t
197
+ heap_sift_max(a, end, 0)
198
+ }
199
+ }
@@ -0,0 +1,10 @@
1
+ # 由 script/sync_stdlib_packages.py 生成,请勿手工编辑。
2
+ [package]
3
+ name = "io"
4
+ version = "7.22.10"
5
+ description = "Code CIN 官方标准库: 文件与路径"
6
+ license = "MIT"
7
+ authors = ["ByUsi Studio"]
8
+ entry = "src/io.cin"
9
+ repo = "https://gitee.com/codecin/internal-libraries"
10
+ keywords = ["codecin", "stdlib", "io"]
@@ -0,0 +1,141 @@
1
+ // Code CIN 官方标准库: 文件与路径 (io)
2
+ // 用法: import "io.cin"
3
+ // 依赖内建: file_read / file_write / file_append / file_exists / file_size ...
4
+ // 注意: 全部为 Go 原生能力 (需原生运行时)。
5
+
6
+ // 读取整个文本 (失败为空串)
7
+ function io_read(string path) -> string {
8
+ return file_read(path)
9
+ }
10
+
11
+ // 覆盖写入 (0 成功 / -1 失败)
12
+ function io_write(string path, string text) -> int {
13
+ return file_write(path, text)
14
+ }
15
+
16
+ // 追加写入
17
+ function io_append(string path, string text) -> int {
18
+ return file_append(path, text)
19
+ }
20
+
21
+ // 是否存在
22
+ function io_exists(string path) -> int {
23
+ return file_exists(path)
24
+ }
25
+
26
+ // 字节数 (-1 失败)
27
+ function io_size(string path) -> int {
28
+ return file_size(path)
29
+ }
30
+
31
+ // 删除
32
+ function io_remove(string path) -> int {
33
+ return file_delete(path)
34
+ }
35
+
36
+ // 递归创建目录
37
+ function io_mkdir(string path) -> int {
38
+ return mkdir(path)
39
+ }
40
+
41
+ // 目录条目 (换行分隔; 目录名带 /)
42
+ function io_list(string path) -> string {
43
+ return dir_list(path)
44
+ }
45
+
46
+ // 路径拼接 (自动补 /; 不处理 .. 归一化)
47
+ function io_join(string a, string b) -> string {
48
+ if (strlen(a) == 0) { return b }
49
+ if (strlen(b) == 0) { return a }
50
+ int last = a[strlen(a) - 1]
51
+ if (last == 47 || last == 92) { return a + b }
52
+ return a + "/" + b
53
+ }
54
+
55
+ // 取路径最后一段 (文件名)
56
+ function io_basename(string path) -> string {
57
+ int n = strlen(path)
58
+ int cut = -1
59
+ for (int i = 0; i < n; i = i + 1) {
60
+ if (path[i] == 47 || path[i] == 92) { cut = i }
61
+ }
62
+ if (cut < 0) { return path }
63
+ return substr(path, cut + 1, n - cut - 1)
64
+ }
65
+
66
+ // 取路径目录部分 (无分隔符返回 "")
67
+ function io_dirname(string path) -> string {
68
+ int n = strlen(path)
69
+ int cut = -1
70
+ for (int i = 0; i < n; i = i + 1) {
71
+ if (path[i] == 47 || path[i] == 92) { cut = i }
72
+ }
73
+ if (cut < 0) { return "" }
74
+ return substr(path, 0, cut)
75
+ }
76
+
77
+ // 行数 (按 \n; 空串为 0)
78
+ function io_line_count(string text) -> int {
79
+ int n = strlen(text)
80
+ if (n == 0) { return 0 }
81
+ int c = 1
82
+ for (int i = 0; i < n; i = i + 1) {
83
+ if (text[i] == 10) { c = c + 1 }
84
+ }
85
+ return c
86
+ }
87
+
88
+ // 取第 idx 行 (0 起, 不含换行符; 越界返回 "")
89
+ function io_get_line(string text, int idx) -> string {
90
+ int n = strlen(text)
91
+ int line = 0
92
+ int start = 0
93
+ for (int i = 0; i <= n; i = i + 1) {
94
+ if (i == n || text[i] == 10) {
95
+ if (line == idx) { return substr(text, start, i - start) }
96
+ line = line + 1
97
+ start = i + 1
98
+ }
99
+ }
100
+ return ""
101
+ }
102
+
103
+ // 按分隔串切分, 返回第 idx 段 (0 起; 越界返回 "")
104
+ function io_split_get(string text, string sep, int idx) -> string {
105
+ int sl = strlen(sep)
106
+ if (sl == 0) { return idx == 0 ? text : "" }
107
+ int n = strlen(text)
108
+ int seg = 0
109
+ int start = 0
110
+ int i = 0
111
+ while (i <= n - sl) {
112
+ if (strcmp(substr(text, i, sl), sep) == 0) {
113
+ if (seg == idx) { return substr(text, start, i - start) }
114
+ seg = seg + 1
115
+ i = i + sl
116
+ start = i
117
+ continue
118
+ }
119
+ i = i + 1
120
+ }
121
+ if (seg == idx) { return substr(text, start, n - start) }
122
+ return ""
123
+ }
124
+
125
+ // 按分隔串切分的段数
126
+ function io_split_count(string text, string sep) -> int {
127
+ int sl = strlen(sep)
128
+ if (sl == 0) { return 1 }
129
+ int n = strlen(text)
130
+ int c = 1
131
+ int i = 0
132
+ while (i <= n - sl) {
133
+ if (strcmp(substr(text, i, sl), sep) == 0) {
134
+ c = c + 1
135
+ i = i + sl
136
+ continue
137
+ }
138
+ i = i + 1
139
+ }
140
+ return c
141
+ }
@@ -0,0 +1,10 @@
1
+ # 由 script/sync_stdlib_packages.py 生成,请勿手工编辑。
2
+ [package]
3
+ name = "json"
4
+ version = "7.22.10"
5
+ description = "Code CIN 官方标准库: 极简 JSON 取值"
6
+ license = "MIT"
7
+ authors = ["ByUsi Studio"]
8
+ entry = "src/json.cin"
9
+ repo = "https://gitee.com/codecin/internal-libraries"
10
+ keywords = ["codecin", "stdlib", "json"]
@@ -0,0 +1,84 @@
1
+ // Code CIN 官方标准库: 极简 JSON 取值 (json)
2
+ // 用法: import "json.cin"
3
+ // 说明: 面向扁平对象 (Termux API 等返回的 JSON), 不做完整语法解析。
4
+ // 支持 "key": value 的字符串/数字/布尔/空值提取。
5
+
6
+ // 取 key 对应的原始片段 (字符串去引号; 数字/布尔原样; 找不到返回 "")
7
+ function j_raw(string json, string key) -> string {
8
+ string pat = "\"" + key + "\""
9
+ int p = indexof(json, pat)
10
+ if (p < 0) { return "" }
11
+ int after = p + strlen(pat)
12
+ string rest = substr(json, after, 9999)
13
+ int q = indexof(rest, ":")
14
+ if (q < 0) { return "" }
15
+ int n = strlen(json)
16
+ int start = after + q + 1
17
+ // 跳过空白
18
+ while (start < n && (json[start] == 32 || json[start] == 9 || json[start] == 10 || json[start] == 13)) {
19
+ start = start + 1
20
+ }
21
+ if (start >= n) { return "" }
22
+ if (json[start] == 34) {
23
+ // 字符串值
24
+ int end = start + 1
25
+ while (end < n && json[end] != 34) { end = end + 1 }
26
+ return substr(json, start + 1, end - start - 1)
27
+ }
28
+ // 数字 / true / false / null
29
+ int end = start
30
+ while (end < n && json[end] != 44 && json[end] != 125) { end = end + 1 }
31
+ return trim(substr(json, start, end - start))
32
+ }
33
+
34
+ // 取字符串字段
35
+ function j_str(string json, string key) -> string {
36
+ return j_raw(json, key)
37
+ }
38
+
39
+ // 取整数字段 (无法解析为 0)
40
+ function j_int(string json, string key) -> int {
41
+ return atoi(j_raw(json, key))
42
+ }
43
+
44
+ // 取浮点字段 (支持可选负号与小数; 无法解析为 0.0)
45
+ function j_float(string json, string key) -> float {
46
+ string s = j_raw(json, key)
47
+ int n = strlen(s)
48
+ int i = 0
49
+ int neg = 0
50
+ if (i < n && s[i] == 45) {
51
+ neg = 1
52
+ i = i + 1
53
+ }
54
+ float v = 0.0
55
+ while (i < n && s[i] >= 48 && s[i] <= 57) {
56
+ v = v * 10.0 + (s[i] - 48)
57
+ i = i + 1
58
+ }
59
+ if (i < n && s[i] == 46) {
60
+ i = i + 1
61
+ float scale = 0.1
62
+ while (i < n && s[i] >= 48 && s[i] <= 57) {
63
+ v = v + (s[i] - 48) * scale
64
+ scale = scale * 0.1
65
+ i = i + 1
66
+ }
67
+ }
68
+ if (neg == 1) { return -v }
69
+ return v
70
+ }
71
+
72
+ // 是否包含 key
73
+ function j_has(string json, string key) -> int {
74
+ if (indexof(json, "\"" + key + "\"") >= 0) { return 1 }
75
+ return 0
76
+ }
77
+
78
+ // 取布尔字段 (true/1 为 1, 否则 0)
79
+ function j_bool(string json, string key) -> int {
80
+ string v = j_raw(json, key)
81
+ if (strcmp(v, "true") == 0) { return 1 }
82
+ if (strcmp(v, "1") == 0) { return 1 }
83
+ return 0
84
+ }
@@ -0,0 +1,10 @@
1
+ # 由 script/sync_stdlib_packages.py 生成,请勿手工编辑。
2
+ [package]
3
+ name = "key"
4
+ version = "7.22.10"
5
+ description = "Code CIN 官方标准库: 键盘输入监听便捷封装"
6
+ license = "MIT"
7
+ authors = ["ByUsi Studio"]
8
+ entry = "src/key.cin"
9
+ repo = "https://gitee.com/codecin/internal-libraries"
10
+ keywords = ["codecin", "stdlib", "key"]
@@ -0,0 +1,78 @@
1
+ // Code CIN 官方标准库: 键盘输入监听便捷封装 (key)
2
+ // 用法: import "key.cin"
3
+ // 说明: 需真实终端 (管道 / 重定向下 get_key 恒为 -1, key_hit 恒为 0)。
4
+ // 首次调用会切换终端原始输入 (不回显), 程序退出自动恢复;
5
+ // Ctrl+C 在此期间不再终止程序, 表现为键码 3 (K_CTRL(67))。
6
+
7
+ // 扩展键码 (与原生引擎一致; 0..255 为原始字节码)
8
+ enum Key {
9
+ K_UP = 1001,
10
+ K_DOWN = 1002,
11
+ K_LEFT = 1003,
12
+ K_RIGHT = 1004,
13
+ K_HOME = 1005,
14
+ K_END = 1006,
15
+ K_PGUP = 1007,
16
+ K_PGDN = 1008,
17
+ K_INS = 1009,
18
+ K_DEL = 1010,
19
+ K_F1 = 1021,
20
+ K_F2 = 1022,
21
+ K_F3 = 1023,
22
+ K_F4 = 1024,
23
+ K_F5 = 1025,
24
+ K_F6 = 1026,
25
+ K_F7 = 1027,
26
+ K_F8 = 1028,
27
+ K_F9 = 1029,
28
+ K_F10 = 1030,
29
+ K_F11 = 1031,
30
+ K_F12 = 1032,
31
+ K_CTRL_UP = 1101,
32
+ K_CTRL_DOWN = 1102,
33
+ K_CTRL_LEFT = 1103,
34
+ K_CTRL_RIGHT = 1104,
35
+ K_SHIFT_UP = 1105,
36
+ K_SHIFT_DOWN = 1106,
37
+ K_SHIFT_LEFT = 1107,
38
+ K_SHIFT_RIGHT = 1108,
39
+ K_SHIFT_TAB = 1109,
40
+ K_ESC = 27,
41
+ K_ENTER = 13,
42
+ K_TAB = 9,
43
+ K_BACKSPACE = 8
44
+ }
45
+
46
+ // Ctrl 组合键码: k_ctrl('C') 即 Ctrl+C (3)
47
+ function k_ctrl(int c) -> int {
48
+ return c & 0x1F
49
+ }
50
+
51
+ // 是否扩展键码 (方向键 / 功能键 / 修饰组合等, 非 0..255 原始字节)
52
+ function k_is_special(int code) -> int {
53
+ if (code >= 1001 && code <= 1032) { return 1 }
54
+ if (code >= 1101 && code <= 1109) { return 1 }
55
+ return 0
56
+ }
57
+
58
+ // 是否功能键 F1..F12
59
+ function k_is_function(int code) -> int {
60
+ if (code >= 1021 && code <= 1032) { return 1 }
61
+ return 0
62
+ }
63
+
64
+ // 是否修饰键 + 方向键组合 (Ctrl/Shift + 方向)
65
+ function k_is_modified_arrow(int code) -> int {
66
+ if (code >= 1101 && code <= 1108) { return 1 }
67
+ return 0
68
+ }
69
+
70
+ // 阻塞等待一个按键 (内部 10ms 轮询 get_key)
71
+ function key_wait() -> int {
72
+ while (1) {
73
+ int k = get_key()
74
+ if (k != -1) { return k }
75
+ sleep_ms(10)
76
+ }
77
+ return -1
78
+ }
@@ -0,0 +1,10 @@
1
+ # 由 script/sync_stdlib_packages.py 生成,请勿手工编辑。
2
+ [package]
3
+ name = "math"
4
+ version = "7.22.10"
5
+ description = "Code CIN 纯 CIN 数学扩展"
6
+ license = "MIT"
7
+ authors = ["ByUsi Studio"]
8
+ entry = "src/math.cin"
9
+ repo = "https://gitee.com/codecin/internal-libraries"
10
+ keywords = ["codecin", "stdlib", "math"]
@@ -0,0 +1,50 @@
1
+ // Code CIN 纯 CIN 数学扩展 (codecin/lib/math.cin)
2
+ // 用法: import "math.cin"
3
+ // 说明: '/' 为浮点除法; 这里提供显式取整/最值/夹取辅助函数。
4
+
5
+ function f_abs(float x) -> float {
6
+ if (x < 0.0) { return -x }
7
+ return x
8
+ }
9
+
10
+ // 向下取整 (负数向 -inf)
11
+ function f_floor(float x) -> float {
12
+ int t = x
13
+ if (x < t) { return t - 1 }
14
+ return t
15
+ }
16
+
17
+ function f_ceil(float x) -> float {
18
+ return -f_floor(-x)
19
+ }
20
+
21
+ // 四舍五入 (x+0.5 向下取整)
22
+ function f_round(float x) -> float {
23
+ return f_floor(x + 0.5)
24
+ }
25
+
26
+ function f_min(float a, float b) -> float {
27
+ if (a < b) { return a }
28
+ return b
29
+ }
30
+
31
+ function f_max(float a, float b) -> float {
32
+ if (a > b) { return a }
33
+ return b
34
+ }
35
+
36
+ function i_min(int a, int b) -> int {
37
+ if (a < b) { return a }
38
+ return b
39
+ }
40
+
41
+ function i_max(int a, int b) -> int {
42
+ if (a > b) { return a }
43
+ return b
44
+ }
45
+
46
+ function i_clamp(int v, int lo, int hi) -> int {
47
+ if (v < lo) { return lo }
48
+ if (v > hi) { return hi }
49
+ return v
50
+ }
@@ -0,0 +1,10 @@
1
+ # 由 script/sync_stdlib_packages.py 生成,请勿手工编辑。
2
+ [package]
3
+ name = "matrix"
4
+ version = "7.22.10"
5
+ description = "Code CIN 官方标准库: 方阵运算"
6
+ license = "MIT"
7
+ authors = ["ByUsi Studio"]
8
+ entry = "src/matrix.cin"
9
+ repo = "https://gitee.com/codecin/internal-libraries"
10
+ keywords = ["codecin", "stdlib", "matrix"]