Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions devel/200_28.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# [200_26] 提取内部桥接 helper,统一 (scheme char) 的 method_or_bust 语义

## 任务相关的代码文件
- src/s7.c
- src/s7_internal_helpers.h
- src/s7_scheme_char.c
- tests/goldfish/scheme/char-test.scm
- devel/200_26.md

## 如何测试
```
xmake b goldfish
bin/goldfish tests/goldfish/scheme/char-test.scm
```

## 2026/02/28 统一 (scheme char) 方法分派错误语义(missing-method / wrong-type-arg)
### What
为避免 `s7_scheme_char.c` 复制 `method_or_bust` 逻辑导致语义漂移,本次改动将字符模块改为复用 `s7.c` 内部语义:
1. 新增内部头文件 `src/s7_internal_helpers.h`,声明桥接函数:
- `s7i_method_or_bust`
- `s7i_method_or_bust_bool`
2. 在 `src/s7.c` 中新增桥接实现,内部直接调用原有 `method_or_bust`,确保行为与核心实现一致
3. 在 `src/s7_scheme_char.c` 中删除本地 `method_or_bust/method_or_bust_bool`,改为统一调用 `s7i_*` 桥接函数
4. 在 `tests/goldfish/scheme/char-test.scm` 增加回归测试,覆盖 openlet 对象参与字符相关调用时的异常语义
16 changes: 16 additions & 0 deletions src/s7.c
Original file line number Diff line number Diff line change
Expand Up @@ -6608,6 +6608,22 @@ static s7_pointer method_or_bust(s7_scheme *sc, s7_pointer obj, s7_pointer metho
return(find_and_apply_method(sc, obj, method, args));
}

s7_pointer s7i_method_or_bust(s7_scheme *sc, s7_pointer obj, const char *method_name,
s7_pointer args, const char *type_name, s7_int arg_pos)
{
return(method_or_bust(sc, obj,
s7_make_symbol(sc, method_name),
args,
wrap_string(sc, type_name, safe_strlen(type_name)),
(int32_t)arg_pos));
}

bool s7i_method_or_bust_bool(s7_scheme *sc, s7_pointer obj, const char *method_name,
s7_pointer args, const char *type_name, s7_int arg_pos)
{
return(s7i_method_or_bust(sc, obj, method_name, args, type_name, arg_pos) != sc->F);
}

static s7_pointer mutable_method_or_bust(s7_scheme *sc, s7_pointer obj, s7_pointer method, s7_pointer args, s7_pointer typ, int32_t num)
{
if (has_active_methods(sc, obj)) return(find_and_apply_method(sc, obj, method, args));
Expand Down
26 changes: 26 additions & 0 deletions src/s7_internal_helpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* s7_internal_helpers.h - internal helper bridge declarations
*
* derived from s7, a Scheme interpreter
* SPDX-License-Identifier: 0BSD
*/

#ifndef S7_INTERNAL_HELPERS_H
#define S7_INTERNAL_HELPERS_H

#include "s7.h"

#ifdef __cplusplus
extern "C" {
#endif

s7_pointer s7i_method_or_bust(s7_scheme *sc, s7_pointer obj, const char *method_name,
s7_pointer args, const char *type_name, s7_int arg_pos);

bool s7i_method_or_bust_bool(s7_scheme *sc, s7_pointer obj, const char *method_name,
s7_pointer args, const char *type_name, s7_int arg_pos);

#ifdef __cplusplus
}
#endif

#endif /* S7_INTERNAL_HELPERS_H */
Loading