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,415 @@
1
+ // Code CIN 官方标准库: Go 标准库兼容层 (gostd)
2
+ // 用法: import "gostd.cin"
3
+ //
4
+ // 覆盖范围 (纯 CIN 实现, 与 Go 标准库命名的对应关系):
5
+ // strings —— Contains/Index/重复/大小写/裁剪/前后缀/替换等常用函数
6
+ // strconv —— Itoa/Atoi/ParseBool/FormatFloat(经 ftoa) 等转换
7
+ // math —— Sqrt/Abs/Floor/Ceil/Round/Pow 等包装
8
+ // slices —— Contains/Index/Sort(经排序内建)/Reverse 等常用操作
9
+ // os —— 仅 os.Args (go_os_args_len / go_os_args_get)
10
+ // 未覆盖 (避免误解): time、os 文件读写、net/http、sync 等包暂无兼容层 ——
11
+ // 计时请用内建 time_ms/time_us/time_ns, 文件读写用内建 file_* 函数族。
12
+ //
13
+ // 以 pkg.Func 命名习惯提供上述包的常用函数 (go_strings_contains 对应
14
+ // strings.Contains)。命名里的包段与 Go 文档一一对应, 便于从 Go 移植或
15
+ // 查阅语义。
16
+ // 注意: go_os_args_len / go_os_args_get 依赖命令行参数内建 (arg_count /
17
+ // arg, SYS 129..130), 需要原生路径 (CLI `--` 传参或 AOT 产物 os.Args)。
18
+
19
+ // ==================== strings ====================
20
+
21
+ // strings.Contains
22
+ function go_strings_contains(string s, string sub) -> int {
23
+ if (indexof(s, sub) >= 0) { return 1 }
24
+ return 0
25
+ }
26
+
27
+ // strings.Index: 未找到 -1 (与 Go 语义一致)
28
+ function go_strings_index(string s, string sub) -> int {
29
+ return indexof(s, sub)
30
+ }
31
+
32
+ // strings.ContainsAny 的单字符特例: s 是否含任一 ch 中字符
33
+ function go_strings_contains_any(string s, string chars) -> int {
34
+ int n = strlen(chars)
35
+ for (int i = 0; i < n; i = i + 1) {
36
+ if (indexof(s, substr(chars, i, 1)) >= 0) { return 1 }
37
+ }
38
+ return 0
39
+ }
40
+
41
+ // strings.HasPrefix / strings.HasSuffix
42
+ function go_strings_has_prefix(string s, string prefix) -> int {
43
+ int sl = strlen(s)
44
+ int pl = strlen(prefix)
45
+ if (pl > sl) { return 0 }
46
+ if (strcmp(substr(s, 0, pl), prefix) == 0) { return 1 }
47
+ return 0
48
+ }
49
+
50
+ function go_strings_has_suffix(string s, string suffix) -> int {
51
+ int sl = strlen(s)
52
+ int fl = strlen(suffix)
53
+ if (fl > sl) { return 0 }
54
+ if (strcmp(substr(s, sl - fl, fl), suffix) == 0) { return 1 }
55
+ return 0
56
+ }
57
+
58
+ // strings.ToUpper / strings.ToLower / strings.TrimSpace
59
+ function go_strings_to_upper(string s) -> string {
60
+ return upper(s)
61
+ }
62
+
63
+ function go_strings_to_lower(string s) -> string {
64
+ return lower(s)
65
+ }
66
+
67
+ function go_strings_trim_space(string s) -> string {
68
+ return trim(s)
69
+ }
70
+
71
+ // strings.Repeat
72
+ function go_strings_repeat(string s, int n) -> string {
73
+ string out = ""
74
+ while (n > 0) {
75
+ out = out + s
76
+ n = n - 1
77
+ }
78
+ return out
79
+ }
80
+
81
+ // strings.Count: 非重叠子串计数
82
+ function go_strings_count(string s, string sub) -> int {
83
+ int sl = strlen(s)
84
+ int nl = strlen(sub)
85
+ if (nl == 0) { return sl + 1 }
86
+ int total = 0
87
+ int pos = 0
88
+ while (pos <= sl) {
89
+ int at = indexof(substr(s, pos, sl), sub)
90
+ if (at < 0) { break }
91
+ total = total + 1
92
+ pos = pos + at + nl
93
+ }
94
+ return total
95
+ }
96
+
97
+ // strings.ReplaceAll
98
+ function go_strings_replace_all(string s, string oldstr, string newstr) -> string {
99
+ int sl = strlen(s)
100
+ int ol = strlen(oldstr)
101
+ if (ol == 0) { return s }
102
+ string out = ""
103
+ int pos = 0
104
+ while (pos <= sl) {
105
+ string rest = substr(s, pos, sl)
106
+ int at = indexof(rest, oldstr)
107
+ if (at < 0) { break }
108
+ out = out + substr(s, pos, at) + newstr
109
+ pos = pos + at + ol
110
+ }
111
+ out = out + substr(s, pos, sl)
112
+ return out
113
+ }
114
+
115
+ // strings.EqualFold 的 ASCII 精确版 (大小写不敏感相等)
116
+ function go_strings_equal_fold(string a, string b) -> int {
117
+ if (strcmp(upper(a), upper(b)) == 0) { return 1 }
118
+ return 0
119
+ }
120
+
121
+ // strings.Compare: <0 / 0 / >0
122
+ function go_strings_compare(string a, string b) -> int {
123
+ return strcmp(a, b)
124
+ }
125
+
126
+ // len(s): 字节长度
127
+ function go_len(string s) -> int {
128
+ return strlen(s)
129
+ }
130
+
131
+ // ==================== strconv ====================
132
+
133
+ // strconv.Itoa
134
+ function go_itoa(int v) -> string {
135
+ return int_to_str(v)
136
+ }
137
+
138
+ // strconv.Atoi (解析失败为 0, 与内建 atoi 一致)
139
+ function go_atoi(string s) -> int {
140
+ return atoi(s)
141
+ }
142
+
143
+ // strconv.FormatFloat 的默认精度替身
144
+ function go_format_float(float v) -> string {
145
+ return float_to_str(v)
146
+ }
147
+
148
+ // ==================== math ====================
149
+
150
+ // math.Abs
151
+ function go_math_abs(int x) -> int {
152
+ if (x < 0) { return -x }
153
+ return x
154
+ }
155
+
156
+ // math.Max / math.Min (整数版)
157
+ function go_math_max(int a, int b) -> int {
158
+ if (a > b) { return a }
159
+ return b
160
+ }
161
+
162
+ function go_math_min(int a, int b) -> int {
163
+ if (a < b) { return a }
164
+ return b
165
+ }
166
+
167
+ // math.Floor / math.Ceil / math.Sqrt / math.Pow
168
+ function go_math_floor(float x) -> float {
169
+ return floor(x)
170
+ }
171
+
172
+ function go_math_ceil(float x) -> float {
173
+ return ceil(x)
174
+ }
175
+
176
+ function go_math_sqrt(float x) -> float {
177
+ return sqrt(x)
178
+ }
179
+
180
+ function go_math_pow(float x, float y) -> float {
181
+ return pow(x, y)
182
+ }
183
+
184
+ // ==================== slices ====================
185
+
186
+ // slices.Index: 未找到 -1
187
+ function go_slices_index(int[] a, int n, int x) -> int {
188
+ for (int i = 0; i < n; i = i + 1) {
189
+ if (a[i] == x) { return i }
190
+ }
191
+ return -1
192
+ }
193
+
194
+ // slices.Contains
195
+ function go_slices_contains(int[] a, int n, int x) -> int {
196
+ if (go_slices_index(a, n, x) >= 0) { return 1 }
197
+ return 0
198
+ }
199
+
200
+ // slices.Max / slices.Min / slices.Sum
201
+ function go_slices_max(int[] a, int n) -> int {
202
+ if (n <= 0) { return 0 }
203
+ int m = a[0]
204
+ for (int i = 1; i < n; i = i + 1) {
205
+ if (a[i] > m) { m = a[i] }
206
+ }
207
+ return m
208
+ }
209
+
210
+ function go_slices_min(int[] a, int n) -> int {
211
+ if (n <= 0) { return 0 }
212
+ int m = a[0]
213
+ for (int i = 1; i < n; i = i + 1) {
214
+ if (a[i] < m) { m = a[i] }
215
+ }
216
+ return m
217
+ }
218
+
219
+ function go_slices_sum(int[] a, int n) -> int {
220
+ int s = 0
221
+ for (int i = 0; i < n; i = i + 1) { s = s + a[i] }
222
+ return s
223
+ }
224
+
225
+ // slices.Reverse (原地)
226
+ function go_slices_reverse(int[] a, int n) -> void {
227
+ int lo = 0
228
+ int hi = n - 1
229
+ while (lo < hi) {
230
+ int t = a[lo]
231
+ a[lo] = a[hi]
232
+ a[hi] = t
233
+ lo = lo + 1
234
+ hi = hi - 1
235
+ }
236
+ }
237
+
238
+ // ==================== os (命令行参数) ====================
239
+ // 依赖原生路径 (CLI `--` 之后传参 / AOT 产物取 os.Args[1:])
240
+
241
+ // len(os.Args)
242
+ function go_os_args_len() -> int {
243
+ return arg_count()
244
+ }
245
+
246
+ // os.Args[i] (越界为空串; Go 语义下标从 0 计 CIN 参数)
247
+ function go_os_args_get(int i) -> string {
248
+ return arg(i)
249
+ }
250
+
251
+ // ==================== strings 扩展 ====================
252
+
253
+ // strings.LastIndex: 末现下标 (未找到 -1)
254
+ function go_strings_last_index(string s, string sub) -> int {
255
+ int sl = strlen(s)
256
+ int nl = strlen(sub)
257
+ if (nl == 0) { return sl }
258
+ int pos = sl - nl
259
+ while (pos >= 0) {
260
+ if (strcmp(substr(s, pos, nl), sub) == 0) { return pos }
261
+ pos = pos - 1
262
+ }
263
+ return -1
264
+ }
265
+
266
+ // strings.IndexAny: chars 中任一字符在 s 的首现下标 (未找到 -1)
267
+ function go_strings_index_any(string s, string chars) -> int {
268
+ int n = strlen(s)
269
+ for (int i = 0; i < n; i = i + 1) {
270
+ if (indexof(chars, substr(s, i, 1)) >= 0) { return i }
271
+ }
272
+ return -1
273
+ }
274
+
275
+ // strings.TrimLeft: 去掉前导的 cutset 内字符 (空 cutset 原样返回)
276
+ function go_strings_trim_left(string s, string cutset) -> string {
277
+ if (strlen(cutset) == 0) { return s }
278
+ int n = strlen(s)
279
+ int i = 0
280
+ while (i < n) {
281
+ if (indexof(cutset, substr(s, i, 1)) < 0) { break }
282
+ i = i + 1
283
+ }
284
+ return substr(s, i, n)
285
+ }
286
+
287
+ // strings.TrimRight: 去掉尾部的 cutset 内字符 (空 cutset 原样返回)
288
+ function go_strings_trim_right(string s, string cutset) -> string {
289
+ if (strlen(cutset) == 0) { return s }
290
+ int i = strlen(s) - 1
291
+ while (i >= 0) {
292
+ if (indexof(cutset, substr(s, i, 1)) < 0) { break }
293
+ i = i - 1
294
+ }
295
+ return substr(s, 0, i + 1)
296
+ }
297
+
298
+ // strings.TrimPrefix: 有前缀则去掉 (无则原样)
299
+ function go_strings_trim_prefix(string s, string prefix) -> string {
300
+ if (go_strings_has_prefix(s, prefix) == 1) {
301
+ return substr(s, strlen(prefix), strlen(s))
302
+ }
303
+ return s
304
+ }
305
+
306
+ // strings.TrimSuffix: 有后缀则去掉 (无则原样)
307
+ function go_strings_trim_suffix(string s, string suffix) -> string {
308
+ if (go_strings_has_suffix(s, suffix) == 1) {
309
+ return substr(s, 0, strlen(s) - strlen(suffix))
310
+ }
311
+ return s
312
+ }
313
+
314
+ // ==================== strconv 扩展 ====================
315
+
316
+ // strconv.FormatInt: base 2..36 (越界按 10); 负数带 - 前缀。
317
+ // int64 最小值取负溢出的极端场景不保证 (CIN int 为 64 位补码)
318
+ function go_format_int(int v, int base) -> string {
319
+ if (base < 2 || base > 36) { base = 10 }
320
+ if (v == 0) { return "0" }
321
+ string digits = "0123456789abcdefghijklmnopqrstuvwxyz"
322
+ int neg = 0
323
+ int x = v
324
+ if (x < 0) { neg = 1 }
325
+ string out = ""
326
+ while (x != 0) {
327
+ int d = x % base
328
+ if (d < 0) { d = -d }
329
+ out = substr(digits, d, 1) + out
330
+ x = idiv(x, base)
331
+ }
332
+ if (neg == 1) { out = "-" + out }
333
+ return out
334
+ }
335
+
336
+ // strconv.ParseInt 简化版: 允许可选 - 前缀, 数字 0-9 / a-z / A-Z,
337
+ // base 2..36 (越界按 10); 非法字符停在非法处 (与 conv.cin 风格一致, 非全有全无)
338
+ function go_parse_int(string s, int base) -> int {
339
+ if (base < 2 || base > 36) { base = 10 }
340
+ int n = strlen(s)
341
+ int i = 0
342
+ int neg = 0
343
+ if (i < n && s[i] == 45) { neg = 1; i = i + 1 } // '-'
344
+ int v = 0
345
+ while (i < n) {
346
+ int c = s[i]
347
+ int d = -1
348
+ if (c >= 48 && c <= 57) {
349
+ d = c - 48
350
+ } else if (c >= 97 && c <= 122) {
351
+ d = c - 87
352
+ } else if (c >= 65 && c <= 90) {
353
+ d = c - 55
354
+ }
355
+ if (d < 0 || d >= base) { break }
356
+ v = v * base + d
357
+ i = i + 1
358
+ }
359
+ if (neg == 1) { v = -v }
360
+ return v
361
+ }
362
+
363
+ // ==================== math 扩展 ====================
364
+
365
+ // math.Round: 半值远离零 (与内建 round 的 floor(x+0.5) 在负半值上不同:
366
+ // go_math_round(-2.5) = -3, round(-2.5) = -2)
367
+ function go_math_round(float x) -> float {
368
+ if (x >= 0.0) { return floor(x + 0.5) }
369
+ return ceil(x - 0.5)
370
+ }
371
+
372
+ // math.Trunc: 向零截断
373
+ function go_math_trunc(float x) -> float {
374
+ if (x >= 0.0) { return floor(x) }
375
+ return ceil(x)
376
+ }
377
+
378
+ // ==================== slices 扩展 ====================
379
+
380
+ // slices.LastIndex: 末现下标 (未找到 -1)
381
+ function go_slices_last_index(int[] a, int n, int x) -> int {
382
+ int i = n - 1
383
+ while (i >= 0) {
384
+ if (a[i] == x) { return i }
385
+ i = i - 1
386
+ }
387
+ return -1
388
+ }
389
+
390
+ // slices.Equal: 前 n 个元素逐一相等
391
+ function go_slices_equal(int[] a, int[] b, int n) -> int {
392
+ for (int i = 0; i < n; i = i + 1) {
393
+ if (a[i] != b[i]) { return 0 }
394
+ }
395
+ return 1
396
+ }
397
+
398
+ // slices.Clone 的定长替身: 拷入调用方提供的 dst (CIN 无动态数组), 返回 n
399
+ function go_slices_clone(int[] dst, int[] src, int n) -> int {
400
+ for (int i = 0; i < n; i = i + 1) { dst[i] = src[i] }
401
+ return n
402
+ }
403
+
404
+ // slices.Sort (升序; CIN 无比较器参数, 固定升序)
405
+ function go_slices_sort(int[] a, int n) -> void {
406
+ for (int i = 0; i < n - 1; i = i + 1) {
407
+ for (int j = 0; j < n - 1 - i; j = j + 1) {
408
+ if (a[j] > a[j + 1]) {
409
+ int t = a[j]
410
+ a[j] = a[j + 1]
411
+ a[j + 1] = t
412
+ }
413
+ }
414
+ }
415
+ }
@@ -0,0 +1,10 @@
1
+ # 由 script/sync_stdlib_packages.py 生成,请勿手工编辑。
2
+ [package]
3
+ name = "graph"
4
+ version = "7.22.10"
5
+ description = "Code CIN 官方标准库: 定长图"
6
+ license = "MIT"
7
+ authors = ["ByUsi Studio"]
8
+ entry = "src/graph.cin"
9
+ repo = "https://gitee.com/codecin/internal-libraries"
10
+ keywords = ["codecin", "stdlib", "graph"]