stage1 人工重构ast.c

This commit is contained in:
zzy
2026-08-12 10:29:38 +08:00
parent 314100afbc
commit b0e6b406ac
22 changed files with 1619 additions and 2895 deletions

View File

@@ -1,4 +1,4 @@
/* spl_vm.c SIR step-by-step interpreter
/* spl_vm.c - SIR step-by-step interpreter
*
* Implements the spl_vm.h API with macro-based type dispatch to
* eliminate repetitive per-type switch cases.
@@ -109,13 +109,13 @@ static int spl_type_size(spl_type_t t) {
/* ================================================================
* Type-dispatch macros for arithmetic / comparison
*
* ARITH_BINOP ADD / SUB / MUL (two's complement: op same for
* ARITH_BINOP - ADD / SUB / MUL (two's complement: op same for
* signed and unsigned at the same bit-width)
* DIV_REM_S signed division / remainder
* DIV_REM_U unsigned division / remainder
* CMP_ALL EQ / NE (bitwise compare, also handles floats)
* CMP_S signed ordering (<, <=, >, >=)
* CMP_U unsigned ordering
* DIV_REM_S - signed division / remainder
* DIV_REM_U - unsigned division / remainder
* CMP_ALL - EQ / NE (bitwise compare, also handles floats)
* CMP_S - signed ordering (<, <=, >, >=)
* CMP_U - unsigned ordering
* ================================================================ */
#define ARITH_BINOP(OP) \
@@ -177,7 +177,7 @@ static int spl_type_size(spl_type_t t) {
PUSH(_r); \
} while (0)
/* signed division / remainder all types cast to signed */
/* signed division / remainder - all types cast to signed */
#define DIV_REM_S(OP) \
do { \
spl_val_t _b = POP(), _a = POP(); \
@@ -280,7 +280,7 @@ static int spl_type_size(spl_type_t t) {
PUSH(_r); \
} while (0)
/* CMP_ALL equality comparisons (all types, floats via memcpy) */
/* CMP_ALL - equality comparisons (all types, floats via memcpy) */
#define CMP_ALL(OP) \
do { \
spl_val_t _b = POP(), _a = POP(); \
@@ -334,7 +334,7 @@ static int spl_type_size(spl_type_t t) {
PUSH(_r); \
} while (0)
/* CMP_S signed ordering (all ints cast to signed, floats OK) */
/* CMP_S - signed ordering (all ints cast to signed, floats OK) */
#define CMP_S(OP) \
do { \
spl_val_t _b = POP(), _a = POP(); \
@@ -388,7 +388,7 @@ static int spl_type_size(spl_type_t t) {
PUSH(_r); \
} while (0)
/* CMP_U unsigned ordering (all ints cast to unsigned, no float) */
/* CMP_U - unsigned ordering (all ints cast to unsigned, no float) */
#define CMP_U(OP) \
do { \
spl_val_t _b = POP(), _a = POP(); \
@@ -726,7 +726,7 @@ int spl_vm_prepare(spl_vm_t *vm, const char *entry, int argc, const char **argv,
}
/* ================================================================
* spl_vm_run_once execute one instruction
* spl_vm_run_once - execute one instruction
*
* Returns: 0 = still running, 1 = halted, 2 = breakpoint (SPL_DBG), -1 = error
* ================================================================ */
@@ -745,7 +745,7 @@ int spl_vm_run_once(spl_vm_t *vm) {
return -1;
}
/* 断点:即将执行的指令命中 ip 断点 暂停(返回 2
/* 断点:即将执行的指令命中 ip 断点 -> 暂停(返回 2
* skip_bp 置位时执行当前指令continue 越过当前断点)。 */
if (ip_breakpoint_hit(vm)) {
if (vm->skip_bp) {