codecin 5.4.2__py3-none-any.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 +229 -0
- codecin/assembler.py +548 -0
- codecin/cache.py +71 -0
- codecin/cin.py +2558 -0
- codecin/cli.py +282 -0
- codecin/config.py +58 -0
- codecin/console.py +183 -0
- codecin/cpu.py +1654 -0
- codecin/crom.py +222 -0
- codecin/debugger.py +659 -0
- codecin/disasm.py +86 -0
- codecin/errors.py +58 -0
- codecin/isa.py +457 -0
- codecin/jit.py +270 -0
- codecin/libcodecin_native.so +0 -0
- codecin/logger.py +145 -0
- codecin/memory.py +348 -0
- codecin/native/aot/aot.go +70 -0
- codecin/native/aot/build.go +219 -0
- codecin/native/aot/stub_main.go.txt +22 -0
- codecin/native/build.ps1 +33 -0
- codecin/native/build.sh +48 -0
- codecin/native/cmd/codecin/main.go +287 -0
- codecin/native/compiler/codegen.go +1938 -0
- codecin/native/compiler/compile_test.go +164 -0
- codecin/native/compiler/parser.go +1071 -0
- codecin/native/compiler/syscalls.go +86 -0
- codecin/native/compiler/tokenizer.go +336 -0
- codecin/native/compiler/types.go +213 -0
- codecin/native/engine/audio.go +152 -0
- codecin/native/engine/audio_other.go +46 -0
- codecin/native/engine/audio_windows.go +43 -0
- codecin/native/engine/canvas.go +271 -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/isa_gen.go +445 -0
- codecin/native/engine/system.go +190 -0
- codecin/native/engine/termux.go +113 -0
- codecin/native/engine/version_gen.go +7 -0
- codecin/native/engine/vm.go +1157 -0
- codecin/native/go.mod +3 -0
- codecin/native/ir/ir.go +48 -0
- codecin/native/main.go +225 -0
- codecin/native.py +336 -0
- codecin/registers.py +130 -0
- codecin/stats.py +235 -0
- codecin-5.4.2.dist-info/METADATA +985 -0
- codecin-5.4.2.dist-info/RECORD +54 -0
- codecin-5.4.2.dist-info/WHEEL +5 -0
- codecin-5.4.2.dist-info/entry_points.txt +2 -0
- codecin-5.4.2.dist-info/licenses/LICENSE +7 -0
- codecin-5.4.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
package engine
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"os"
|
|
5
|
+
"os/exec"
|
|
6
|
+
"os/user"
|
|
7
|
+
"runtime"
|
|
8
|
+
"sort"
|
|
9
|
+
"strings"
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
// 系统原生交互: 文件/目录/进程/环境变量/系统信息 (跨平台 Windows/Linux/macOS)。
|
|
13
|
+
// 全部经 SYS 宿主调用暴露给 CIN。
|
|
14
|
+
|
|
15
|
+
// empty 返回一个安全的空串地址 (惰性分配, 避免影响 heap_ptr 的三路径一致性)。
|
|
16
|
+
func (vm *vmState) empty() uint64 {
|
|
17
|
+
if vm.emptyStr == 0 {
|
|
18
|
+
p, _ := vm.heapDupString("")
|
|
19
|
+
vm.emptyStr = p
|
|
20
|
+
}
|
|
21
|
+
cur := vm.emptyStr
|
|
22
|
+
return cur
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// hs 在堆上分配字符串; 失败时回退到预留空串 (安全无副作用)。
|
|
26
|
+
func (vm *vmState) hs(s string) uint64 {
|
|
27
|
+
p, e := vm.heapDupString(s)
|
|
28
|
+
if e != "" {
|
|
29
|
+
return vm.empty()
|
|
30
|
+
}
|
|
31
|
+
return p
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// ---------------- 文件系统 ----------------
|
|
35
|
+
|
|
36
|
+
func (vm *vmState) fileRead(path string) uint64 {
|
|
37
|
+
data, err := os.ReadFile(path)
|
|
38
|
+
if err != nil {
|
|
39
|
+
return vm.empty()
|
|
40
|
+
}
|
|
41
|
+
return vm.hs(string(data))
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
func (vm *vmState) fileWrite(path, content string) uint64 {
|
|
45
|
+
if err := os.WriteFile(path, []byte(content), 0o644); err != nil {
|
|
46
|
+
return mask64
|
|
47
|
+
}
|
|
48
|
+
return 0
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
func (vm *vmState) fileAppend(path, content string) uint64 {
|
|
52
|
+
f, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
|
|
53
|
+
if err != nil {
|
|
54
|
+
return mask64
|
|
55
|
+
}
|
|
56
|
+
defer f.Close()
|
|
57
|
+
if _, err := f.WriteString(content); err != nil {
|
|
58
|
+
return mask64
|
|
59
|
+
}
|
|
60
|
+
return 0
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
func (vm *vmState) fileExists(path string) uint64 {
|
|
64
|
+
if _, err := os.Stat(path); err == nil {
|
|
65
|
+
return 1
|
|
66
|
+
}
|
|
67
|
+
return 0
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
func (vm *vmState) fileDelete(path string) uint64 {
|
|
71
|
+
if err := os.Remove(path); err != nil {
|
|
72
|
+
return mask64
|
|
73
|
+
}
|
|
74
|
+
return 0
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
func (vm *vmState) fileSize(path string) uint64 {
|
|
78
|
+
fi, err := os.Stat(path)
|
|
79
|
+
if err != nil {
|
|
80
|
+
return mask64
|
|
81
|
+
}
|
|
82
|
+
return uint64(fi.Size())
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
func (vm *vmState) mkdir(path string) uint64 {
|
|
86
|
+
if err := os.MkdirAll(path, 0o755); err != nil {
|
|
87
|
+
return mask64
|
|
88
|
+
}
|
|
89
|
+
return 0
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
func (vm *vmState) dirList(path string) uint64 {
|
|
93
|
+
entries, err := os.ReadDir(path)
|
|
94
|
+
if err != nil {
|
|
95
|
+
return vm.empty()
|
|
96
|
+
}
|
|
97
|
+
names := make([]string, 0, len(entries))
|
|
98
|
+
for _, e := range entries {
|
|
99
|
+
name := e.Name()
|
|
100
|
+
if e.IsDir() {
|
|
101
|
+
name += "/"
|
|
102
|
+
}
|
|
103
|
+
names = append(names, name)
|
|
104
|
+
}
|
|
105
|
+
sort.Strings(names)
|
|
106
|
+
return vm.hs(strings.Join(names, "\n"))
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// ---------------- 进程执行 ----------------
|
|
110
|
+
|
|
111
|
+
func shellCommand(cmd string) *exec.Cmd {
|
|
112
|
+
if runtime.GOOS == "windows" {
|
|
113
|
+
return exec.Command("cmd", "/c", cmd)
|
|
114
|
+
}
|
|
115
|
+
return exec.Command("sh", "-c", cmd)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
func (vm *vmState) execCmd(cmd string) uint64 {
|
|
119
|
+
err := shellCommand(cmd).Run()
|
|
120
|
+
if err == nil {
|
|
121
|
+
return 0
|
|
122
|
+
}
|
|
123
|
+
if ee, ok := err.(*exec.ExitError); ok {
|
|
124
|
+
return uint64(int64(ee.ExitCode())) & mask64
|
|
125
|
+
}
|
|
126
|
+
return mask64
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
func (vm *vmState) execOutput(cmd string) uint64 {
|
|
130
|
+
out, err := shellCommand(cmd).Output()
|
|
131
|
+
if err != nil && len(out) == 0 {
|
|
132
|
+
return vm.empty()
|
|
133
|
+
}
|
|
134
|
+
return vm.hs(string(out))
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// ---------------- 环境变量 / 系统信息 ----------------
|
|
138
|
+
|
|
139
|
+
func (vm *vmState) getenv(name string) uint64 {
|
|
140
|
+
return vm.hs(os.Getenv(name))
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
func (vm *vmState) setenv(name, value string) uint64 {
|
|
144
|
+
if err := os.Setenv(name, value); err != nil {
|
|
145
|
+
return mask64
|
|
146
|
+
}
|
|
147
|
+
return 0
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
func (vm *vmState) osName() uint64 {
|
|
151
|
+
return vm.hs(runtime.GOOS)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
func (vm *vmState) hostname() uint64 {
|
|
155
|
+
h, err := os.Hostname()
|
|
156
|
+
if err != nil {
|
|
157
|
+
return vm.empty()
|
|
158
|
+
}
|
|
159
|
+
return vm.hs(h)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
func (vm *vmState) username() uint64 {
|
|
163
|
+
if u, err := user.Current(); err == nil && u.Username != "" {
|
|
164
|
+
return vm.hs(u.Username)
|
|
165
|
+
}
|
|
166
|
+
for _, key := range []string{"USER", "USERNAME", "LOGNAME"} {
|
|
167
|
+
if v := os.Getenv(key); v != "" {
|
|
168
|
+
return vm.hs(v)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return vm.empty()
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
func (vm *vmState) cwd() uint64 {
|
|
175
|
+
d, err := os.Getwd()
|
|
176
|
+
if err != nil {
|
|
177
|
+
return vm.empty()
|
|
178
|
+
}
|
|
179
|
+
return vm.hs(d)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
func (vm *vmState) homeDir() uint64 {
|
|
183
|
+
if h, err := os.UserHomeDir(); err == nil && h != "" {
|
|
184
|
+
return vm.hs(h)
|
|
185
|
+
}
|
|
186
|
+
if h := os.Getenv("HOME"); h != "" {
|
|
187
|
+
return vm.hs(h)
|
|
188
|
+
}
|
|
189
|
+
return vm.hs(os.Getenv("USERPROFILE"))
|
|
190
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
package engine
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"os"
|
|
5
|
+
"os/exec"
|
|
6
|
+
"strconv"
|
|
7
|
+
"strings"
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
// Termux API 交互 (Android / Termux)。经 termux-* 命令调用 (需 pkg install termux-api
|
|
11
|
+
// 并安装 Termux:API 应用)。非 Termux 环境下所有调用优雅失败 (返回 -1 或空串)。
|
|
12
|
+
|
|
13
|
+
// TermuxAvailable 检测 Termux API 是否可用。
|
|
14
|
+
func TermuxAvailable() bool {
|
|
15
|
+
if os.Getenv("TERMUX_VERSION") != "" {
|
|
16
|
+
return true
|
|
17
|
+
}
|
|
18
|
+
if strings.Contains(os.Getenv("PREFIX"), "com.termux") {
|
|
19
|
+
return true
|
|
20
|
+
}
|
|
21
|
+
_, err := exec.LookPath("termux-notification")
|
|
22
|
+
return err == nil
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// termuxRun 运行 termux-* 命令, 返回 (stdout, 0/-1)。
|
|
26
|
+
func termuxRun(name string, args ...string) (string, uint64) {
|
|
27
|
+
path, err := exec.LookPath(name)
|
|
28
|
+
if err != nil {
|
|
29
|
+
return "", mask64
|
|
30
|
+
}
|
|
31
|
+
out, err := exec.Command(path, args...).Output()
|
|
32
|
+
if err != nil {
|
|
33
|
+
return string(out), mask64
|
|
34
|
+
}
|
|
35
|
+
return string(out), 0
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
func (vm *vmState) termuxAvailable() uint64 {
|
|
39
|
+
if TermuxAvailable() {
|
|
40
|
+
return 1
|
|
41
|
+
}
|
|
42
|
+
return 0
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
func (vm *vmState) termuxNotify(title, content string) uint64 {
|
|
46
|
+
_, code := termuxRun("termux-notification", "--title", title, "--content", content)
|
|
47
|
+
return code
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
func (vm *vmState) termuxToast(msg string) uint64 {
|
|
51
|
+
_, code := termuxRun("termux-toast", msg)
|
|
52
|
+
return code
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
func (vm *vmState) termuxClipboardGet() uint64 {
|
|
56
|
+
out, code := termuxRun("termux-clipboard-get")
|
|
57
|
+
if code != 0 {
|
|
58
|
+
return vm.empty()
|
|
59
|
+
}
|
|
60
|
+
return vm.hs(strings.TrimRight(out, "\r\n"))
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
func (vm *vmState) termuxClipboardSet(text string) uint64 {
|
|
64
|
+
_, code := termuxRun("termux-clipboard-set", text)
|
|
65
|
+
return code
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
func (vm *vmState) termuxBattery() uint64 {
|
|
69
|
+
out, code := termuxRun("termux-battery-status")
|
|
70
|
+
if code != 0 {
|
|
71
|
+
return vm.empty()
|
|
72
|
+
}
|
|
73
|
+
return vm.hs(strings.TrimSpace(out))
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
func (vm *vmState) termuxVibrate(ms uint64) uint64 {
|
|
77
|
+
_, code := termuxRun("termux-vibrate", "-d", strconv.FormatUint(ms, 10))
|
|
78
|
+
return code
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
func (vm *vmState) termuxTTS(text string) uint64 {
|
|
82
|
+
_, code := termuxRun("termux-tts-speak", text)
|
|
83
|
+
return code
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
func (vm *vmState) termuxLocation() uint64 {
|
|
87
|
+
out, code := termuxRun("termux-location")
|
|
88
|
+
if code != 0 {
|
|
89
|
+
return vm.empty()
|
|
90
|
+
}
|
|
91
|
+
return vm.hs(strings.TrimSpace(out))
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
func (vm *vmState) termuxWifiInfo() uint64 {
|
|
95
|
+
out, code := termuxRun("termux-wifi-connectioninfo")
|
|
96
|
+
if code != 0 {
|
|
97
|
+
return vm.empty()
|
|
98
|
+
}
|
|
99
|
+
return vm.hs(strings.TrimSpace(out))
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
func (vm *vmState) termuxDialog(title string) uint64 {
|
|
103
|
+
out, code := termuxRun("termux-dialog", "-t", title)
|
|
104
|
+
if code != 0 {
|
|
105
|
+
return vm.empty()
|
|
106
|
+
}
|
|
107
|
+
return vm.hs(strings.TrimSpace(out))
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
func (vm *vmState) termuxSmsSend(number, text string) uint64 {
|
|
111
|
+
_, code := termuxRun("termux-sms-send", "-n", number, text)
|
|
112
|
+
return code
|
|
113
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Code generated by script/gen_native_isa.py from codecin/__init__.py; DO NOT EDIT.
|
|
2
|
+
// 单一事实来源: codecin/__init__.py 的 __version__ (见 pyproject.toml dynamic version)。
|
|
3
|
+
|
|
4
|
+
package engine
|
|
5
|
+
|
|
6
|
+
// BuildVersion 是 Code CIN 的版本号 (被 codecin_version() 与日志使用)。
|
|
7
|
+
const BuildVersion = "5.4.2"
|