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,424 @@
|
|
|
1
|
+
// Code CIN 官方标准库: C 语言兼容层 (cstd)
|
|
2
|
+
// 用法: import "cstd.cin"
|
|
3
|
+
//
|
|
4
|
+
// 语义对齐 <ctype.h> / <string.h> / <stdlib.h> / <math.h> / <stdio.h>,
|
|
5
|
+
// 让 C 程序员以惯用的名字与约定操作 CIN 的内置类型。类型对应:
|
|
6
|
+
// C int/size_t/ssize_t -> int C char -> int (字符码 0..127)
|
|
7
|
+
// C char* / const char* -> string C float/double -> float
|
|
8
|
+
// C bool -> int (0/1) C NULL -> 0 / C EOF -> -1
|
|
9
|
+
// 差异: CIN 字符串是堆字符串且无裸指针, 因此 "写入 dst" 类 API 返回新串、
|
|
10
|
+
// strchr 返回下标 (C 返回指针); 数组一律以引用传递并显式带长度。
|
|
11
|
+
// 字符码可直接用字符字面量传入: libc_isupper('A')、libc_tolower('Q') 等。
|
|
12
|
+
|
|
13
|
+
// ==================== <ctype.h> ====================
|
|
14
|
+
|
|
15
|
+
// isdigit: '0'..'9' (48..57)
|
|
16
|
+
function libc_isdigit(int ch) -> int {
|
|
17
|
+
if (ch >= 48 && ch <= 57) { return 1 }
|
|
18
|
+
return 0
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// islower: 'a'..'z' (97..122)
|
|
22
|
+
function libc_islower(int ch) -> int {
|
|
23
|
+
if (ch >= 97 && ch <= 122) { return 1 }
|
|
24
|
+
return 0
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// isupper: 'A'..'Z' (65..90)
|
|
28
|
+
function libc_isupper(int ch) -> int {
|
|
29
|
+
if (ch >= 65 && ch <= 90) { return 1 }
|
|
30
|
+
return 0
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// isalpha
|
|
34
|
+
function libc_isalpha(int ch) -> int {
|
|
35
|
+
if (libc_islower(ch) == 1 || libc_isupper(ch) == 1) { return 1 }
|
|
36
|
+
return 0
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// isalnum
|
|
40
|
+
function libc_isalnum(int ch) -> int {
|
|
41
|
+
if (libc_isdigit(ch) == 1 || libc_isalpha(ch) == 1) { return 1 }
|
|
42
|
+
return 0
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// isspace: ' ' 与 \t \n \v \f \r (9..13)
|
|
46
|
+
function libc_isspace(int ch) -> int {
|
|
47
|
+
if (ch == 32) { return 1 }
|
|
48
|
+
if (ch >= 9 && ch <= 13) { return 1 }
|
|
49
|
+
return 0
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// isprint: 可打印 ASCII (32..126)
|
|
53
|
+
function libc_isprint(int ch) -> int {
|
|
54
|
+
if (ch >= 32 && ch <= 126) { return 1 }
|
|
55
|
+
return 0
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// isxdigit: 十六进制数字
|
|
59
|
+
function libc_isxdigit(int ch) -> int {
|
|
60
|
+
if (libc_isdigit(ch) == 1) { return 1 }
|
|
61
|
+
if (ch >= 65 && ch <= 70) { return 1 }
|
|
62
|
+
if (ch >= 97 && ch <= 102) { return 1 }
|
|
63
|
+
return 0
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// toupper
|
|
67
|
+
function libc_toupper(int ch) -> int {
|
|
68
|
+
if (libc_islower(ch) == 1) { return ch - 32 }
|
|
69
|
+
return ch
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// tolower
|
|
73
|
+
function libc_tolower(int ch) -> int {
|
|
74
|
+
if (libc_isupper(ch) == 1) { return ch + 32 }
|
|
75
|
+
return ch
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// ==================== <string.h> ====================
|
|
79
|
+
|
|
80
|
+
// strlen
|
|
81
|
+
function libc_strlen(string s) -> int {
|
|
82
|
+
return strlen(s)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// strcmp: <0 / 0 / >0
|
|
86
|
+
function libc_strcmp(string a, string b) -> int {
|
|
87
|
+
return strcmp(a, b)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// strdup: 复制字符串 (返回新堆串)
|
|
91
|
+
function libc_strdup(string s) -> string {
|
|
92
|
+
return s
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// strcat: 拼接 (C 需要预分配 dst, CIN 直接返回新串)
|
|
96
|
+
function libc_strcat(string a, string b) -> string {
|
|
97
|
+
return a + b
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// strstr: 子串首现下标 (C 返回指针; 未找到 NULL -> 这里 -1)
|
|
101
|
+
function libc_strstr(string hay, string needle) -> int {
|
|
102
|
+
return indexof(hay, needle)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// strchr: 首现下标 (C 第二参数是字符码; CIN 从码值构造字符需要额外
|
|
106
|
+
// 字节表, 这里约定传 1 字符串, 如 libc_strchr(s, "x"); 未找到 -1)
|
|
107
|
+
function libc_strchr(string s, string ch) -> int {
|
|
108
|
+
return indexof(s, ch)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// strrchr: 末现下标 (同上, 未找到 -1)
|
|
112
|
+
function libc_strrchr(string s, string ch) -> int {
|
|
113
|
+
int n = strlen(s)
|
|
114
|
+
int cl = strlen(ch)
|
|
115
|
+
if (cl == 0) { return n }
|
|
116
|
+
int pos = n - cl
|
|
117
|
+
while (pos >= 0) {
|
|
118
|
+
if (strcmp(substr(s, pos, cl), ch) == 0) { return pos }
|
|
119
|
+
pos = pos - 1
|
|
120
|
+
}
|
|
121
|
+
return -1
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// strncmp: 比较前 n 个字符 (同 strcmp 三态)
|
|
125
|
+
function libc_strncmp(string a, string b, int n) -> int {
|
|
126
|
+
if (n <= 0) { return 0 }
|
|
127
|
+
int al = strlen(a)
|
|
128
|
+
int bl = strlen(b)
|
|
129
|
+
int i = 0
|
|
130
|
+
while (i < n) {
|
|
131
|
+
if (i >= al) {
|
|
132
|
+
if (i >= bl) { return 0 }
|
|
133
|
+
return -1
|
|
134
|
+
}
|
|
135
|
+
if (i >= bl) { return 1 }
|
|
136
|
+
string ca = substr(a, i, 1)
|
|
137
|
+
string cb = substr(b, i, 1)
|
|
138
|
+
if (strcmp(ca, cb) != 0) {
|
|
139
|
+
if (strcmp(ca, cb) < 0) { return -1 }
|
|
140
|
+
return 1
|
|
141
|
+
}
|
|
142
|
+
i = i + 1
|
|
143
|
+
}
|
|
144
|
+
return 0
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// strrev (POSIX 常见扩展): 反转字符串
|
|
148
|
+
function libc_strrev(string s) -> string {
|
|
149
|
+
string out = ""
|
|
150
|
+
int i = strlen(s)
|
|
151
|
+
while (i > 0) {
|
|
152
|
+
i = i - 1
|
|
153
|
+
out = out + substr(s, i, 1)
|
|
154
|
+
}
|
|
155
|
+
return out
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// memcpy / memmove: 复制 n 个 int 槽 (CIN 数组即引用, 原地写 dst)
|
|
159
|
+
function libc_memcpy(int[] dst, int[] src, int n) -> void {
|
|
160
|
+
for (int i = 0; i < n; i = i + 1) { dst[i] = src[i] }
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// memset: 用 v 填充 n 个槽
|
|
164
|
+
function libc_memset(int[] dst, int v, int n) -> void {
|
|
165
|
+
for (int i = 0; i < n; i = i + 1) { dst[i] = v }
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// memcmp: 逐槽比较 (同 strcmp 三态)
|
|
169
|
+
function libc_memcmp(int[] a, int[] b, int n) -> int {
|
|
170
|
+
for (int i = 0; i < n; i = i + 1) {
|
|
171
|
+
if (a[i] < b[i]) { return -1 }
|
|
172
|
+
if (a[i] > b[i]) { return 1 }
|
|
173
|
+
}
|
|
174
|
+
return 0
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// ==================== <stdlib.h> ====================
|
|
178
|
+
|
|
179
|
+
// abs
|
|
180
|
+
function libc_abs(int x) -> int {
|
|
181
|
+
if (x < 0) { return -x }
|
|
182
|
+
return x
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// atoi (非整数字符串按 0, 与内建一致; 非 C 的前缀解析)
|
|
186
|
+
function libc_atoi(string s) -> int {
|
|
187
|
+
return atoi(s)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// max / min (C 无标准 max, 这里按 POSIX 风格补齐)
|
|
191
|
+
function libc_max(int a, int b) -> int {
|
|
192
|
+
if (a > b) { return a }
|
|
193
|
+
return b
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function libc_min(int a, int b) -> int {
|
|
197
|
+
if (a < b) { return a }
|
|
198
|
+
return b
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// qsort 升序 (原地; C 的函数指针比较器以"固定升序"简化)
|
|
202
|
+
function libc_qsort_asc(int[] a, int n) -> void {
|
|
203
|
+
for (int i = 0; i < n - 1; i = i + 1) {
|
|
204
|
+
for (int j = 0; j < n - 1 - i; j = j + 1) {
|
|
205
|
+
if (a[j] > a[j + 1]) {
|
|
206
|
+
int t = a[j]
|
|
207
|
+
a[j] = a[j + 1]
|
|
208
|
+
a[j + 1] = t
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// ==================== <math.h> ====================
|
|
215
|
+
|
|
216
|
+
// fabs
|
|
217
|
+
function libc_fabs(float x) -> float {
|
|
218
|
+
if (x < 0.0) { return -x }
|
|
219
|
+
return x
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// sqrt / pow / floor / ceil (转发内建, 三路径一致)
|
|
223
|
+
function libc_sqrt(float x) -> float {
|
|
224
|
+
return sqrt(x)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function libc_pow(float x, float y) -> float {
|
|
228
|
+
return pow(x, y)
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function libc_floor(float x) -> float {
|
|
232
|
+
return floor(x)
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function libc_ceil(float x) -> float {
|
|
236
|
+
return ceil(x)
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// fmod: C 语义 (商向零截断, 结果符号随被除数)
|
|
240
|
+
function libc_fmod(float a, float b) -> float {
|
|
241
|
+
if (b == 0.0) { return 0.0 }
|
|
242
|
+
float q = a / b
|
|
243
|
+
float tq = floor(q)
|
|
244
|
+
if (q < 0.0) { tq = ceil(q) }
|
|
245
|
+
return a - tq * b
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// ==================== <stdio.h> ====================
|
|
249
|
+
|
|
250
|
+
// puts: 输出并换行 (成功返回非负)
|
|
251
|
+
function libc_puts(string s) -> int {
|
|
252
|
+
println(s)
|
|
253
|
+
return 0
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// fputs / printf 的无格式替身 (CIN 无变参; 用字符串拼接表达格式化)
|
|
257
|
+
function libc_print(string s) -> int {
|
|
258
|
+
print(s)
|
|
259
|
+
return 0
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// putchar: 输出单个字符 (传字符码), 返回该字符码; 表外字符码无法构串, 不输出
|
|
263
|
+
// (CIN 无字符构造内建, 表覆盖可见 ASCII 与 \t \n \r)
|
|
264
|
+
function libc_putchar(int ch) -> int {
|
|
265
|
+
print(_libc_chr(ch))
|
|
266
|
+
return ch
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// 内部: 字符码 -> 单字符字符串 (32..126 与 \t \n \r; 其余返回空串)
|
|
270
|
+
function _libc_chr(int code) -> string {
|
|
271
|
+
if (code == 10) { return "\n" }
|
|
272
|
+
if (code == 9) { return "\t" }
|
|
273
|
+
if (code == 13) { return "\r" }
|
|
274
|
+
if (code < 32 || code > 126) { return "" }
|
|
275
|
+
string all = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
|
|
276
|
+
return substr(all, code - 32, 1)
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// ==================== <ctype.h> 扩展 ====================
|
|
280
|
+
|
|
281
|
+
// iscntrl: 控制字符 (0..31 与 127)
|
|
282
|
+
function libc_iscntrl(int ch) -> int {
|
|
283
|
+
if (ch >= 0 && ch <= 31) { return 1 }
|
|
284
|
+
if (ch == 127) { return 1 }
|
|
285
|
+
return 0
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// isgraph: 可打印且非空白 (33..126)
|
|
289
|
+
function libc_isgraph(int ch) -> int {
|
|
290
|
+
if (ch >= 33 && ch <= 126) { return 1 }
|
|
291
|
+
return 0
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// isblank: 空格与 \t
|
|
295
|
+
function libc_isblank(int ch) -> int {
|
|
296
|
+
if (ch == 32 || ch == 9) { return 1 }
|
|
297
|
+
return 0
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// ispunct: 可打印且非字母数字
|
|
301
|
+
function libc_ispunct(int ch) -> int {
|
|
302
|
+
if (libc_isgraph(ch) == 1 && libc_isalnum(ch) == 0) { return 1 }
|
|
303
|
+
return 0
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// toascii: 保留低 7 位 (C 语义)
|
|
307
|
+
function libc_toascii(int ch) -> int {
|
|
308
|
+
return ch & 127
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// ==================== <string.h> 扩展 ====================
|
|
312
|
+
|
|
313
|
+
// memmove: 与 memcpy 同语义 (CIN 数组是引用, 无重叠问题)
|
|
314
|
+
function libc_memmove(int[] dst, int[] src, int n) -> void {
|
|
315
|
+
libc_memcpy(dst, src, n)
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// strspn: 前缀中连续属于 accept 的字符数
|
|
319
|
+
function libc_strspn(string s, string accept) -> int {
|
|
320
|
+
int n = strlen(s)
|
|
321
|
+
int i = 0
|
|
322
|
+
while (i < n) {
|
|
323
|
+
if (libc_strchr(accept, substr(s, i, 1)) < 0) { return i }
|
|
324
|
+
i = i + 1
|
|
325
|
+
}
|
|
326
|
+
return n
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// strcspn: 前缀中连续不属于 reject 的字符数
|
|
330
|
+
function libc_strcspn(string s, string reject) -> int {
|
|
331
|
+
int n = strlen(s)
|
|
332
|
+
int i = 0
|
|
333
|
+
while (i < n) {
|
|
334
|
+
if (libc_strchr(reject, substr(s, i, 1)) >= 0) { return i }
|
|
335
|
+
i = i + 1
|
|
336
|
+
}
|
|
337
|
+
return n
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// strpbrk: s 中首个属于 accept 的字符下标 (C 返回指针; 未找到 -1)
|
|
341
|
+
function libc_strpbrk(string s, string accept) -> int {
|
|
342
|
+
int n = strlen(s)
|
|
343
|
+
int i = 0
|
|
344
|
+
while (i < n) {
|
|
345
|
+
if (libc_strchr(accept, substr(s, i, 1)) >= 0) { return i }
|
|
346
|
+
i = i + 1
|
|
347
|
+
}
|
|
348
|
+
return -1
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// strlwr (POSIX 扩展): 整串转小写 (仅 ASCII 字母变换, 其余字节原样)
|
|
352
|
+
function libc_strlwr(string s) -> string {
|
|
353
|
+
string out = ""
|
|
354
|
+
int n = strlen(s)
|
|
355
|
+
for (int i = 0; i < n; i = i + 1) {
|
|
356
|
+
int ch = s[i]
|
|
357
|
+
if (ch >= 65 && ch <= 90) {
|
|
358
|
+
out = out + substr("abcdefghijklmnopqrstuvwxyz", ch - 65, 1)
|
|
359
|
+
} else {
|
|
360
|
+
out = out + substr(s, i, 1)
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return out
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// strupr (POSIX 扩展): 整串转大写 (仅 ASCII 字母变换, 其余字节原样)
|
|
367
|
+
function libc_strupr(string s) -> string {
|
|
368
|
+
string out = ""
|
|
369
|
+
int n = strlen(s)
|
|
370
|
+
for (int i = 0; i < n; i = i + 1) {
|
|
371
|
+
int ch = s[i]
|
|
372
|
+
if (ch >= 97 && ch <= 122) {
|
|
373
|
+
out = out + substr("ABCDEFGHIJKLMNOPQRSTUVWXYZ", ch - 97, 1)
|
|
374
|
+
} else {
|
|
375
|
+
out = out + substr(s, i, 1)
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return out
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// ==================== <stdlib.h> 扩展 ====================
|
|
382
|
+
|
|
383
|
+
// labs: long 绝对值 (CIN int 即 64 位, 与 abs 同语义)
|
|
384
|
+
function libc_labs(int x) -> int {
|
|
385
|
+
return libc_abs(x)
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// rand / srand: 转发内建 (范围随内建; C 的 RAND_MAX 不适用)
|
|
389
|
+
function libc_rand() -> int {
|
|
390
|
+
return rand()
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
function libc_srand(int seed) -> int {
|
|
394
|
+
srand(seed)
|
|
395
|
+
return 0
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// ==================== <math.h> 扩展 ====================
|
|
399
|
+
|
|
400
|
+
// sin / cos / tan (弧度, 转发内建, 三路径一致)
|
|
401
|
+
function libc_sin(float x) -> float {
|
|
402
|
+
return sin(x)
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function libc_cos(float x) -> float {
|
|
406
|
+
return cos(x)
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
function libc_tan(float x) -> float {
|
|
410
|
+
return tan(x)
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// round: C 语义 (半值远离零; 与内建 round 的 floor(x+0.5) 在负半值上不同:
|
|
414
|
+
// libc_round(-2.5) = -3, round(-2.5) = -2)
|
|
415
|
+
function libc_round(float x) -> float {
|
|
416
|
+
if (x >= 0.0) { return floor(x + 0.5) }
|
|
417
|
+
return ceil(x - 0.5)
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// trunc: 向零截断
|
|
421
|
+
function libc_trunc(float x) -> float {
|
|
422
|
+
if (x >= 0.0) { return floor(x) }
|
|
423
|
+
return ceil(x)
|
|
424
|
+
}
|
codecin/lib/csv/pic.toml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# 由 script/sync_stdlib_packages.py 生成,请勿手工编辑。
|
|
2
|
+
[package]
|
|
3
|
+
name = "csv"
|
|
4
|
+
version = "7.22.10"
|
|
5
|
+
description = "Code CIN 官方标准库: 单行 CSV 解析与生成"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
authors = ["ByUsi Studio"]
|
|
8
|
+
entry = "src/csv.cin"
|
|
9
|
+
repo = "https://gitee.com/codecin/internal-libraries"
|
|
10
|
+
keywords = ["codecin", "stdlib", "csv"]
|