Some simple information syncing

This commit is contained in:
2026-07-28 21:08:58 +08:00
parent 1837339f69
commit 3633be1995
65 changed files with 1132 additions and 368581 deletions

View File

@@ -127,33 +127,26 @@ class ArgumentParser:
def __new__(self, prog: str = "", description: str = "",
pool: memhub.MemBuddy | t.CPtr = None) -> t.CPtr:
stdio.printf("[DBG-argparse] __new__ enter pool=%p\n", pool)
stdio.fflush(0)
mb: memhub.MemBuddy | t.CPtr = pool
if mb is None: mb = _mbuddy
stdio.printf("[DBG-argparse] __new__ mb=%p\n", mb)
stdio.fflush(0)
ret: t.CPtr = mb.alloc(40)
stdio.printf("[DBG-argparse] __new__ ret=%p\n", ret)
stdio.fflush(0)
return ret
def __init__(self, prog: str = "", description: str = "",
pool: memhub.MemBuddy | t.CPtr = None):
stdio.printf("[DBG-argparse] __init__ enter self=%p pool=%p\n", self, pool)
stdio.fflush(0)
mb: memhub.MemBuddy | t.CPtr = pool
if mb is None: mb = _mbuddy
stdio.printf("[DBG-argparse] __init__ mb=%p\n", mb)
stdio.fflush(0)
self.__mbuddy__ = mb
self._prog = prog
self._description = description
self._arg_count = 0
stdio.printf("[DBG-argparse] __init__ before alloc\n")
stdio.fflush(0)
self._args = mb.alloc(MAX_ARGS * Argument.__sizeof__())
stdio.printf("[DBG-argparse] __init__ after alloc _args=%p\n", self._args)
stdio.fflush(0)
def add_argument(self, name: str = "", short: str = None,
arg_type: INT = 0, default: INT = 0,
@@ -172,17 +165,13 @@ class ArgumentParser:
help: 帮助文本
"""
stdio.printf("[DBG-argparse] enter add_argument name=%s args_ptr=%p\n", name, self._args)
stdio.fflush(0)
if self._arg_count >= MAX_ARGS: return
idx: INT = self._arg_count
stdio.printf("[DBG-argparse] idx=%d sizeof(Argument)=%d\n", idx, Argument.__sizeof__())
stdio.fflush(0)
arg: Argument | t.CPtr = t.CPtr(t.CUInt64T(self._args) + idx * Argument.__sizeof__())
stdio.printf("[DBG-argparse] arg ptr=%p\n", arg)
stdio.fflush(0)
arg.name = name
stdio.printf("[DBG-argparse] after arg.name=%s\n", arg.name)
stdio.fflush(0)
arg.short_name = short
arg.help_text = help
arg.arg_type = arg_type
@@ -191,7 +180,6 @@ class ArgumentParser:
arg.default_str = default_str
arg.required = required
stdio.printf("[DBG-argparse] before dest logic\n")
stdio.fflush(0)
# 判断是否位置参数
if name is not None and name[0] != '-':
arg.is_positional = True
@@ -203,10 +191,8 @@ class ArgumentParser:
else:
arg.dest = name + 1
stdio.printf("[DBG-argparse] after dest logic\n")
stdio.fflush(0)
self._arg_count = idx + 1
stdio.printf("[DBG-argparse] exit add_argument\n")
stdio.fflush(0)
def _get_arg(self, idx: INT) -> Argument | t.CPtr:
return t.CPtr(t.CUInt64T(self._args) + idx * Argument.__sizeof__())