Rewrote the comments in the libraries under 'includes' in English (excluding those inside folders)

This commit is contained in:
2026-07-29 23:34:36 +08:00
parent 3633be1995
commit a2cc28a6ab
54 changed files with 7091 additions and 899 deletions

View File

@@ -5,46 +5,46 @@ import memhub
import string
import stdio
# Windows 后端依赖
# Windows backend dependencies
import w32.win32base
import w32.win32process
# POSIX 后端依赖
# POSIX backend dependencies
import posix
# 模块级全局 MBuddy 指针(由用户在 main 中赋值初始化)
# Module global MBuddy pointer (initialized in user main), Plans to ban
_mbuddy: memhub.MemBuddy | t.CPtr
# =============================================================================
# C 标准库 IO 声明
# C Standard Library IO Declarations
# =============================================================================
def fgets(buf: t.CChar | t.CPtr, size: t.CInt, stream: t.CVoid | t.CPtr) -> t.CChar | t.CPtr | t.CExtern | t.CExport: pass
def fgets(buf: bytes, size: int, stream: t.CVoid | t.CPtr) -> str | t.State: pass
def fflush(stream: t.CVoid | t.CPtr) -> t.CInt | t.CExtern | t.CExport: pass
def fflush(stream: t.CVoid | t.CPtr) -> int | t.State: pass
# C 标准库 exit刷新缓冲区后终止进程跨平台
def exit(status: INT) -> VOID | t.CExtern | t.CExport: pass
# C standard library exit (terminates the process after flushing the buffer, cross-platform)
def exit(status: int) -> t.State: pass
# =============================================================================
# 平台信息
# Platform Information
# =============================================================================
# 最大整数值64 位平台 ssize_t 上限)
maxsize: t.CDefine = 9223372036854775807
# Maximum integer value (64-bit platform ssize_t upper limit)
maxsize: t.CDefine = 9223372036854775807 # 2^63 - 1
def platform() -> str:
"""返回平台标识字符串('win32' 'linux'"""
"""Returns the platform identifier string ('win32' or 'linux')."""
if platmacro.IS_WINDOWS:
return "win32"
return "linux"
# =============================================================================
# 进程信息
# Process Information
# =============================================================================
def get_pid() -> int:
@@ -55,19 +55,19 @@ def get_pid() -> int:
# =============================================================================
# 命令行参数(argv
# Command Line Arguments (argv)
# =============================================================================
# 全局 argv 状态(首次访问时初始化)
_argc: INT = 0
# _argv 是指针数组char**),必须用 str | t.CPtr 使索引按 sizeof(char*) 步长
# str 本身是 char*| t.CPtr 再加一层指针 = char**
# bytes | t.CPtr 也是 char**,可以同样用
# global argv status (initialized on first access)
_argc: int = 0
# _argv is a pointer array (char**), must use str | t.CPtr to index with sizeof(char*)
# str | t.CPtr is a pointer to char**
# bytes | t.CPtr is a pointer to char**
_argv: str | t.CPtr
def _init_argv():
"""初始化全局 argv首次访问时调用一次"""
"""Initialize global argv once on first access"""
global _argc, _argv
if _argc != 0:
return
@@ -78,7 +78,7 @@ def _init_argv():
def _init_argv_win32():
"""WindowsGetCommandLineA + 手动解析(处理空格/双引号/反斜杠)"""
"""Windows: GetCommandLineA + manual parsing (handle spaces/double quotes/backslashes)"""
global _argc, _argv
cmdline: CHARPTR = w32.win32base.GetCommandLineA()
if cmdline == None:
@@ -87,12 +87,12 @@ def _init_argv_win32():
if cmdlen == 0:
return
# 分配参数字符串缓冲区(最坏情况:整个命令行 + argc 个 \0
# Allocate buffer for parameter strings (worst case: entire command line + argc \0s)
buf: bytes = _mbuddy.alloc(cmdlen + 1)
if buf == None:
return
# 分配指针数组(最坏情况:每个字符都是一个参数)
# Allocate pointer array for argv (worst case: each character is a parameter)
max_args: t.CSizeT = cmdlen + 1
argv_arr: str | t.CPtr = (str | t.CPtr)(_mbuddy.alloc(max_args * platmacro.SIZEOF_POINTER))
if argv_arr == None:
@@ -106,14 +106,14 @@ def _init_argv_win32():
while i < cmdlen:
ch: t.CInt = cmdline[i]
if ch == 34: # 双引号
if ch == 34: # Double quote
in_quote = not in_quote
if not in_arg:
argv_arr[argc] = str(buf + j)
argc += 1
in_arg = True
elif (ch == 32 or ch == 9) and not in_quote:
# 空格或 Tab引号外参数分隔符
# Space or Tab (outside quotes): parameter delimiter
if in_arg:
buf[j] = 0
j += 1
@@ -135,14 +135,14 @@ def _init_argv_win32():
def _init_argv_posix():
"""POSIX:读取 /proc/self/cmdline(参数以 \\0 分隔,末尾双 \\0"""
"""POSIX: Read cmdline from /proc/self/cmdline (\0) separated parameters"""
global _argc, _argv
fd: INT = posix.open("/proc/self/cmdline", posix.O_RDONLY, 0)
if fd < 0:
return
# 读取 cmdline4KB 足够大多数情况)
buf: bytes = _mbuddy.alloc(4096)
# Read cmdline (4KB)
buf: bytes = _mbuddy.alloc(4096) # Need to verify size of buffer
if buf == None:
posix.close(fd)
return
@@ -152,7 +152,7 @@ def _init_argv_posix():
if total <= 0:
return
# 计算参数个数(\0 分隔)
# Calculate argument count (\0 delimited)
argc: INT = 0
i: t.CSizeT = 0
total_size: t.CSizeT = t.CSizeT(total)
@@ -164,12 +164,12 @@ def _init_argv_posix():
if argc == 0:
return
# 分配指针数组
# Allocate pointer array for argv (argc pointers)
argv_arr: str | t.CPtr = (str | t.CPtr)(_mbuddy.alloc(argc * platmacro.SIZEOF_POINTER))
if argv_arr == None:
return
# 填充指针(每个参数的起始地址)
# Populate pointer array (start address of each parameter)
argv_arr[0] = str(buf)
idx: INT = 1
i = 0
@@ -184,15 +184,15 @@ def _init_argv_posix():
def argc() -> int:
"""返回命令行参数个数。首次调用时自动初始化。"""
"""Returns the number of command line arguments. Automatically initializes on the first call."""
if _argc == 0:
_init_argv()
return _argc
def argv(index: int) -> str:
"""返回第 index 个命令行参数index 从 0 开始)。
首次调用时自动初始化。索引越界返回 None。"""
"""Returns the command line argument at index `index` (starting from 0).
Automatically initializes on first call. Returns None if the index is out of range."""
if _argc == 0:
_init_argv()
if index < 0 or index >= _argc: