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
codecin/native/mc/elf.go
ADDED
|
@@ -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
|
+
}
|