stage2 修复全局变量未完成的问题 提供错误处理解析

This commit is contained in:
zzy committed 2026-09-25 13:46:07 +08:00
1 parent c0a86ea552
commit 0b8f649818
11 files changed
+317 -18

No files matched your search

+24 -4
View File
@@ -87,12 +87,32 @@ SPL_FN u64 vm_timestamp(u64 kind) {
#define SPL_VM_EMBED_IMPLIMENTATION
#include "spl_vm_embed.h"
/* 配置层外部函数处理器(native 端)。VM 模式的实现见 spl_syscall.c。
* native 的 foreign 分发尚未接入(后续),这里先提供可链接入口。 */
SPL_FN void vm_set_foreign(void *vm, unsigned long long handler, void *ctx) {
/* 配置层外部函数处理器(native 端):把 nested VM 未解析的 native 按名分发到
* 编译器生成的 `ct_*` 函数(表由 ir2c 生成,见 stage2/ir2c.spl)。 */
extern void *spl_ct_lookup(const char *name);
typedef spl_vm_val_t (*spl_native_ct_fn_t)(void *, spl_vm_val_t, spl_vm_val_t, spl_vm_val_t);
SPL_FN spl_vm_val_t spl_native_foreign(spl_vm_t *vm, const spl_vm_call_t *call, void *user) {
void *fn;
spl_vm_val_t a0 = 0, a1 = 0;
(void)vm;
if (!call)
return 0;
fn = spl_ct_lookup(call->name);
if (!fn)
return 0;
if (call->nargs > 0)
a0 = call->args[0];
if (call->nargs > 1)
a1 = call->args[1];
/* ct_* 统一形状:返回 u64,参数 (ctx, u64, u64);多余参数被忽略。 */
return ((spl_native_ct_fn_t)fn)(user, a0, a1, 0);
}
SPL_FN void vm_set_foreign(void *p, unsigned long long handler, void *ctx) {
(void)handler;
(void)ctx;
spl_vm_set_foreign((spl_vm_t *)p, spl_native_foreign, ctx);
}
#endif /* __SPL_RT_H__ */
+1 -4
View File
@@ -1674,11 +1674,8 @@ L_SPL_STORE:
spl_vm_val_t _v = POP();
spl_vm_val_t _off = POP();
void *_addr = spl_vm_xlate(vm, _off, spl_type_size(ins->type));
if (!_addr) {
fprintf(stderr, "vm: STORE bad off=%zu sz=%d\n", (size_t)_off, (int)spl_type_size(ins->type));
spl_vm_backtrace(vm, vm->fp);
if (!_addr)
VM_ERROR("STORE: invalid address");
}
memcpy(_addr, &_v, spl_type_size(ins->type));
DISPATCH();
}