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/disasm.py
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"""UCBC 字节码反汇编 (A3): .bin -> .asm 风格文本清单。
|
|
2
|
+
|
|
3
|
+
支持三种输入:
|
|
4
|
+
- CPUSA v3 容器 (.bin, `--compile-only` 产物, v5.9.0 段式格式):
|
|
5
|
+
头 50B + 段表 + UCBC 段
|
|
6
|
+
- CPUSA v2 容器 (遗留): 头 34B + 内存镜像 + UCBC 段
|
|
7
|
+
- 裸 UCBC 段 (magic 'UCBC')
|
|
8
|
+
|
|
9
|
+
CLI: codecin --disasm prog.bin
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import os
|
|
13
|
+
import struct
|
|
14
|
+
from typing import Any, List, Tuple
|
|
15
|
+
|
|
16
|
+
from .errors import CPUSimulatorError
|
|
17
|
+
from .isa import Constants
|
|
18
|
+
|
|
19
|
+
Operand = Tuple[Any, ...]
|
|
20
|
+
Instruction = Tuple[str, List[Operand]]
|
|
21
|
+
|
|
22
|
+
#: CPUSA v2 容器头长度 (MAGIC5 + ver1 + mem_size u32 + entry u32 + sp u64
|
|
23
|
+
#: + bc_len u32 + 保留 8B)。
|
|
24
|
+
_BIN_V2_HEADER = 34
|
|
25
|
+
|
|
26
|
+
#: CPUSA v3 容器头长度 (与 crom.BIN_V3_HEADER 一致: mem_size u64 / entry u32 /
|
|
27
|
+
#: sp u64 / heap_base u64 / bc_len u32 / seg_count u32 / 保留 8B)。
|
|
28
|
+
_BIN_V3_HEADER = 50
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def fmt_operand(op: tuple) -> str:
|
|
32
|
+
"""格式化操作数为汇编文本 (自 debugger.fmt_operand 迁移)。"""
|
|
33
|
+
kind = op[0]
|
|
34
|
+
if kind == 'reg':
|
|
35
|
+
return f"X{op[1]}"
|
|
36
|
+
if kind == 'vec':
|
|
37
|
+
return f"V{op[1]}"
|
|
38
|
+
if kind == 'veclane':
|
|
39
|
+
return f"V{op[1]}.{op[2]}"
|
|
40
|
+
if kind == 'imm':
|
|
41
|
+
return f"#{op[1]}"
|
|
42
|
+
if kind == 'mem':
|
|
43
|
+
base, off = op[1], op[2]
|
|
44
|
+
if base >= 0:
|
|
45
|
+
return f"[X{base}, #{off}]" if off else f"[X{base}]"
|
|
46
|
+
return f"[#{off}]"
|
|
47
|
+
if kind == 'cond':
|
|
48
|
+
return op[1]
|
|
49
|
+
if kind == 'str':
|
|
50
|
+
return f"\"@{op[1]}\""
|
|
51
|
+
return str(op)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _format_instruction(index: int, opcode: str, args: List[Operand]) -> str:
|
|
55
|
+
# 条件后缀形式: cond 操作数作为指令 mnemonic.cond 前缀
|
|
56
|
+
if args and args[0][0] == 'cond':
|
|
57
|
+
cond = args[0][1]
|
|
58
|
+
rest = " ".join(fmt_operand(op) for op in args[1:])
|
|
59
|
+
return f"{index:04x}: {opcode}.{cond} {rest}".rstrip()
|
|
60
|
+
parts = [f"{index:04x}:", opcode]
|
|
61
|
+
parts.extend(fmt_operand(op) for op in args)
|
|
62
|
+
return " ".join(parts)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _decode_ucbc_segment(bytecode: bytes) -> Tuple[List[Instruction], int]:
|
|
66
|
+
from .native import decode_program
|
|
67
|
+
return decode_program(bytecode)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _extract_from_bin_v3(data: bytes):
|
|
71
|
+
"""解析 CPUSA v3 容器 (段式), 返回 (bytecode, mem_size, entry, sp)。"""
|
|
72
|
+
mem_size = struct.unpack_from('<Q', data, 6)[0]
|
|
73
|
+
entry = struct.unpack_from('<I', data, 14)[0]
|
|
74
|
+
sp = struct.unpack_from('<Q', data, 18)[0]
|
|
75
|
+
bc_len = struct.unpack_from('<I', data, 34)[0]
|
|
76
|
+
seg_count = struct.unpack_from('<I', data, 38)[0]
|
|
77
|
+
# 段表: 每段 addr u64 + len u64 + data
|
|
78
|
+
pos = _BIN_V3_HEADER
|
|
79
|
+
for _ in range(seg_count):
|
|
80
|
+
if pos + 16 > len(data):
|
|
81
|
+
raise CPUSimulatorError("--disasm: 段表不完整 (文件损坏?)")
|
|
82
|
+
seg_len = struct.unpack_from('<Q', data, pos + 8)[0]
|
|
83
|
+
pos += 16 + seg_len
|
|
84
|
+
if pos + bc_len > len(data):
|
|
85
|
+
raise CPUSimulatorError("--disasm: 字节码不完整 (文件损坏?)")
|
|
86
|
+
return data[pos:pos + bc_len], mem_size, entry, sp
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _extract_from_bin_v2(data: bytes):
|
|
90
|
+
"""解析 CPUSA v2 容器 (遗留), 返回 (bytecode, mem_size, entry, sp)。"""
|
|
91
|
+
mem_size = struct.unpack_from('<I', data, 6)[0]
|
|
92
|
+
entry = struct.unpack_from('<I', data, 10)[0]
|
|
93
|
+
sp = struct.unpack_from('<Q', data, 14)[0]
|
|
94
|
+
bc_len = struct.unpack_from('<I', data, 22)[0]
|
|
95
|
+
return (data[_BIN_V2_HEADER + mem_size:
|
|
96
|
+
_BIN_V2_HEADER + mem_size + bc_len],
|
|
97
|
+
mem_size, entry, sp)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _extract_from_cpusa(data: bytes):
|
|
101
|
+
"""按版本分发解析 CPUSA 容器; 非 CPUSA 返回 None。"""
|
|
102
|
+
if data[:5] != Constants.MAGIC_NUMBER:
|
|
103
|
+
return None
|
|
104
|
+
version = data[5]
|
|
105
|
+
if version == Constants.BIN_VERSION:
|
|
106
|
+
return _extract_from_bin_v3(data)
|
|
107
|
+
if version == Constants.BIN_VERSION_V2:
|
|
108
|
+
return _extract_from_bin_v2(data)
|
|
109
|
+
raise CPUSimulatorError(
|
|
110
|
+
f"--disasm: unsupported binary version {version}")
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def disassemble_bytes(data: bytes) -> List[str]:
|
|
114
|
+
# CPUSA 容器
|
|
115
|
+
cpusa = _extract_from_cpusa(data)
|
|
116
|
+
if cpusa is not None:
|
|
117
|
+
bytecode, mem_size, entry, sp = cpusa
|
|
118
|
+
instructions, _ = _decode_ucbc_segment(bytecode)
|
|
119
|
+
out = [f"; CPUSA binary: {len(instructions)} instructions, "
|
|
120
|
+
f"mem={mem_size} bytes, entry=0x{entry:x}, sp=0x{sp:x}", ";"]
|
|
121
|
+
for idx, (opcode, args) in enumerate(instructions):
|
|
122
|
+
out.append(_format_instruction(idx, opcode, args))
|
|
123
|
+
out.append("")
|
|
124
|
+
return out
|
|
125
|
+
|
|
126
|
+
# 裸 UCBC
|
|
127
|
+
if data[:4] != b'UCBC':
|
|
128
|
+
raise CPUSimulatorError(
|
|
129
|
+
"--disasm 需要 .bin (CPUSA 容器) 或 UCBC 字节码; "
|
|
130
|
+
"先用 `codecin src.cin --compile-only -o out.bin` 生成")
|
|
131
|
+
instructions, entry = _decode_ucbc_segment(data)
|
|
132
|
+
out = [f"; UCBC disassembly: {len(instructions)} instructions, "
|
|
133
|
+
f"entry=0x{entry:x}", ";"]
|
|
134
|
+
for idx, (opcode, args) in enumerate(instructions):
|
|
135
|
+
out.append(_format_instruction(idx, opcode, args))
|
|
136
|
+
out.append("")
|
|
137
|
+
return out
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def disassemble_file(path: str) -> List[str]:
|
|
141
|
+
if not os.path.exists(path):
|
|
142
|
+
raise CPUSimulatorError(f"File '{path}' not found")
|
|
143
|
+
with open(path, 'rb') as f:
|
|
144
|
+
data = f.read()
|
|
145
|
+
from . import sdgcc
|
|
146
|
+
if sdgcc.is_sdgcc(data):
|
|
147
|
+
# .sdgcc 的 CODE 段就是 BIN v3, 直接对其进行反汇编。
|
|
148
|
+
data = sdgcc.parse(data).code
|
|
149
|
+
return disassemble_bytes(data)
|
codecin/environment.py
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"""宿主环境检测与安装提示 (environment)。
|
|
2
|
+
|
|
3
|
+
C/C++/Go 兼容层与 AOT/原生加速依赖本机工具链与原生运行时; 本模块把它们
|
|
4
|
+
的"缺失检测"与"怎么装"集中成单一来源, 保证三条规则:
|
|
5
|
+
|
|
6
|
+
1. 检测只做只读探测 (shutil.which), 绝不自动安装;
|
|
7
|
+
2. 提示必须给出**当前平台可复制执行**的安装命令 (winget/apt/brew/pkg/...);
|
|
8
|
+
3. 缺失提示在所有入口一致: AOT 构建、pip 安装 (setup.py)、解释器
|
|
9
|
+
调用宿主内建 (无原生库)、以及 ``--build-info`` 的环境自检。
|
|
10
|
+
|
|
11
|
+
对外接口::
|
|
12
|
+
|
|
13
|
+
find_tool(tool) -> 绝对路径 / None
|
|
14
|
+
tool_available(tool) -> bool
|
|
15
|
+
install_hint(tool) -> str (多行, 平台相关, 含命令)
|
|
16
|
+
missing_tool_message(tool, purpose) -> str
|
|
17
|
+
native_runtime_hint() -> str (原生库缺失时的安装指引)
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
import os
|
|
21
|
+
import platform
|
|
22
|
+
import shutil
|
|
23
|
+
import sys
|
|
24
|
+
from typing import Optional
|
|
25
|
+
|
|
26
|
+
__all__ = [
|
|
27
|
+
'find_tool',
|
|
28
|
+
'tool_available',
|
|
29
|
+
'install_hint',
|
|
30
|
+
'missing_tool_message',
|
|
31
|
+
'native_runtime_hint',
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
#: GitHub Releases (预编译原生库下载地址)。
|
|
35
|
+
RELEASES_URL = 'https://github.com/ByUsiStudio/Code-CIN/releases'
|
|
36
|
+
#: Go 官方下载页 (所有平台的兜底指引)。
|
|
37
|
+
GO_DOWNLOAD_URL = 'https://go.dev/dl/'
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _system() -> str:
|
|
41
|
+
"""统一平台名: windows / darwin / linux / termux / 其他。"""
|
|
42
|
+
if sys.platform == 'win32':
|
|
43
|
+
return 'windows'
|
|
44
|
+
if sys.platform == 'darwin':
|
|
45
|
+
return 'darwin'
|
|
46
|
+
if sys.platform.startswith('linux'):
|
|
47
|
+
# Termux 的 sys.platform 也是 linux; 用前缀目录特征识别
|
|
48
|
+
if os.path.exists('/data/data/com.termux/files/usr/bin/pkg'):
|
|
49
|
+
return 'termux'
|
|
50
|
+
return 'linux'
|
|
51
|
+
return sys.platform
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def find_tool(tool: str) -> Optional[str]:
|
|
55
|
+
"""在 PATH 中查找可执行文件, 找到返回绝对路径, 否则 None。"""
|
|
56
|
+
if not tool:
|
|
57
|
+
return None
|
|
58
|
+
return shutil.which(tool)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def tool_available(tool: str) -> bool:
|
|
62
|
+
"""工具是否已在 PATH 中可用 (只读探测, 不执行任何命令)。"""
|
|
63
|
+
return find_tool(tool) is not None
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def install_hint(tool: str) -> str:
|
|
67
|
+
"""返回在**当前平台**安装 `tool` 的可操作指引 (多行文本)。
|
|
68
|
+
|
|
69
|
+
已支持: go / gcc / g++ / cc / c++ / clang / clang++ / make。
|
|
70
|
+
未收录的工具返回通用提示 (自行用包管理器安装)。
|
|
71
|
+
"""
|
|
72
|
+
sysname = _system()
|
|
73
|
+
|
|
74
|
+
if tool == 'go':
|
|
75
|
+
if sysname == 'windows':
|
|
76
|
+
return ("安装 Go 工具链 (Windows):\n"
|
|
77
|
+
" winget install GoLang.Go\n"
|
|
78
|
+
f" 或从 {GO_DOWNLOAD_URL} 下载 MSI 安装包\n"
|
|
79
|
+
" 安装后重新打开终端, `go version` 可用即成功")
|
|
80
|
+
if sysname == 'darwin':
|
|
81
|
+
return ("安装 Go 工具链 (macOS):\n"
|
|
82
|
+
" brew install go\n"
|
|
83
|
+
f" 或从 {GO_DOWNLOAD_URL} 下载 pkg 安装包\n"
|
|
84
|
+
" 安装后重新打开终端, `go version` 可用即成功")
|
|
85
|
+
if sysname == 'termux':
|
|
86
|
+
return ("安装 Go 工具链 (Termux):\n"
|
|
87
|
+
" pkg install golang\n"
|
|
88
|
+
" 安装后 `go version` 可用即成功")
|
|
89
|
+
return ("安装 Go 工具链 (Linux):\n"
|
|
90
|
+
" Debian/Ubuntu : sudo apt install golang-go\n"
|
|
91
|
+
" Fedora : sudo dnf install golang\n"
|
|
92
|
+
" Arch : sudo pacman -S go\n"
|
|
93
|
+
f" 或从 {GO_DOWNLOAD_URL} 下载 tarball 解压到 /usr/local\n"
|
|
94
|
+
" 安装后重新打开终端, `go version` 可用即成功")
|
|
95
|
+
|
|
96
|
+
if tool in ('gcc', 'cc'):
|
|
97
|
+
if sysname == 'windows':
|
|
98
|
+
return ("安装 C 编译器 (Windows):\n"
|
|
99
|
+
" MSYS2 : pacman -S mingw-w64-ucrt-x86_64-gcc\n"
|
|
100
|
+
" (然后把 <MSYS2>\\ucrt64\\bin 加入 PATH)\n"
|
|
101
|
+
" WinLibs: winget install BrechtSanders.WinLibs.MSYS-UCRT\n"
|
|
102
|
+
" 安装后 `gcc --version` 可用即成功")
|
|
103
|
+
if sysname == 'darwin':
|
|
104
|
+
return ("安装 C 编译器 (macOS):\n"
|
|
105
|
+
" xcode-select --install (提供 clang, gcc 别名同 clang)\n"
|
|
106
|
+
" 安装后 `gcc --version` 可用即成功")
|
|
107
|
+
if sysname == 'termux':
|
|
108
|
+
return ("安装 C 编译器 (Termux):\n"
|
|
109
|
+
" pkg install clang\n"
|
|
110
|
+
" 安装后 `cc --version` 可用即成功")
|
|
111
|
+
return ("安装 C 编译器 (Linux):\n"
|
|
112
|
+
" Debian/Ubuntu : sudo apt install gcc\n"
|
|
113
|
+
" Fedora : sudo dnf install gcc\n"
|
|
114
|
+
" Arch : sudo pacman -S gcc\n"
|
|
115
|
+
" 安装后 `gcc --version` 可用即成功")
|
|
116
|
+
|
|
117
|
+
if tool in ('g++', 'c++', 'clang++'):
|
|
118
|
+
if sysname == 'windows':
|
|
119
|
+
return ("安装 C++ 编译器 (Windows):\n"
|
|
120
|
+
" MSYS2 : pacman -S mingw-w64-ucrt-x86_64-gcc\n"
|
|
121
|
+
" (含 g++, 然后把 <MSYS2>\\ucrt64\\bin 加入 PATH)\n"
|
|
122
|
+
" WinLibs: winget install BrechtSanders.WinLibs.MSYS-UCRT\n"
|
|
123
|
+
" 安装后 `g++ --version` 可用即成功")
|
|
124
|
+
if sysname == 'darwin':
|
|
125
|
+
return ("安装 C++ 编译器 (macOS):\n"
|
|
126
|
+
" xcode-select --install (提供 clang++)\n"
|
|
127
|
+
" 安装后 `c++ --version` 可用即成功")
|
|
128
|
+
if sysname == 'termux':
|
|
129
|
+
return ("安装 C++ 编译器 (Termux):\n"
|
|
130
|
+
" pkg install clang\n"
|
|
131
|
+
" 安装后 `clang++ --version` 可用即成功")
|
|
132
|
+
return ("安装 C++ 编译器 (Linux):\n"
|
|
133
|
+
" Debian/Ubuntu : sudo apt install g++\n"
|
|
134
|
+
" Fedora : sudo dnf install gcc-c++\n"
|
|
135
|
+
" Arch : sudo pacman -S gcc\n"
|
|
136
|
+
" 安装后 `g++ --version` 可用即成功")
|
|
137
|
+
|
|
138
|
+
if tool in ('clang',):
|
|
139
|
+
return ("安装 Clang:\n"
|
|
140
|
+
" Windows : winget install LLVM.LLVM\n"
|
|
141
|
+
" macOS : xcode-select --install\n"
|
|
142
|
+
" Linux : sudo apt install clang (Debian/Ubuntu)\n"
|
|
143
|
+
" Termux : pkg install clang\n")
|
|
144
|
+
|
|
145
|
+
return (f"未找到 {tool}: 请使用当前平台的包管理器安装\n"
|
|
146
|
+
f" (Windows: winget / Linux: apt|dnf|pacman / macOS: brew)\n")
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def missing_tool_message(tool: str, purpose: str) -> str:
|
|
150
|
+
"""「缺工具 + 用途 + 怎么装」合一的完整错误提示。"""
|
|
151
|
+
lines = [
|
|
152
|
+
f"未找到 `{tool}` 命令 — {purpose} 需要 {tool} 工具链 (当前平台: "
|
|
153
|
+
f"{platform.system()})。",
|
|
154
|
+
]
|
|
155
|
+
lines.append(install_hint(tool).rstrip())
|
|
156
|
+
return '\n'.join(lines)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def native_runtime_hint() -> str:
|
|
160
|
+
"""原生 Go 运行库缺失时的安装指引 (多行文本)。
|
|
161
|
+
|
|
162
|
+
适用场景: 宿主能力内建 (音频/GUI/文件/网络/键盘...) 在无原生库时被调用。
|
|
163
|
+
只有其中的原生依赖项 (如 go_os_args_*) 会走到这里。
|
|
164
|
+
"""
|
|
165
|
+
pkg_dir = os.path.dirname(os.path.abspath(__file__))
|
|
166
|
+
return (
|
|
167
|
+
"宿主能力内建需要原生 Go 运行库 (c-shared DLL/SO), 当前不可用。\n"
|
|
168
|
+
"解决方案 (任选其一):\n"
|
|
169
|
+
" 1. 安装 Go 工具链后重装本包 (安装时现场编译原生库):\n"
|
|
170
|
+
" pip install --force-reinstall codecin\n"
|
|
171
|
+
" 2. 从 Release 下载预编译原生库 (平台-架构 后缀), 放到:\n"
|
|
172
|
+
f" {pkg_dir}\n"
|
|
173
|
+
f" {RELEASES_URL}\n"
|
|
174
|
+
" 3. 本地手动构建: 运行 codecin/native/build.ps1 (Windows)\n"
|
|
175
|
+
" 或 codecin/native/build.sh (Linux/Termux/macOS)。"
|
|
176
|
+
)
|
codecin/errors.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
from typing import Any, Optional
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class CPUSimulatorError(Exception):
|
|
5
|
+
"""所有 Code CIN 错误的基类。"""
|
|
6
|
+
|
|
7
|
+
def __init__(self, message: str, detail: Optional[Any] = None):
|
|
8
|
+
self.message = message
|
|
9
|
+
self.detail = detail
|
|
10
|
+
super().__init__(message)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class AssemblerError(CPUSimulatorError):
|
|
14
|
+
"""汇编阶段错误 (.pl / .asm)。"""
|
|
15
|
+
|
|
16
|
+
def __init__(self, line: str, detail: str, line_num: Optional[int] = None,
|
|
17
|
+
filename: Optional[str] = None):
|
|
18
|
+
self.line = line
|
|
19
|
+
self.line_num = line_num
|
|
20
|
+
self.filename = filename
|
|
21
|
+
location = ""
|
|
22
|
+
if filename and line_num:
|
|
23
|
+
location = f"{filename}:{line_num}: "
|
|
24
|
+
elif line_num:
|
|
25
|
+
location = f"Line {line_num}: "
|
|
26
|
+
super().__init__(f"{location}Assembler error: {line.strip()} -- {detail}",
|
|
27
|
+
detail=detail)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class CompilerError(CPUSimulatorError):
|
|
31
|
+
"""CIN 编译阶段错误。"""
|
|
32
|
+
|
|
33
|
+
def __init__(self, message: str, line_num: Optional[int] = None,
|
|
34
|
+
filename: Optional[str] = None):
|
|
35
|
+
self.line_num = line_num
|
|
36
|
+
self.filename = filename
|
|
37
|
+
location = ""
|
|
38
|
+
if filename and line_num:
|
|
39
|
+
location = f"{filename}:{line_num}: "
|
|
40
|
+
elif line_num:
|
|
41
|
+
location = f"Line {line_num}: "
|
|
42
|
+
super().__init__(f"{location}Compiler error: {message}")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class ExecutionError(CPUSimulatorError):
|
|
46
|
+
"""指令执行阶段错误 (除零、未实现指令、栈错误等)。"""
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class MemoryAccessError(CPUSimulatorError):
|
|
50
|
+
"""内存访问错误 (越界)。"""
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
# 向后兼容别名 (旧代码引用 MemoryError)
|
|
54
|
+
MemoryError = MemoryAccessError
|