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.
- codecin/__init__.py +27 -0
- codecin/aot.py +1057 -0
- codecin/assembler.py +619 -0
- codecin/cbackend.py +3024 -0
- codecin/cin.py +4265 -0
- codecin/cli.py +670 -0
- codecin/codecin_native.dll +0 -0
- codecin/config.py +50 -0
- codecin/console.py +183 -0
- codecin/cpu.py +312 -0
- codecin/crom.py +449 -0
- codecin/cvm.py +708 -0
- codecin/disasm.py +149 -0
- codecin/environment.py +176 -0
- codecin/errors.py +54 -0
- codecin/isa.py +560 -0
- codecin/lib/array/pic.toml +10 -0
- codecin/lib/array/src/array.cin +103 -0
- codecin/lib/bigint/pic.toml +10 -0
- codecin/lib/bigint/src/bigint.cin +589 -0
- codecin/lib/bits/pic.toml +10 -0
- codecin/lib/bits/src/bits.cin +143 -0
- codecin/lib/bitset/pic.toml +10 -0
- codecin/lib/bitset/src/bitset.cin +374 -0
- codecin/lib/codec/pic.toml +10 -0
- codecin/lib/codec/src/codec.cin +563 -0
- codecin/lib/combin/pic.toml +10 -0
- codecin/lib/combin/src/combin.cin +414 -0
- codecin/lib/conv/pic.toml +10 -0
- codecin/lib/conv/src/conv.cin +151 -0
- codecin/lib/cppstd/pic.toml +10 -0
- codecin/lib/cppstd/src/cppstd.cin +418 -0
- codecin/lib/cstd/pic.toml +10 -0
- codecin/lib/cstd/src/cstd.cin +424 -0
- codecin/lib/csv/pic.toml +10 -0
- codecin/lib/csv/src/csv.cin +405 -0
- codecin/lib/dp/pic.toml +10 -0
- codecin/lib/dp/src/dp.cin +325 -0
- codecin/lib/ffi/pic.toml +10 -0
- codecin/lib/ffi/src/ffi.cin +163 -0
- codecin/lib/fmt/pic.toml +10 -0
- codecin/lib/fmt/src/fmt.cin +325 -0
- codecin/lib/frac/pic.toml +10 -0
- codecin/lib/frac/src/frac.cin +252 -0
- codecin/lib/gostd/pic.toml +10 -0
- codecin/lib/gostd/src/gostd.cin +415 -0
- codecin/lib/graph/pic.toml +10 -0
- codecin/lib/graph/src/graph.cin +367 -0
- codecin/lib/gui/pic.toml +10 -0
- codecin/lib/gui/src/gui.cin +218 -0
- codecin/lib/hash/pic.toml +10 -0
- codecin/lib/hash/src/hash.cin +67 -0
- codecin/lib/heap/pic.toml +10 -0
- codecin/lib/heap/src/heap.cin +199 -0
- codecin/lib/io/pic.toml +10 -0
- codecin/lib/io/src/io.cin +141 -0
- codecin/lib/json/pic.toml +10 -0
- codecin/lib/json/src/json.cin +84 -0
- codecin/lib/key/pic.toml +10 -0
- codecin/lib/key/src/key.cin +78 -0
- codecin/lib/math/pic.toml +10 -0
- codecin/lib/math/src/math.cin +50 -0
- codecin/lib/matrix/pic.toml +10 -0
- codecin/lib/matrix/src/matrix.cin +155 -0
- codecin/lib/net/pic.toml +10 -0
- codecin/lib/net/src/net.cin +171 -0
- codecin/lib/path/pic.toml +10 -0
- codecin/lib/path/src/path.cin +372 -0
- codecin/lib/queue/pic.toml +10 -0
- codecin/lib/queue/src/queue.cin +112 -0
- codecin/lib/rand/pic.toml +10 -0
- codecin/lib/rand/src/rand.cin +46 -0
- codecin/lib/set/pic.toml +10 -0
- codecin/lib/set/src/set.cin +269 -0
- codecin/lib/sort/pic.toml +10 -0
- codecin/lib/sort/src/sort.cin +93 -0
- codecin/lib/stat/pic.toml +10 -0
- codecin/lib/stat/src/stat.cin +138 -0
- codecin/lib/str/pic.toml +10 -0
- codecin/lib/str/src/str.cin +54 -0
- codecin/lib/termux/pic.toml +10 -0
- codecin/lib/termux/src/termux.cin +118 -0
- codecin/lib/test/pic.toml +10 -0
- codecin/lib/test/src/test.cin +74 -0
- codecin/lib/text/pic.toml +10 -0
- codecin/lib/text/src/text.cin +323 -0
- codecin/lib/time/pic.toml +10 -0
- codecin/lib/time/src/time.cin +54 -0
- codecin/lib/token/pic.toml +10 -0
- codecin/lib/token/src/token.cin +183 -0
- codecin/lib/tree/pic.toml +10 -0
- codecin/lib/tree/src/tree.cin +256 -0
- codecin/lib/unionfind/pic.toml +10 -0
- codecin/lib/unionfind/src/unionfind.cin +115 -0
- codecin/lib/validate/pic.toml +10 -0
- codecin/lib/validate/src/validate.cin +148 -0
- codecin/lib/vec/pic.toml +10 -0
- codecin/lib/vec/src/vec.cin +88 -0
- codecin/logger.py +145 -0
- codecin/memory.py +306 -0
- codecin/mkn.py +916 -0
- codecin/native/aot/aot.go +114 -0
- codecin/native/aot/stub_main.go.txt +23 -0
- codecin/native/build.ps1 +33 -0
- codecin/native/build.sh +48 -0
- codecin/native/cmd/cincc/main.go +66 -0
- codecin/native/compiler/codegen.go +2238 -0
- codecin/native/compiler/compile_test.go +1069 -0
- codecin/native/compiler/parser.go +1331 -0
- codecin/native/compiler/syscalls.go +166 -0
- codecin/native/compiler/tokenizer.go +394 -0
- codecin/native/compiler/types.go +217 -0
- codecin/native/engine/args.go +37 -0
- codecin/native/engine/audio.go +402 -0
- codecin/native/engine/audio_other.go +105 -0
- codecin/native/engine/audio_test.go +279 -0
- codecin/native/engine/audio_windows.go +190 -0
- codecin/native/engine/canvas.go +271 -0
- codecin/native/engine/console_other.go +9 -0
- codecin/native/engine/console_windows.go +43 -0
- codecin/native/engine/crom.go +86 -0
- codecin/native/engine/encode.go +93 -0
- codecin/native/engine/engine_test.go +198 -0
- codecin/native/engine/ffi_nocgo.go +20 -0
- codecin/native/engine/ffi_registry.go +69 -0
- codecin/native/engine/ffi_unix.go +109 -0
- codecin/native/engine/ffi_windows.go +117 -0
- codecin/native/engine/gui.go +209 -0
- codecin/native/engine/gui_stub.go +13 -0
- codecin/native/engine/gui_test.go +148 -0
- codecin/native/engine/gui_windows.go +604 -0
- codecin/native/engine/gui_x11.go +723 -0
- codecin/native/engine/host_test.go +139 -0
- codecin/native/engine/hostcrypto.go +30 -0
- codecin/native/engine/hostdesktop.go +173 -0
- codecin/native/engine/hostnet.go +127 -0
- codecin/native/engine/isa_gen.go +689 -0
- codecin/native/engine/keyboard.go +432 -0
- codecin/native/engine/keyboard_other.go +94 -0
- codecin/native/engine/keyboard_stub.go +17 -0
- codecin/native/engine/keyboard_termios_darwin.go +9 -0
- codecin/native/engine/keyboard_termios_linux.go +9 -0
- codecin/native/engine/keyboard_test.go +246 -0
- codecin/native/engine/keyboard_windows.go +208 -0
- codecin/native/engine/keyboard_windows_test.go +123 -0
- codecin/native/engine/lineedit.go +262 -0
- codecin/native/engine/lineedit_test.go +105 -0
- codecin/native/engine/lineint_unix.go +17 -0
- codecin/native/engine/lineint_windows.go +19 -0
- codecin/native/engine/mem_other.go +37 -0
- codecin/native/engine/mem_windows.go +33 -0
- codecin/native/engine/native.go +640 -0
- codecin/native/engine/netsock.go +321 -0
- codecin/native/engine/ops_ext.go +515 -0
- codecin/native/engine/stdin.go +72 -0
- codecin/native/engine/stdin_other.go +9 -0
- codecin/native/engine/stdin_windows.go +60 -0
- codecin/native/engine/system.go +313 -0
- codecin/native/engine/termux.go +180 -0
- codecin/native/engine/version_gen.go +7 -0
- codecin/native/engine/vkb_darwin.go +62 -0
- codecin/native/engine/vkb_linux.go +95 -0
- codecin/native/engine/vkb_stub.go +11 -0
- codecin/native/engine/vm.go +1677 -0
- codecin/native/go.mod +3 -0
- codecin/native/ir/ir.go +48 -0
- codecin/native/main.go +448 -0
- codecin/native/mc/aarch64.go +165 -0
- codecin/native/mc/aarch64_test.go +30 -0
- codecin/native/mc/elf.go +88 -0
- codecin/native/mc/print_test.go +52 -0
- codecin/native/mc/x86_64.go +1262 -0
- codecin/native/mc/x86_64_test.go +102 -0
- codecin/native.py +432 -0
- codecin/native_codegen.py +987 -0
- codecin/nativegen.py +786 -0
- codecin/object.py +539 -0
- codecin/optimizer.py +236 -0
- codecin/packaging/__init__.py +46 -0
- codecin/packaging/archive.py +177 -0
- codecin/packaging/model.py +519 -0
- codecin/packaging/spec.py +193 -0
- codecin/packaging/store.py +372 -0
- codecin/packaging/toml.py +541 -0
- codecin/packaging/vcs.py +215 -0
- codecin/pic.py +1917 -0
- codecin/pic_api.py +374 -0
- codecin/pic_login.py +519 -0
- codecin/pic_registry.py +515 -0
- codecin/registers.py +130 -0
- codecin/sdgcc.py +493 -0
- codecin/stats.py +230 -0
- codecin/stdlib.py +138 -0
- codecin/toolchain.py +396 -0
- codecin/toolkit.py +26 -0
- codecin/version.py +260 -0
- codecin-7.22.10.dist-info/METADATA +1077 -0
- codecin-7.22.10.dist-info/RECORD +202 -0
- codecin-7.22.10.dist-info/WHEEL +5 -0
- codecin-7.22.10.dist-info/entry_points.txt +5 -0
- codecin-7.22.10.dist-info/licenses/LICENSE +7 -0
- codecin-7.22.10.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
// Code CIN 官方标准库: C++ 标准库 (STL) 兼容层 (cppstd)
|
|
2
|
+
// 用法: import "cppstd.cin"
|
|
3
|
+
//
|
|
4
|
+
// 以 std:: 命名习惯提供 std::string / std::vector / std::stack /
|
|
5
|
+
// std::queue 的常用方法。CIN 没有模板与引用包装, 容器以
|
|
6
|
+
// "数组 + 长度游标" 表达: 数组是引用传递, push/pop 返回**新的长度**,
|
|
7
|
+
// 调用方把它存回自己的游标变量, 例如:
|
|
8
|
+
// int v[64]
|
|
9
|
+
// int n = 0
|
|
10
|
+
// n = stl_vec_push_back(v, n, 42)
|
|
11
|
+
// 注意: push 前调用方需自行保证数组容量 (CIN 无动态扩容)。
|
|
12
|
+
|
|
13
|
+
// ==================== std::string ====================
|
|
14
|
+
|
|
15
|
+
// size() / length()
|
|
16
|
+
function stl_str_size(string s) -> int {
|
|
17
|
+
return strlen(s)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function stl_str_length(string s) -> int {
|
|
21
|
+
return strlen(s)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// empty()
|
|
25
|
+
function stl_str_empty(string s) -> int {
|
|
26
|
+
if (strlen(s) == 0) { return 1 }
|
|
27
|
+
return 0
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// find(): 首现下标 (npos 以 -1 表示)
|
|
31
|
+
function stl_str_find(string s, string sub) -> int {
|
|
32
|
+
return indexof(s, sub)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// rfind(): 末现下标 (npos 以 -1 表示)
|
|
36
|
+
function stl_str_rfind(string s, string sub) -> int {
|
|
37
|
+
int sl = strlen(s)
|
|
38
|
+
int nl = strlen(sub)
|
|
39
|
+
if (nl == 0) { return sl }
|
|
40
|
+
int pos = sl - nl
|
|
41
|
+
while (pos >= 0) {
|
|
42
|
+
if (strcmp(substr(s, pos, nl), sub) == 0) { return pos }
|
|
43
|
+
pos = pos - 1
|
|
44
|
+
}
|
|
45
|
+
return -1
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// substr(pos, len)
|
|
49
|
+
function stl_str_substr(string s, int pos, int len) -> string {
|
|
50
|
+
return substr(s, pos, len)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// operator+ / append()
|
|
54
|
+
function stl_str_append(string a, string b) -> string {
|
|
55
|
+
return a + b
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// compare(): <0 / 0 / >0
|
|
59
|
+
function stl_str_compare(string a, string b) -> int {
|
|
60
|
+
return strcmp(a, b)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// c_str(): CIN 字符串本身就是宿主字符串, 恒等返回
|
|
64
|
+
function stl_str_c_str(string s) -> string {
|
|
65
|
+
return s
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// std::to_string
|
|
69
|
+
function stl_to_string(int v) -> string {
|
|
70
|
+
return int_to_str(v)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// ==================== std::vector<int> ====================
|
|
74
|
+
|
|
75
|
+
// push_back(x): 返回新长度
|
|
76
|
+
function stl_vec_push_back(int[] v, int len, int x) -> int {
|
|
77
|
+
v[len] = x
|
|
78
|
+
return len + 1
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// pop_back(): 返回新长度 (空容器不变)
|
|
82
|
+
function stl_vec_pop_back(int len) -> int {
|
|
83
|
+
if (len > 0) { return len - 1 }
|
|
84
|
+
return 0
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// back() / front(): 空容器返回 0
|
|
88
|
+
function stl_vec_back(int[] v, int len) -> int {
|
|
89
|
+
if (len > 0) { return v[len - 1] }
|
|
90
|
+
return 0
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function stl_vec_front(int[] v, int len) -> int {
|
|
94
|
+
if (len > 0) { return v[0] }
|
|
95
|
+
return 0
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// size() / empty() / clear()
|
|
99
|
+
function stl_vec_size(int len) -> int {
|
|
100
|
+
return len
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function stl_vec_empty(int len) -> int {
|
|
104
|
+
if (len == 0) { return 1 }
|
|
105
|
+
return 0
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function stl_vec_clear() -> int {
|
|
109
|
+
return 0
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// at(i): 带边界检查 (越界返回 0; C++ 此处抛 std::out_of_range)
|
|
113
|
+
function stl_vec_at(int[] v, int len, int i) -> int {
|
|
114
|
+
if (i >= 0 && i < len) { return v[i] }
|
|
115
|
+
return 0
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// 原地反转
|
|
119
|
+
function stl_vec_reverse(int[] v, int len) -> void {
|
|
120
|
+
int lo = 0
|
|
121
|
+
int hi = len - 1
|
|
122
|
+
while (lo < hi) {
|
|
123
|
+
int t = v[lo]
|
|
124
|
+
v[lo] = v[hi]
|
|
125
|
+
v[hi] = t
|
|
126
|
+
lo = lo + 1
|
|
127
|
+
hi = hi - 1
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// 填充
|
|
132
|
+
function stl_vec_fill(int[] v, int len, int x) -> void {
|
|
133
|
+
for (int i = 0; i < len; i = i + 1) { v[i] = x }
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// 求和 / 最大 / 最小
|
|
137
|
+
function stl_vec_sum(int[] v, int len) -> int {
|
|
138
|
+
int s = 0
|
|
139
|
+
for (int i = 0; i < len; i = i + 1) { s = s + v[i] }
|
|
140
|
+
return s
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function stl_vec_max(int[] v, int len) -> int {
|
|
144
|
+
if (len <= 0) { return 0 }
|
|
145
|
+
int m = v[0]
|
|
146
|
+
for (int i = 1; i < len; i = i + 1) {
|
|
147
|
+
if (v[i] > m) { m = v[i] }
|
|
148
|
+
}
|
|
149
|
+
return m
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function stl_vec_min(int[] v, int len) -> int {
|
|
153
|
+
if (len <= 0) { return 0 }
|
|
154
|
+
int m = v[0]
|
|
155
|
+
for (int i = 1; i < len; i = i + 1) {
|
|
156
|
+
if (v[i] < m) { m = v[i] }
|
|
157
|
+
}
|
|
158
|
+
return m
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// ==================== std::stack<int> ====================
|
|
162
|
+
// top 游标语义: 0 = 空, 栈顶是 s[top - 1]
|
|
163
|
+
|
|
164
|
+
// push(x): 返回新 top
|
|
165
|
+
function stl_stack_push(int[] s, int top, int x) -> int {
|
|
166
|
+
s[top] = x
|
|
167
|
+
return top + 1
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// pop(): 返回新 top (空栈不变)
|
|
171
|
+
function stl_stack_pop(int top) -> int {
|
|
172
|
+
if (top > 0) { return top - 1 }
|
|
173
|
+
return 0
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// top(): 空栈返回 0
|
|
177
|
+
function stl_stack_top(int[] s, int top) -> int {
|
|
178
|
+
if (top > 0) { return s[top - 1] }
|
|
179
|
+
return 0
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// size() / empty()
|
|
183
|
+
function stl_stack_size(int top) -> int {
|
|
184
|
+
return top
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function stl_stack_empty(int top) -> int {
|
|
188
|
+
if (top == 0) { return 1 }
|
|
189
|
+
return 0
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// ==================== std::queue<int> ====================
|
|
193
|
+
// 非循环数组队列: head 指向队首, tail 指向下一个写入位 (head <= tail)
|
|
194
|
+
|
|
195
|
+
// push(x): 返回新 tail
|
|
196
|
+
function stl_queue_push(int[] q, int tail, int x) -> int {
|
|
197
|
+
q[tail] = x
|
|
198
|
+
return tail + 1
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// pop(): 返回新 head (调用方保证非空)
|
|
202
|
+
function stl_queue_pop(int head) -> int {
|
|
203
|
+
return head + 1
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// front() / back()
|
|
207
|
+
function stl_queue_front(int[] q, int head) -> int {
|
|
208
|
+
return q[head]
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function stl_queue_back(int[] q, int tail) -> int {
|
|
212
|
+
if (tail > 0) { return q[tail - 1] }
|
|
213
|
+
return 0
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// empty() / size()
|
|
217
|
+
function stl_queue_empty(int head, int tail) -> int {
|
|
218
|
+
if (head >= tail) { return 1 }
|
|
219
|
+
return 0
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function stl_queue_size(int head, int tail) -> int {
|
|
223
|
+
return tail - head
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// ==================== <utility> / <algorithm> ====================
|
|
227
|
+
|
|
228
|
+
// std::max / std::min / std::abs
|
|
229
|
+
function stl_max(int a, int b) -> int {
|
|
230
|
+
if (a > b) { return a }
|
|
231
|
+
return b
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function stl_min(int a, int b) -> int {
|
|
235
|
+
if (a < b) { return a }
|
|
236
|
+
return b
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function stl_abs(int x) -> int {
|
|
240
|
+
if (x < 0) { return -x }
|
|
241
|
+
return x
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// std::swap 的数组元素版
|
|
245
|
+
function stl_swap(int[] v, int i, int j) -> void {
|
|
246
|
+
int t = v[i]
|
|
247
|
+
v[i] = v[j]
|
|
248
|
+
v[j] = t
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// std::sort (升序; CIN 无函数指针, 固定升序)
|
|
252
|
+
function stl_sort(int[] v, int len) -> void {
|
|
253
|
+
for (int i = 0; i < len - 1; i = i + 1) {
|
|
254
|
+
for (int j = 0; j < len - 1 - i; j = j + 1) {
|
|
255
|
+
if (v[j] > v[j + 1]) {
|
|
256
|
+
int t = v[j]
|
|
257
|
+
v[j] = v[j + 1]
|
|
258
|
+
v[j + 1] = t
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// ==================== std::string 扩展 ====================
|
|
265
|
+
|
|
266
|
+
// starts_with / ends_with (C++20)
|
|
267
|
+
function stl_str_starts_with(string s, string prefix) -> int {
|
|
268
|
+
int pl = strlen(prefix)
|
|
269
|
+
if (pl == 0) { return 1 }
|
|
270
|
+
if (pl > strlen(s)) { return 0 }
|
|
271
|
+
if (strcmp(substr(s, 0, pl), prefix) == 0) { return 1 }
|
|
272
|
+
return 0
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function stl_str_ends_with(string s, string suffix) -> int {
|
|
276
|
+
int fl = strlen(suffix)
|
|
277
|
+
int sl = strlen(s)
|
|
278
|
+
if (fl == 0) { return 1 }
|
|
279
|
+
if (fl > sl) { return 0 }
|
|
280
|
+
if (strcmp(substr(s, sl - fl, fl), suffix) == 0) { return 1 }
|
|
281
|
+
return 0
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// find_first_of: chars 中任一字符在 s 的首现下标 (npos 以 -1 表示)
|
|
285
|
+
function stl_str_find_first_of(string s, string chars) -> int {
|
|
286
|
+
int n = strlen(s)
|
|
287
|
+
for (int i = 0; i < n; i = i + 1) {
|
|
288
|
+
if (indexof(chars, substr(s, i, 1)) >= 0) { return i }
|
|
289
|
+
}
|
|
290
|
+
return -1
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// find_last_of: chars 中任一字符在 s 的末现下标 (npos 以 -1 表示)
|
|
294
|
+
function stl_str_find_last_of(string s, string chars) -> int {
|
|
295
|
+
int i = strlen(s) - 1
|
|
296
|
+
while (i >= 0) {
|
|
297
|
+
if (indexof(chars, substr(s, i, 1)) >= 0) { return i }
|
|
298
|
+
i = i - 1
|
|
299
|
+
}
|
|
300
|
+
return -1
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// at(i): 字符码 (越界返回 0; C++ 此处抛 std::out_of_range)
|
|
304
|
+
function stl_str_at(string s, int i) -> int {
|
|
305
|
+
if (i >= 0 && i < strlen(s)) { return s[i] }
|
|
306
|
+
return 0
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// front() / back(): 首末字符码 (空串返回 0)
|
|
310
|
+
function stl_str_front(string s) -> int {
|
|
311
|
+
if (strlen(s) > 0) { return s[0] }
|
|
312
|
+
return 0
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function stl_str_back(string s) -> int {
|
|
316
|
+
int n = strlen(s)
|
|
317
|
+
if (n > 0) { return s[n - 1] }
|
|
318
|
+
return 0
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// insert(pos, sub): 在下标 pos 前插入 (pos 越界时裁剪到 0 / 末尾)
|
|
322
|
+
function stl_str_insert(string s, int pos, string sub) -> string {
|
|
323
|
+
int n = strlen(s)
|
|
324
|
+
if (pos < 0) { pos = 0 }
|
|
325
|
+
if (pos > n) { pos = n }
|
|
326
|
+
return substr(s, 0, pos) + sub + substr(s, pos, n)
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// erase(pos, len): 删除 [pos, pos+len) (越界裁剪; len<0 视为 0)
|
|
330
|
+
function stl_str_erase(string s, int pos, int len) -> string {
|
|
331
|
+
int n = strlen(s)
|
|
332
|
+
if (pos < 0) { pos = 0 }
|
|
333
|
+
if (pos >= n) { return s }
|
|
334
|
+
if (len < 0) { len = 0 }
|
|
335
|
+
return substr(s, 0, pos) + substr(s, pos + len, n)
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// replace(pos, len, sub): 把 [pos, pos+len) 替换为 sub (越界裁剪)
|
|
339
|
+
function stl_str_replace(string s, int pos, int len, string sub) -> string {
|
|
340
|
+
int n = strlen(s)
|
|
341
|
+
if (pos < 0) { pos = 0 }
|
|
342
|
+
if (pos >= n) { return s }
|
|
343
|
+
if (len < 0) { len = 0 }
|
|
344
|
+
return substr(s, 0, pos) + sub + substr(s, pos + len, n)
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// ==================== std::vector<int> 扩展 ====================
|
|
348
|
+
|
|
349
|
+
// 查找首个等于 x 的下标 (无则 -1)
|
|
350
|
+
function stl_vec_find(int[] v, int len, int x) -> int {
|
|
351
|
+
for (int i = 0; i < len; i = i + 1) {
|
|
352
|
+
if (v[i] == x) { return i }
|
|
353
|
+
}
|
|
354
|
+
return -1
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// 统计等于 x 的元素个数
|
|
358
|
+
function stl_vec_count(int[] v, int len, int x) -> int {
|
|
359
|
+
int total = 0
|
|
360
|
+
for (int i = 0; i < len; i = i + 1) {
|
|
361
|
+
if (v[i] == x) { total = total + 1 }
|
|
362
|
+
}
|
|
363
|
+
return total
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// insert(i, x): 在下标 i 处插入, 整体后移 (调用方保证 len < 容量);
|
|
367
|
+
// 返回新长度; i 越界时视为尾部追加
|
|
368
|
+
function stl_vec_insert(int[] v, int len, int i, int x) -> int {
|
|
369
|
+
if (i < 0 || i > len) { i = len }
|
|
370
|
+
int j = len
|
|
371
|
+
while (j > i) {
|
|
372
|
+
v[j] = v[j - 1]
|
|
373
|
+
j = j - 1
|
|
374
|
+
}
|
|
375
|
+
v[i] = x
|
|
376
|
+
return len + 1
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// erase(i): 删除下标 i, 整体前移; 返回新长度 (i 越界时长度不变)
|
|
380
|
+
function stl_vec_erase(int[] v, int len, int i) -> int {
|
|
381
|
+
if (i < 0 || i >= len) { return len }
|
|
382
|
+
while (i < len - 1) {
|
|
383
|
+
v[i] = v[i + 1]
|
|
384
|
+
i = i + 1
|
|
385
|
+
}
|
|
386
|
+
return len - 1
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// ==================== <algorithm> 扩展 ====================
|
|
390
|
+
|
|
391
|
+
// std::sort 降序 (CIN 无函数指针, 固定降序)
|
|
392
|
+
function stl_sort_desc(int[] v, int len) -> void {
|
|
393
|
+
for (int i = 0; i < len - 1; i = i + 1) {
|
|
394
|
+
for (int j = 0; j < len - 1 - i; j = j + 1) {
|
|
395
|
+
if (v[j] < v[j + 1]) {
|
|
396
|
+
int t = v[j]
|
|
397
|
+
v[j] = v[j + 1]
|
|
398
|
+
v[j + 1] = t
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// std::find / std::count
|
|
405
|
+
function stl_find(int[] v, int len, int x) -> int {
|
|
406
|
+
return stl_vec_find(v, len, x)
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
function stl_count(int[] v, int len, int x) -> int {
|
|
410
|
+
return stl_vec_count(v, len, x)
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// std::clamp (C++17): 把 x 限制到 [lo, hi]
|
|
414
|
+
function stl_clamp(int x, int lo, int hi) -> int {
|
|
415
|
+
if (x < lo) { return lo }
|
|
416
|
+
if (x > hi) { return hi }
|
|
417
|
+
return x
|
|
418
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# 由 script/sync_stdlib_packages.py 生成,请勿手工编辑。
|
|
2
|
+
[package]
|
|
3
|
+
name = "cstd"
|
|
4
|
+
version = "7.22.10"
|
|
5
|
+
description = "Code CIN 官方标准库: C 语言兼容层"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
authors = ["ByUsi Studio"]
|
|
8
|
+
entry = "src/cstd.cin"
|
|
9
|
+
repo = "https://gitee.com/codecin/internal-libraries"
|
|
10
|
+
keywords = ["codecin", "stdlib", "cstd"]
|