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,321 @@
1
+ package engine
2
+
3
+ // netsock.go: 完整的 TCP/UDP/DNS 网络系统调用 (SYS 147-157)。
4
+ //
5
+ // 句柄语义: fd 是从 1 开始递增的整数 (三种套接字共用计数), 0/-1 表示失败。
6
+ // - tcp_dial(host, port) -> fd / -1
7
+ // - tcp_send(fd, buf, n) -> 发送字节数 / -1
8
+ // - tcp_recv(fd, buf, max) -> 读取字节数 / 0 对端关闭 / -1 错误
9
+ // - tcp_close(fd) -> 0 成功 / -1
10
+ // - tcp_listen(port) -> 监听 fd / -1
11
+ // - tcp_accept(lfd) -> 连接 fd / -1
12
+ // - udp_open(port) -> fd / -1 (port=0 系统分配)
13
+ // - udp_sendto(fd,host,port,buf,n) -> 发送字节数 / -1
14
+ // - udp_recvfrom(fd,buf,max,srcbuf)-> 读取字节数 / -1 (srcbuf 写入 "ip:port")
15
+ // - udp_close(fd) -> 0 成功 / -1
16
+ // - dns_lookup(host) -> IP 字符串 (新堆串; 失败空串)
17
+
18
+ import (
19
+ "io"
20
+ "net"
21
+ "strconv"
22
+ "sync"
23
+ "time"
24
+ )
25
+
26
+ const (
27
+ netDialTimeout = 10 * time.Second
28
+ maxNetPayload = 8 << 20 // 单次 send/recv 上限 8 MiB
29
+ maxRecvBlockSize = 4 << 20 // recv 一次最多读 4 MiB
30
+ )
31
+
32
+ type sockRegistry struct {
33
+ mu sync.Mutex
34
+ next int
35
+ conns map[int]net.Conn
36
+ listeners map[int]net.Listener
37
+ udps map[int]*net.UDPConn
38
+ }
39
+
40
+ var socks = &sockRegistry{
41
+ next: 1,
42
+ conns: map[int]net.Conn{},
43
+ listeners: map[int]net.Listener{},
44
+ udps: map[int]*net.UDPConn{},
45
+ }
46
+
47
+ func (r *sockRegistry) alloc() int {
48
+ id := r.next
49
+ r.next++
50
+ return id
51
+ }
52
+
53
+ func (r *sockRegistry) getConn(fd uint64) net.Conn {
54
+ r.mu.Lock()
55
+ defer r.mu.Unlock()
56
+ return r.conns[int(fd)]
57
+ }
58
+
59
+ func (r *sockRegistry) getListener(fd uint64) net.Listener {
60
+ r.mu.Lock()
61
+ defer r.mu.Unlock()
62
+ return r.listeners[int(fd)]
63
+ }
64
+
65
+ func (r *sockRegistry) getUDP(fd uint64) *net.UDPConn {
66
+ r.mu.Lock()
67
+ defer r.mu.Unlock()
68
+ return r.udps[int(fd)]
69
+ }
70
+
71
+ func failUint() uint64 { return mask64 } // -1
72
+
73
+ // resolveHost 把主机名解析为 IP (IP 字面量直接返回)。
74
+ // 解析结果偏好 IPv4 地址 —— Windows 上 "localhost" 常先返回 ::1,
75
+ // 对端只监听 IPv4 回环时会收不到包。
76
+ func resolveHost(host string) net.IP {
77
+ if ip := net.ParseIP(host); ip != nil {
78
+ return ip
79
+ }
80
+ addrs, err := net.LookupHost(host)
81
+ if err != nil || len(addrs) == 0 {
82
+ return nil
83
+ }
84
+ for _, a := range addrs {
85
+ if ip := net.ParseIP(a); ip != nil && ip.To4() != nil {
86
+ return ip
87
+ }
88
+ }
89
+ return net.ParseIP(addrs[0])
90
+ }
91
+
92
+ func (vm *vmState) tcpDial(host string, port int) uint64 {
93
+ if host == "" || port <= 0 || port > 65535 {
94
+ return failUint()
95
+ }
96
+ d := net.Dialer{Timeout: netDialTimeout}
97
+ conn, err := d.Dial("tcp", net.JoinHostPort(host, strconv.Itoa(port)))
98
+ if err != nil {
99
+ return failUint()
100
+ }
101
+ socks.mu.Lock()
102
+ defer socks.mu.Unlock()
103
+ id := socks.alloc()
104
+ socks.conns[id] = conn
105
+ return uint64(id)
106
+ }
107
+
108
+ func (vm *vmState) tcpSend(fd, buf uint64, n int) uint64 {
109
+ if n < 0 || n > maxNetPayload {
110
+ return failUint()
111
+ }
112
+ conn := socks.getConn(fd)
113
+ if conn == nil {
114
+ return failUint()
115
+ }
116
+ if n == 0 {
117
+ return 0
118
+ }
119
+ if e := vm.checkAddr(buf, n); e != "" {
120
+ return failUint()
121
+ }
122
+ data := make([]byte, n)
123
+ copy(data, vm.mem[buf:buf+uint64(n)])
124
+ written := 0
125
+ for written < n {
126
+ k, err := conn.Write(data[written:])
127
+ written += k
128
+ if err != nil {
129
+ if written > 0 {
130
+ return uint64(written)
131
+ }
132
+ return failUint()
133
+ }
134
+ }
135
+ return uint64(written)
136
+ }
137
+
138
+ // tcpRecv 阻塞读取 (最多 max 字节); 对端正常关闭返回 0, 错误返回 -1。
139
+ func (vm *vmState) tcpRecv(fd, buf uint64, max int) (uint64, string) {
140
+ if max < 0 || max > maxRecvBlockSize {
141
+ return failUint(), ""
142
+ }
143
+ conn := socks.getConn(fd)
144
+ if conn == nil || max == 0 {
145
+ if conn == nil {
146
+ return failUint(), ""
147
+ }
148
+ return 0, ""
149
+ }
150
+ if e := vm.checkAddr(buf, max); e != "" {
151
+ return 0, "tcp_recv: " + e
152
+ }
153
+ tmp := make([]byte, max)
154
+ n, err := conn.Read(tmp)
155
+ if n > 0 {
156
+ copy(vm.mem[buf:buf+uint64(n)], tmp[:n])
157
+ vm.touch(buf, uint64(n))
158
+ return uint64(n), ""
159
+ }
160
+ if err == io.EOF {
161
+ return 0, ""
162
+ }
163
+ if err == nil {
164
+ return 0, ""
165
+ }
166
+ return failUint(), ""
167
+ }
168
+
169
+ func (vm *vmState) tcpClose(fd uint64) uint64 {
170
+ socks.mu.Lock()
171
+ conn, ok := socks.conns[int(fd)]
172
+ if ok {
173
+ delete(socks.conns, int(fd))
174
+ }
175
+ socks.mu.Unlock()
176
+ if !ok {
177
+ return failUint()
178
+ }
179
+ if err := conn.Close(); err != nil {
180
+ return failUint()
181
+ }
182
+ return 0
183
+ }
184
+
185
+ func (vm *vmState) tcpListen(port uint64) uint64 {
186
+ if port == 0 || port > 65535 {
187
+ return failUint()
188
+ }
189
+ ln, err := net.Listen("tcp", ":"+strconv.FormatUint(port, 10))
190
+ if err != nil {
191
+ return failUint()
192
+ }
193
+ socks.mu.Lock()
194
+ defer socks.mu.Unlock()
195
+ id := socks.alloc()
196
+ socks.listeners[id] = ln
197
+ return uint64(id)
198
+ }
199
+
200
+ func (vm *vmState) tcpAccept(lfd uint64) uint64 {
201
+ ln := socks.getListener(lfd)
202
+ if ln == nil {
203
+ return failUint()
204
+ }
205
+ conn, err := ln.Accept()
206
+ if err != nil {
207
+ return failUint()
208
+ }
209
+ socks.mu.Lock()
210
+ defer socks.mu.Unlock()
211
+ id := socks.alloc()
212
+ socks.conns[id] = conn
213
+ return uint64(id)
214
+ }
215
+
216
+ func (vm *vmState) udpOpen(port uint64) uint64 {
217
+ if port > 65535 {
218
+ return failUint()
219
+ }
220
+ var addr *net.UDPAddr
221
+ if port == 0 {
222
+ addr = &net.UDPAddr{IP: nil} // 系统分配端口
223
+ } else {
224
+ addr = &net.UDPAddr{Port: int(port)}
225
+ }
226
+ conn, err := net.ListenUDP("udp", addr)
227
+ if err != nil {
228
+ return failUint()
229
+ }
230
+ socks.mu.Lock()
231
+ defer socks.mu.Unlock()
232
+ id := socks.alloc()
233
+ socks.udps[id] = conn
234
+ return uint64(id)
235
+ }
236
+
237
+ func (vm *vmState) udpSendTo(fd uint64, host string, port int, buf uint64, n int) uint64 {
238
+ if host == "" || port <= 0 || port > 65535 || n < 0 || n > maxNetPayload {
239
+ return failUint()
240
+ }
241
+ conn := socks.getUDP(fd)
242
+ if conn == nil {
243
+ return failUint()
244
+ }
245
+ // host 兼容 IP 字面量与主机名 (主机名走系统解析, 偏好 IPv4)
246
+ ip := resolveHost(host)
247
+ if ip == nil {
248
+ return failUint()
249
+ }
250
+ if n == 0 {
251
+ k, err := conn.WriteToUDP(nil, &net.UDPAddr{IP: ip, Port: port})
252
+ if err != nil {
253
+ return failUint()
254
+ }
255
+ return uint64(k)
256
+ }
257
+ if e := vm.checkAddr(buf, n); e != "" {
258
+ return failUint()
259
+ }
260
+ data := make([]byte, n)
261
+ copy(data, vm.mem[buf:buf+uint64(n)])
262
+ k, err := conn.WriteToUDP(data, &net.UDPAddr{IP: ip, Port: port})
263
+ if err != nil {
264
+ return failUint()
265
+ }
266
+ return uint64(k)
267
+ }
268
+
269
+ func (vm *vmState) udpRecvFrom(fd, buf uint64, max int, srcInfo uint64) (uint64, string) {
270
+ if max < 0 || max > maxRecvBlockSize {
271
+ return failUint(), ""
272
+ }
273
+ conn := socks.getUDP(fd)
274
+ if conn == nil {
275
+ return failUint(), ""
276
+ }
277
+ if e := vm.checkAddr(buf, max); e != "" {
278
+ return 0, "udp_recvfrom: " + e
279
+ }
280
+ tmp := make([]byte, max)
281
+ n, raddr, err := conn.ReadFromUDP(tmp)
282
+ if err != nil {
283
+ return failUint(), ""
284
+ }
285
+ copy(vm.mem[buf:buf+uint64(n)], tmp[:n])
286
+ vm.touch(buf, uint64(n))
287
+ if srcInfo != 0 {
288
+ if e := vm.writeString(srcInfo, raddr.String()); e != "" {
289
+ return uint64(n), "" // 源地址写不进去不影响收包结果
290
+ }
291
+ }
292
+ return uint64(n), ""
293
+ }
294
+
295
+ func (vm *vmState) udpClose(fd uint64) uint64 {
296
+ socks.mu.Lock()
297
+ conn, ok := socks.udps[int(fd)]
298
+ if ok {
299
+ delete(socks.udps, int(fd))
300
+ }
301
+ socks.mu.Unlock()
302
+ if !ok {
303
+ return failUint()
304
+ }
305
+ if err := conn.Close(); err != nil {
306
+ return failUint()
307
+ }
308
+ return 0
309
+ }
310
+
311
+ // dnsLookup 解析主机名 -> IP 字符串 (偏好 IPv4; 新堆字符串; 失败空串)。
312
+ func (vm *vmState) dnsLookup(host string) uint64 {
313
+ if host == "" {
314
+ return vm.empty()
315
+ }
316
+ ip := resolveHost(host)
317
+ if ip == nil {
318
+ return vm.empty()
319
+ }
320
+ return vm.hs(ip.String())
321
+ }