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,88 @@
1
+ package mc
2
+
3
+ import (
4
+ "encoding/binary"
5
+ "fmt"
6
+
7
+ "codecin-native/ir"
8
+ )
9
+
10
+ const (
11
+ ehdrSize = 0x40
12
+ phdrSize = 0x38
13
+ entryOff = ehdrSize + phdrSize // 0x78
14
+ )
15
+
16
+ // WrapELF 把入口处的机器码 + 程序数据包装成可执行的 ELF64 (Linux, x86-64)。
17
+ //
18
+ // 布局: [ELF 头 + 1 个 PT_LOAD][代码][寄存器组/标志][数据段]。
19
+ // IR 数据地址 A 落在虚地址 dataBase+A。
20
+ func WrapELF(p *ir.Program, code []byte) []byte {
21
+ if len(code) == 0 {
22
+ return nil
23
+ }
24
+ dataOff := dataBase - baseAddr
25
+ end := dataOff + regCount*8
26
+ if flags := dataOff + flagOff + 8; flags > end {
27
+ end = flags
28
+ }
29
+ if buf := dataOff + itoaBuf + 64; buf > end {
30
+ end = buf
31
+ }
32
+ for _, w := range p.DataWrites {
33
+ if e := dataOff + w.Addr + len(w.Data); e > end {
34
+ end = e
35
+ }
36
+ }
37
+ img := make([]byte, end)
38
+ copy(img[entryOff:], code)
39
+ for _, w := range p.DataWrites {
40
+ copy(img[dataOff+w.Addr:], w.Data)
41
+ }
42
+
43
+ // e_ident
44
+ copy(img[0:16], []byte{0x7F, 'E', 'L', 'F', 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0})
45
+ le := binary.LittleEndian
46
+ le.PutUint16(img[16:], 2) // ET_EXEC
47
+ le.PutUint16(img[18:], 62) // EM_X86_64
48
+ le.PutUint32(img[20:], 1) // EV_CURRENT
49
+ le.PutUint64(img[24:], uint64(baseAddr+entryOff)) // e_entry
50
+ le.PutUint64(img[32:], ehdrSize) // e_phoff
51
+ le.PutUint64(img[40:], 0) // e_shoff
52
+ le.PutUint32(img[48:], 0) // e_flags
53
+ le.PutUint16(img[52:], ehdrSize) // e_ehsize
54
+ le.PutUint16(img[54:], phdrSize) // e_phentsize
55
+ le.PutUint16(img[56:], 1) // e_phnum
56
+ le.PutUint16(img[58:], 0) // e_shentsize
57
+ le.PutUint16(img[60:], 0) // e_shnum
58
+ le.PutUint16(img[62:], 0) // e_shstrndx
59
+
60
+ ph := ehdrSize
61
+ le.PutUint32(img[ph:], 1) // PT_LOAD
62
+ le.PutUint32(img[ph+4:], 7) // PF_R|PF_W|PF_X
63
+ le.PutUint64(img[ph+8:], 0) // p_offset
64
+ le.PutUint64(img[ph+16:], uint64(baseAddr)) // p_vaddr
65
+ le.PutUint64(img[ph+24:], uint64(baseAddr)) // p_paddr
66
+ le.PutUint64(img[ph+32:], uint64(len(img))) // p_filesz
67
+ le.PutUint64(img[ph+40:], uint64(len(img))) // p_memsz
68
+ le.PutUint64(img[ph+48:], 0x1000) // p_align
69
+ return img
70
+ }
71
+
72
+ // Entry 返回代码段入口的虚拟地址 (供测试校验)。
73
+ func Entry() uint64 { return uint64(baseAddr + entryOff) }
74
+
75
+ // CheckELF 校验产物是 x86-64 ELF 且入口正确。
76
+ func CheckELF(img []byte) error {
77
+ if len(img) < entryOff || string(img[:4]) != "\x7fELF" {
78
+ return fmt.Errorf("不是 ELF")
79
+ }
80
+ le := binary.LittleEndian
81
+ if machine := le.Uint16(img[18:]); machine != 62 {
82
+ return fmt.Errorf("e_machine=%d, 期望 62", machine)
83
+ }
84
+ if entry := le.Uint64(img[24:]); entry != Entry() {
85
+ return fmt.Errorf("e_entry=%#x, 期望 %#x", entry, Entry())
86
+ }
87
+ return nil
88
+ }
@@ -0,0 +1,52 @@
1
+ package mc
2
+
3
+ import (
4
+ "os"
5
+ "os/exec"
6
+ "path/filepath"
7
+ "runtime"
8
+ "testing"
9
+
10
+ "codecin-native/ir"
11
+ )
12
+
13
+ func runRC(t *testing.T, code []byte, p *ir.Program) string {
14
+ t.Helper()
15
+ dir := t.TempDir()
16
+ path := filepath.Join(dir, "prog")
17
+ if err := os.WriteFile(path, WrapELF(p, code), 0o755); err != nil {
18
+ t.Fatal(err)
19
+ }
20
+ wslPath := "/mnt/" + string(path[0]|0x20) + filepath.ToSlash(path[2:])
21
+ script := `"` + wslPath + `"; echo rc=$?`
22
+ out, err := exec.Command("wsl", "-e", "sh", "-c", script).CombinedOutput()
23
+ if err != nil {
24
+ t.Fatalf("运行失败: %v\n%s", err, out)
25
+ }
26
+ return string(out)
27
+ }
28
+
29
+ // TestPrintString 验证 OUT str 生成的 write 系统调用真的输出了字符串。
30
+ func TestPrintString(t *testing.T) {
31
+ if runtime.GOOS != "windows" {
32
+ t.Skip("仅在 Windows + WSL 下运行")
33
+ }
34
+ if err := exec.Command("wsl", "-e", "echo", "ok").Run(); err != nil {
35
+ t.Skip("WSL 不可用")
36
+ }
37
+ p := &ir.Program{
38
+ Instructions: []ir.Instr{
39
+ {Op: "OUT", Args: []ir.Operand{ir.Str(0x1000)}},
40
+ {Op: "HALT"},
41
+ },
42
+ DataWrites: []ir.DataWrite{{Addr: 0x1000, Data: []byte("hi\n\x00")}},
43
+ }
44
+ code, err := Encode(p)
45
+ if err != nil {
46
+ t.Fatalf("Encode: %v", err)
47
+ }
48
+ out := runRC(t, code, p)
49
+ if !contains(out, "hi") {
50
+ t.Fatalf("输出 %q 不含 hi", out)
51
+ }
52
+ }